Strategy on S&P500 30min/5min

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #206545 quote
    stefou102
    Participant
    Veteran

    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.

    DEFPARAM FlatAfter = 235500
    DEFPARAM cumulateorders=false
    DEFPARAM PRELOADBARS = 10000
    ONCE positionsize=10
    Once ministop=2
    
    
    
    tradetime=time >080000 and time < 215000 and dayofweek<>0
    
    timeframe (30 minute, updateonclose)
    
    stdev=1
    aa = 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=high
    Low1H=Low
    
    
    Timeframe (5 minute)
    
    EMA8=exponentialaverage[8](close)
    SMA20=average[20](close)
    
    c2=close>highest[12](high)[1] and close>High1H and BARINDEX-TRADEINDEX(1)>=3
    cs2=close<lowest[12](low)[1] and close<Low1H and BARINDEX-TRADEINDEX(1)>=3
    
    if tradetime then
    
    if c1 and c2 and not onmarket then
    
    Buy positionsize contracts at market
    stoplevel=lowest[6](low)-close/500//lowest[5](low)-close/1000
    
    endif
    
    if cs1 and cs2 and not onmarket then
    
    Sellshort positionsize contracts at market
    stoplevel=highest[6](high)+close/500//lowest[5](low)-close/1000
    
    endif
    endif
    
    stoplevelactive=1
    if longonmarket and stoplevelactive=1 then
    sell at stoplevel stop
    endif
    if shortonmarket and stoplevelactive=1 then
    exitshort at stoplevel stop
    endif
    
    
    
    targetactive=1 
    if longonmarket and close<low[1] and close<SMA20 and targetactive=1 and positionperf>0.001 then //and positionperf>0.001
    sell at market
    endif
    
    if shortonmarket and close>high[1] and close>SMA20 and targetactive=1 and positionperf>0.001 then //and positionperf>0.001
    exitshort at market
    endif
    
    //si le trade ne part pas
    flat=1
    if longonmarket and BARINDEX-TRADEINDEX(1)>=18 and positionperf<0.001 and flat and close<positionprice then
    sell at positionprice+ministop limit
    endif
    //si le trade part pas
    if shortonmarket and BARINDEX-TRADEINDEX(1)>=18 and positionperf<0.001 and close>positionprice and flat then
    exitshort at positionprice-ministop limit
    endif
    //vendredi le marché cloture plus tot
    if dayofweek=5 and longonmarket and time=225500 then
    sell at market
    endif
    if dayofweek=5 and shortonmarket and time=225500 then
    exitshort at market
    endif
    
    set stop %loss 0.5
    set target %profit 1
    
    Capture-2.jpg Capture-2.jpg
    #206561 quote
    Roger
    Participant
    Veteran

    Watch out, I have backtested your strategy on 1M units (since 2010), see the result attached

    prt-forum.png prt-forum.png
    #206594 quote
    stefou102
    Participant
    Veteran

    Thx. 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.

    #206682 quote
    stefou102
    Participant
    Veteran

    improved version.

    DEFPARAM FlatAfter = 235500
    DEFPARAM cumulateorders=false
    DEFPARAM PRELOADBARS = 10000
    ONCE positionsize=10
    Once ministop=2
    
    
    tradetime=time >153000 and time < 215000 and dayofweek<>0 
    
    timeframe (30 minutes, updateonclose)
    
    
    once stdev=1
    aa = 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=high
    Low1H=Low
    
    
    Timeframe (5 minute)
    
    if month<>month[1]then
    dmonthly=0
    else
    dmonthly=dmonthly+1
    endif
    
     
    If volume >0 then
    
     
    VWAPmonthly = SUMMATION[max(1,dmonthly)](volume*typicalprice)/SUMMATION[max(1,dmonthly)](volume)
    
    endif
    
    EMA8=exponentialaverage[8](close)
    
    SMA20=average[20](close)
    
    if day<>day[1] then
    barVWAP=0
    else
    barVWAP=barVWAP+1
    endif
    
    if volume>0 then
    VWAP = SUMMATION[max(1,barVWAP)](volume*typicalprice)/SUMMATION[max(1,barVWAP)](volume)
    
    
    endif
    
    c2=close>highest[12](high)[1] and close>High1H and BARINDEX-TRADEINDEX(1)>=3 and close>VWAPmonthly
    cs2=close<lowest[12](low)[1] and close<Low1H and BARINDEX-TRADEINDEX(1)>=3 and close<VWAPmonthly
    
    
    
    if tradetime then
    
    if c1 and c2 and not onmarket  then
    
    Buy positionsize contracts at market
    
    endif
    
    if cs1 and cs2 and not onmarket then
    
    Sellshort positionsize contracts at market
    
    endif
    endif
    
    
    
    
    targetactive=1
    
    if longonmarket and close<SMA20 and targetactive=1 and positionperf>0.001 then //and positionperf>0.001
    sell at low-ministop*1.5 stop
    endif
    
    if shortonmarket and close>SMA20 and targetactive=1 and positionperf>0.001 then //and positionperf>0.001
    exitshort at high+ministop*1.5 stop
    endif
    
    
    
    if dayofweek=5 and longonmarket and time=225500 then
    sell at market
    endif
    if dayofweek=5 and shortonmarket and time=225500 then
    exitshort at market
    endif
    
    
    breakevenactive=1
    
    If not OnMarket then
    StopLoss = 0
    Endif
    If StopLoss = 0 and OnMarket and breakevenactive then
    
    If PositionPerf > 0.004 then
    
    If LongOnMarket then
    StopLoss = PositionPrice // + ministop
    Else
    StopLoss = PositionPrice //- ministop
    Endif
    Endif
    Endif
    If StopLoss > 0 then
    Sell      at StopLoss STOP
    Exitshort at StopLoss STOP
    Endif
    
    set stop %loss 0.5
    set target %profit 1
    
    Nicolas thanked this post
    #206686 quote
    stefou102
    Participant
    Veteran

    the strategy working only if there is sufficient vol, adding ATR filter on the 30Min makes sense

    #206828 quote
    fifi743
    Participant
    Master

    I have modified the code,
    how many spread do you need to do the backtest?

    //DEFPARAM FlatAfter = 235500
    DEFPARAM cumulateorders=false
    DEFPARAM PRELOADBARS = 10000
    ONCE positionsize=10
    Once ministop=2
    
    
    
    tradetime=time >080000 and time < 215000 and dayofweek<>0
    
    timeframe (30 minute, updateonclose)
    
    stdev=1
    aa = 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=high
    Low1H=Low
    
    
    Timeframe (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)>=3
    cs2=close<lowest[12](low)[1] and close<Low1H and BARINDEX-TRADEINDEX(1)>=3
    c3=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-sma20
    cs3=sma20[1]-ema8[1]<sma20-ema8
    
    if tradetime then
    
    if c1 and c2 and c3 and not onmarket then
    
    Buy positionsize contracts at market
    stoplevel=lowest[6](low)-close/500//lowest[5](low)-close/1000
    
    endif
    
    if cs1 and cs2 and cs3 and not onmarket then
    //
    Sellshort positionsize contracts at market
    stoplevel=highest[6](high)+close/500//lowest[5](low)-close/1000
    
    endif
    set stop %loss 0.5
    set target %profit 1
    endif
    
    stoplevelactive=0
    if longonmarket and stoplevelactive=1 then
    sell at stoplevel stop
    endif
    if shortonmarket and stoplevelactive=1 then
    exitshort at stoplevel stop
    endif
    
    
    
    targetactive=1
    if longonmarket and close<low[1] and close<SMA20 and targetactive=1 and positionperf>0.001 then //and positionperf>0.001
    sell at market
    endif
    
    if shortonmarket and close>high[1] and close>SMA20 and targetactive=1 and positionperf>0.001 then //and positionperf>0.001
    exitshort at market
    endif
    
    //si le trade ne part pas
    flat=1
    if longonmarket and BARINDEX-TRADEINDEX(1)>=18 and positionperf<0.001 and flat and close<positionprice then
    sell at positionprice+ministop limit
    endif
    //si le trade part pas
    if shortonmarket and BARINDEX-TRADEINDEX(1)>=18 and positionperf<0.001 and close>positionprice and flat then
    exitshort at positionprice-ministop limit
    endif
    //vendredi le marché cloture plus tot
    if dayofweek=5 and longonmarket and time=225500 then
    //sell at market
    endif
    if dayofweek=5 and shortonmarket and time=225500 then
    //exitshort at market
    endif
    if longonmarket and close>tradeprice and open=close and dhigh(0)=high then
    sell at market
    endif
    
    #206830 quote
    stefou102
    Participant
    Veteran

    Thx for the interest. Spread is around 0.8

    #206970 quote
    stefou102
    Participant
    Veteran

    Hello #fifi743, I have reviewed the conditions you added but don’t believe they have any added value unfortunately.

    #206974 quote
    fifi743
    Participant
    Master

    Spread =1
    I’m in the market for less time
    Less loss
    More gain

    Capture-decran-595.png Capture-decran-595.png
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

Strategy on S&P500 30min/5min


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
stefou102 @stefou102 Participant
Summary

This topic contains 8 replies,
has 3 voices, and was last updated by fifi743
3 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/30/2022
Status: Active
Attachments: 3 files
Logo Logo
Loading...