TradingView
TsangYouJun
Jan 10, 2020 4:54 PM

YJ Mean Reversion 

SPDR S&P 500 ETF TRUSTArca

Description

Mean reversion strategy, based upon the price deviation (%) from a chosen moving average (bars). Do note that the "gains" are always relative to your starting capital, so if you set a smaller starting capital (e.g. $10000) your gains will look bigger. Also when the strategy tester has finished calculating, check the "Open P/L", as there could still be open trades.

Some Tips:
- Was designed firstly to work on an index like the S&P 500 , which over time tends to go up in value.
- Avoid trading too frequently (e.g. Daily, Weekly), to avoid getting eaten by fees.
- If you change the underlying asset, or time frame, tweaking the moving average may be necessary.
- Can work with a starting capital of just $1000, optimise the settings as necessary.
- Accepts floating point values for the amount of units to purchase (e.g. Bitcoin ).
- If price of units exceeds available capital, script will cancel the buy.
- Adjusted the input parameters to be more intuitive.

Release Notes

Mean reversion strategy, based upon the price deviation (%) from a chosen moving average (bars). Do note that the "gains" are always relative to your starting capital, so if you set a smaller starting capital (e.g. $1000) your gains will look bigger. Also when the strategy tester has finished calculating, check the "Open P/L", as there could still be open trades.

Some Tips:
- Was designed firstly to work on an index like the S&P 500 , which over time tends to go up in value.
- Avoid trading too frequently (e.g. Daily, Weekly, Monthly), to avoid getting eaten by fees.
- If you change the underlying asset, or time frame, tweaking the moving average may be necessary.
- Can work with a starting capital of just $1000, optimise the settings as necessary.
- Accepts floating point values for the amount of units to purchase (e.g. Bitcoin).
- If price of units exceeds available capital, script will cancel the buy.
- Adjusted the input parameters to be more intuitive.
Comments
HermanBrummer
Hi TsangYouJun,

Thanks for coding and publishing this.

Have you traded using this system and if so what are your thoughts?
gandolfi
Thanks for your work and your time. But the flattering figures of a strategy should always be compared to Buy and hold the profit : $651361.33 --> 651.36%.
It is always easier to get good results by following an index that makes big gains over time.
drdorien
This is great, but something weird is happening for me. I think it's buying more than I have cash and it starts with a cumulative profit and drawdown (huh?). Also a lot of orders remain open...

I think some issue exists in: unitsLevel1 * close < (strategy.initial_capital + strategy.netprofit - strategy.openprofit

Because this does not check how much cash you have on hand, only your total worth.
eatyofood
the colors are elegant. the whole thing is brilliant. and i like the entry mode options. I've been wanting to build something like this to back test against balance sheets and other catylists...Thank you for sharing! holla at me if you want it in python.
YALCIN_A
@eatyofood, hi Did you apply the code in python?
eatyofood
Can i just say ... YOU ROCK!!! thank you! i was about to script this out myself.
More