help in back testing strategy

Forums ProRealTime English forum ProBuilder support help in back testing strategy

Viewing 13 posts - 1 through 13 (of 13 total)
  • #188704

    Hi All

    I am to back test a strategy with below conditions for differ time frame. I want the entry to be in 5 min once the first bar close above MA 20. But should meet below conditions as well. SL based on 1.5 ATR and TP same distance  SL. I tried first below coding but every time in back test no results showed as all. I am new in back testing process. any help please ?

     

    =============================================================================================================

    TIMEFRAME(4 hours)
    indicator1= MACDline [21,89,8](High+Low/2)
    indicator2= MACDSignal[21,89,8](High+Low/2)
    indictaor3= exponentialaverage[50](close)
    indictaor4= exponentialaverage[20](close)
    xClose = (open + close + high + low) / 4
    c1=(indicator1<indicator2)
    c2= (xClose[1] <indictaor3)
    c3= (xClose[1] < indictaor4)
    REM The following code is related to this timescale:daily
    TIMEFRAME(1 hour)
    indicator5= MACDline [21,89,8](High+Low/2)
    indicator6= MACDSignal[21,89,8](High+Low/2)
    c4=(indicator5<indicator6)
    REM The following code is related to this timescale:4 hours
    TIMEFRAME(15 minute)
    indicator7= MACDline [21,89,8](High+Low/2)
    indicator8= MACDSignal[21,89,8](High+Low/2)
    c5=(indicator7< indicator8)
    indictaor9=exponentialaverage[10](close[2])
    //xClose = (open + close + high + low) / 4
    c6=(xClose[1] < indictaor9)

    IF c1 AND c2 and c3 and c4 and c5 and c6 THEN
    SELLSHORT AT MARKET
    ENDIF

    #188736

    I think you have coded a wrong expression: High+Low/2, which high + half the Low, perhaps this is what you want:

    #188861

    Thanks for correction

    I am still getting an issue in back tests. Though i selected right period , some time i got a message said invalid back test date and sometime it run but not getting me a results. Any issue with above code for back test. How i can intergrade TP and SL/

    #188935

    The following code works fine on a 5 min chart. You seem to have too many restrictions. With all conditions, there are no trades on 1k bars on Dow 5min. When I remove C4, 19 trades are generated on 5min TF. If you want to keep C4, then you need to find MACD 1 hour TF parameters which are compatible with all the other conditions.

    I added TP & SL at 1.5 x ATR.

    At first glance on 1k bars, the system looks profitable, but way too much drawdown, large SL, R/R 1:1 is not enough. I didn’t dig into the subject, but it seems like you have late entries. You may want to add more conditions on lower TF and relax the conditions on H4 TF (suggestion/intuition). As you seem to be new here, trade on Demo account first, because sexy backtest rarely reflect what can happen next…

    Hope this helps.

     

     

    1 user thanked author for this post.
    #188941

    Thanks Dear Khaled

    really appreciated. I realized that for manual entry will get late reply. If I want to make entry in M15 only by closing the first bar above EMA 10. Who ic an express this in coding. As sometimes the pentation happen at late stage and as you said it is difficult to reach 1:1

    #188942

    Happy to help.

    If you need to remover certain conditions (H4, H1, etc.) with their Timeframe you just need to add “//” before the code, like

    //xClose = (open + close + high + low) / 4

    #188955

    Thanks alot bro

    what i meant if i need to put a condition that a sell or buy trade will take place i.e  15m TF once the bar close , how this can be expressed ?

    #188956

    It depends 🙂

    1. if you’re running your system on a 15 min TF graph: the code will be executed at the end of each 15 min candle and take a trade if there a Signal in the closed candle.
    2. if you’re running your system on TF lower than 15 min – for example 5 min TF:
      1. if you put TIMEFRAME(15 minutes, updateonclose), then the code will be executed each 15 min
      2. if you put TIMEFRAME(15 minutes), then the code will be executed at the end of each 5 min candle. If there is a Signal on the 15 min TF (suppose your signal appears in min 9, then code will be executed at min 10:00:01.)

    The best way to get grasp of this MTF is to put your system into an indicator and see how the indicator behaves on different TF. The smaller the TF, the earlier you catch the trade, but you will get way higher number of false signals, i.e. higher number of losses. So there is a balance to find according to your Money Management and Psychology between higher number of trades and higher losers and potentially higher gains, or lower number of trades, lower losses and lower gains. Unfortunately, there is no free lunch in trading.

    #188957

    Many thanks  Dear Khaled and sorry for hanging you a lot on this. I am new in this software , I normally back test in Metrader4 (but not professional  software form back testing). Totally agree with you that lower time frame will be earlier catch for the trade. I am trying differ scenario. My  manual back test good. I entered as well in demo for 3 weeks , so far good results (apart form 1:1 R to reward). (I normally trade live with diff. system)

    I tried to modify the code in such way that once condition in TF daily and 1 hr met to open the trade once the closed of candle above EMA 10 in time frame 1 H (as per defied condition) but I got sell and buy trades (which is very strange to me). Which means in daily time frame if conditions met , then looking for 1 H and should conditions met as per 1 h conditions and also to execuate  the trade after meeting 1 h criteria  . In particular closing 1h candle above/below  10 EM.(b elow case for sell , should be below)

     

     

    DEFPARAM CUMULATEORDERS = FALSE

    TIMEFRAME(daily)
    c1=0
    c2=0
    c3=0

    indicator1= MACDline [21,89,8]((High+Low)/2)
    indicator2= MACDSignal[21,89,8]((High+Low)/2)

    indictaor3= exponentialaverage[50](close)
    indictaor4= exponentialaverage[20](close)

    xClose = (open + close + high + low) / 4

    c1=(MACDline [21,89,8]((High+Low)/2) < MACDSignal[21,89,8]((High+Low)/2))

    c2= (xClose[1] < exponentialaverage[50](close))

    c3= (xClose[1] < exponentialaverage[20](close))

    TIMEFRAME(4 hour )
    c4=0

    indicator5= MACDline [21,89,8](High+Low)/2
    indicator6= MACDSignal[21,89,8](High+Low)/2
    ATR = AverageTrueRange[14](close)

    c4=(MACDline [21,89,8](High+Low)/2 < MACDSignal[21,89,8](High+Low)/2)

    TIMEFRAME(1 hour)
    c5=0
    c6=0

    indicator7= MACDline [21,89,8]((High+Low)/2)
    indicator8= MACDSignal[21,89,8]((High+Low)/2)
    indictaor9=exponentialaverage[10](close[2])

    c5=(MACDline [21,89,8](High+Low)/2 < MACDSignal[21,89,8](High+Low)/2)
    c6=(xClose[1] < exponentialaverage[10](close[2]))
    //xClose = (open + close + high + low) / 4

    TIMEFRAME(1 hour ,updateonclose)
    IF c1 and c2 and c3 and  c6 THEN // c4 and
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF

    SET STOP PLOSS (1.5 * ATR)
    SET TARGET PPROFIT (1.5 * ATR)

    #188979

    I tested your code on DAX40 and it didn’t generate any buy orders, only Shorts (as expected – see screenshot 2).

    The code shows a crossing of EMA10 of 2 periods before the current candle.

    Is this what you want?

    I cleaned up the code.

     

    #188990

    Thanks Dear Khaled

    I will re run it again. For EMA , I thought this is the expression of EMA 10 shifted by 2 (offset) , unless I am doing the wrong code. So with this EMA setup  once a 1hr candle close below should sell provided daily conditions as wel met.

    #188994

    If you want to take Signal on the most recent EMA10 H1, then the code should read (without shift)

     

    #188995

    This is what am getting, unless there is something wrong !

    1 user thanked author for this post.
Viewing 13 posts - 1 through 13 (of 13 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login