Strategy on S&P500 30min/5min
Forums › ProRealTime English forum › ProOrder support › Strategy on S&P500 30min/5min
- This topic has 8 replies, 3 voices, and was last updated 1 year ago by fifi743.
-
-
12/30/2022 at 6:38 PM #206545
If some of you can improve this strategy, please share. Logic is pretty robust normally for markets that can trend. Basically you have some bands (like bollinger, but it’s not) on a higher timeframe, and if your outside the bands, it may mean there is a strong trend and you bet it will continue, while you enter into position on a lower TF.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586DEFPARAM FlatAfter = 235500DEFPARAM cumulateorders=falseDEFPARAM PRELOADBARS = 10000ONCE positionsize=10Once ministop=2tradetime=time >080000 and time < 215000 and dayofweek<>0timeframe (30 minute, updateonclose)stdev=1aa = average[100,1]HBand = aa+average[200](std[100]*stdev)LBand = aa-average[200](std[100]*stdev)c1=close crosses over Hband and high>high[1] and summation[100](close>Hband)<65 //and summation[10](close>Hband)[1]<xx//and high<highest[4](high)[1]cs1=close crosses under Lband and low<low[1] and summation[100](close<LBand)<65 //and summation[10](close<LBand)[1]<xx//and low>lowest[4](low)[1]High1H=highLow1H=LowTimeframe (5 minute)EMA8=exponentialaverage[8](close)SMA20=average[20](close)c2=close>highest[12](high)[1] and close>High1H and BARINDEX-TRADEINDEX(1)>=3cs2=close<lowest[12](low)[1] and close<Low1H and BARINDEX-TRADEINDEX(1)>=3if tradetime thenif c1 and c2 and not onmarket thenBuy positionsize contracts at marketstoplevel=lowest[6](low)-close/500//lowest[5](low)-close/1000endifif cs1 and cs2 and not onmarket thenSellshort positionsize contracts at marketstoplevel=highest[6](high)+close/500//lowest[5](low)-close/1000endifendifstoplevelactive=1if longonmarket and stoplevelactive=1 thensell at stoplevel stopendifif shortonmarket and stoplevelactive=1 thenexitshort at stoplevel stopendiftargetactive=1if longonmarket and close<low[1] and close<SMA20 and targetactive=1 and positionperf>0.001 then //and positionperf>0.001sell at marketendifif shortonmarket and close>high[1] and close>SMA20 and targetactive=1 and positionperf>0.001 then //and positionperf>0.001exitshort at marketendif//si le trade ne part pasflat=1if longonmarket and BARINDEX-TRADEINDEX(1)>=18 and positionperf<0.001 and flat and close<positionprice thensell at positionprice+ministop limitendif//si le trade part pasif shortonmarket and BARINDEX-TRADEINDEX(1)>=18 and positionperf<0.001 and close>positionprice and flat thenexitshort at positionprice-ministop limitendif//vendredi le marché cloture plus totif dayofweek=5 and longonmarket and time=225500 thensell at marketendifif dayofweek=5 and shortonmarket and time=225500 thenexitshort at marketendifset stop %loss 0.5set target %profit 112/30/2022 at 11:32 PM #20656101/01/2023 at 2:38 PM #206594Thx. I think I still need to add a filter of some sort. Also either the strat is overfitted, which I don’t believe, either it works best when there is lot of uncertainty in the market like in 2022, so maybe the bands parameters should change in function of a measure of this uncertainty, which is maybe not easy to do.
01/02/2023 at 5:14 PM #206682improved version.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121DEFPARAM FlatAfter = 235500DEFPARAM cumulateorders=falseDEFPARAM PRELOADBARS = 10000ONCE positionsize=10Once ministop=2tradetime=time >153000 and time < 215000 and dayofweek<>0timeframe (30 minutes, updateonclose)once stdev=1aa = average[100,1]HBand = aa+average[200](std[100]*stdev)LBand = aa-average[200](std[100]*stdev)c1=close crosses over Hband and high>high[1] and summation[100](close>Hband)<65 //and summation[10](close>Hband)[1]<xx//and high<highest[4](high)[1]cs1=close crosses under Lband and low<low[1] and summation[100](close<LBand)<65 //and summation[10](close<LBand)[1]<xx//and low>lowest[4](low)[1]High1H=highLow1H=LowTimeframe (5 minute)if month<>month[1]thendmonthly=0elsedmonthly=dmonthly+1endifIf volume >0 thenVWAPmonthly = SUMMATION[max(1,dmonthly)](volume*typicalprice)/SUMMATION[max(1,dmonthly)](volume)endifEMA8=exponentialaverage[8](close)SMA20=average[20](close)if day<>day[1] thenbarVWAP=0elsebarVWAP=barVWAP+1endifif volume>0 thenVWAP = SUMMATION[max(1,barVWAP)](volume*typicalprice)/SUMMATION[max(1,barVWAP)](volume)endifc2=close>highest[12](high)[1] and close>High1H and BARINDEX-TRADEINDEX(1)>=3 and close>VWAPmonthlycs2=close<lowest[12](low)[1] and close<Low1H and BARINDEX-TRADEINDEX(1)>=3 and close<VWAPmonthlyif tradetime thenif c1 and c2 and not onmarket thenBuy positionsize contracts at marketendifif cs1 and cs2 and not onmarket thenSellshort positionsize contracts at marketendifendiftargetactive=1if longonmarket and close<SMA20 and targetactive=1 and positionperf>0.001 then //and positionperf>0.001sell at low-ministop*1.5 stopendifif shortonmarket and close>SMA20 and targetactive=1 and positionperf>0.001 then //and positionperf>0.001exitshort at high+ministop*1.5 stopendifif dayofweek=5 and longonmarket and time=225500 thensell at marketendifif dayofweek=5 and shortonmarket and time=225500 thenexitshort at marketendifbreakevenactive=1If not OnMarket thenStopLoss = 0EndifIf StopLoss = 0 and OnMarket and breakevenactive thenIf PositionPerf > 0.004 thenIf LongOnMarket thenStopLoss = PositionPrice // + ministopElseStopLoss = PositionPrice //- ministopEndifEndifEndifIf StopLoss > 0 thenSell at StopLoss STOPExitshort at StopLoss STOPEndifset stop %loss 0.5set target %profit 11 user thanked author for this post.
01/02/2023 at 6:23 PM #20668601/05/2023 at 1:43 PM #206828I have modified the code,
how many spread do you need to do the backtest?123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990//DEFPARAM FlatAfter = 235500DEFPARAM cumulateorders=falseDEFPARAM PRELOADBARS = 10000ONCE positionsize=10Once ministop=2tradetime=time >080000 and time < 215000 and dayofweek<>0timeframe (30 minute, updateonclose)stdev=1aa = average[100,1]HBand = aa+average[200](std[100]*stdev)LBand = aa-average[200](std[100]*stdev)c1=close crosses over Hband and high>high[1] and summation[100](close>Hband)<65 //and summation[10](close>Hband)[1]<xx//and high<highest[4](high)[1]cs1=close crosses under Lband and low<low[1] and summation[100](close<LBand)<65 //and summation[10](close<LBand)[1]<xx//and low>lowest[4](low)[1]High1H=highLow1H=LowTimeframe (5 minute)EMA8=exponentialaverage[8](close)SMA20=average[20](close)wil=Williams[40](close)c2=close>highest[12](high)[1] and close>High1H and BARINDEX-TRADEINDEX(1)>=3cs2=close<lowest[12](low)[1] and close<Low1H and BARINDEX-TRADEINDEX(1)>=3c3=abs(open[1]-close[1])>1 and not(dhigh(0)=high and high-close<1 and low-ema8>5)and high>close and ema8[1]-sma20[1]<ema8-sma20cs3=sma20[1]-ema8[1]<sma20-ema8if tradetime thenif c1 and c2 and c3 and not onmarket thenBuy positionsize contracts at marketstoplevel=lowest[6](low)-close/500//lowest[5](low)-close/1000endifif cs1 and cs2 and cs3 and not onmarket then//Sellshort positionsize contracts at marketstoplevel=highest[6](high)+close/500//lowest[5](low)-close/1000endifset stop %loss 0.5set target %profit 1endifstoplevelactive=0if longonmarket and stoplevelactive=1 thensell at stoplevel stopendifif shortonmarket and stoplevelactive=1 thenexitshort at stoplevel stopendiftargetactive=1if longonmarket and close<low[1] and close<SMA20 and targetactive=1 and positionperf>0.001 then //and positionperf>0.001sell at marketendifif shortonmarket and close>high[1] and close>SMA20 and targetactive=1 and positionperf>0.001 then //and positionperf>0.001exitshort at marketendif//si le trade ne part pasflat=1if longonmarket and BARINDEX-TRADEINDEX(1)>=18 and positionperf<0.001 and flat and close<positionprice thensell at positionprice+ministop limitendif//si le trade part pasif shortonmarket and BARINDEX-TRADEINDEX(1)>=18 and positionperf<0.001 and close>positionprice and flat thenexitshort at positionprice-ministop limitendif//vendredi le marché cloture plus totif dayofweek=5 and longonmarket and time=225500 then//sell at marketendifif dayofweek=5 and shortonmarket and time=225500 then//exitshort at marketendifif longonmarket and close>tradeprice and open=close and dhigh(0)=high thensell at marketendif01/05/2023 at 2:43 PM #20683001/07/2023 at 9:50 AM #20697001/07/2023 at 10:34 AM #206974 -
AuthorPosts
Find exclusive trading pro-tools on