How to improve a strategy with simulated trades – part 1

This new article deals with a code snippet that can improve a strategy by stopping the real trading when the performance of the strategy decreases significantly, to simulate new orders by the code so that, as soon as the strategy performs again, restart auto trading in real time.

The simulation of trading orders is a point that has been addressed already on the site, especially in this old article of the blog equity curve trading and also in some topics of the forum.

I had not yet managed to find the time to put the idea into ProBuilder language so as to allow the first tests and application but it is now done with this new article, I hope it will arouse interest and that the bravest of you will be able to carry out tests and extensions on the subject, from this code 😉

Trading is a game, a statistical simulation

Even knowing that a strategy is profitable, it often happens that the distribution of orders can act in this way:
Out of 20 orders in total, 12 were winners and we closed in loss 8 times, nothing very extraordinary, yes but if these 8 losses had been successive … What a pity! This will have the effect, very often, to no longer trust the strategy, to stop it or again to restart working on it so that it can no longer suffer from this type of series of losses.

The code that follows will allow us, for example, to stop the strategy when the performance, due to these successive losses allows us to say: “ok it’s time to take a break”.
We will simply perform an average of the last X performances to assess whether the strategy currently performs or not. If the performance falls below this average, then we simulate false orders and test them to see if the performance has returned. If so, then we will re-engage automatic trading. Easy! 🙂

Application on a trend following strategy

A simple strategy made of moving averages crosses (7 and 21 periods), buying only, with takeprofit and fixed stoploss, let’s look at its equity curve:


(backtest performed on Mini DAX FUTURES, 5 minutes, 2 points spread).
There is uneven performance over time, but logically expected due to rather bearish periods and range areas where a trend following strategy is not suitable.

Let’s look at the cumulative performance of the orders and make an average of the last 20 performances:


When the performances fall below this blue line, we will start our “fake orders”, here is the complete code:

 

Explanations about the function code and how it works are inside the code itself.

It should be noted that in order to calculate this average, it will of course be necessary to wait for a sufficient number of real orders to have taken place (ie 20 in the present case), therefore during the first 20 orders, the strategy will be trading all by itself, help! 🙂

The results are encouraging, the strategy stops trading during bad times, compare the 2 equities curves, below is the basic strategy, above the strategy with the simulated orders:

 

The false orders are represented by the green line at the bottom of the graph, we note the performances that accumulates well on the black curve (and on the average in blue), while there is no order really at the market!


A magic function? never lose again?

We could indeed go to that conclusion. The worst strategy deserves this feature to be added. However, a strategy that performs well in the contexts for which it has been studied and coded, should not find any use there. In any case, that’s the conclusion I draw from it.
However and in summary, I will say that indeed, this function, added to your strategy will allow you not to go beyond serious problems and could even improve these performances, in most of the cases.

Here, we can conclude that the strategy benefits from the principle of orders simulation, since we see that the equity curve follows a constant rise. Even if the actual result, it is not entirely satisfactory, we managed to significantly improve the performance!

Interested in adding to your strategy, privately? Contact our programming service.

What is the next step ?

This concept demonstrated and coded in this article exists only at an experimental stage and should undoubtedly be experienced further by the community 🙂
In addition, fake orders are tested only once per bar when the code is read, which would not be the case with stoploss and takeprofit in real time since these levels are registered
in the order book of the broker. Also, I did not use takeprofit and dynamic stoploss, but only fixed levels … some work is still to do if we want to simulate all possibilities of a real strategy and real orders facing the market!

In the next article, I will add the code to handle short selling positions. I will also discuss the use of other calculation methods to consider whether it is whether or not to return to real positions again, using technical indicators such as the RSI calculated on the last X performances, for example.

Share this

  1. criscolci • 09/13/2018 #

    Thanks!!!

  2. Frankyboy • 09/13/2018 #

    Thank you, Nicolas, for this really creative idea! I think this can be an asset for many trading strategies!

    I just tried the code you posted above for the DAX, but there was a problem: the variable “avg” was always 0 in the entire backtest, and as a consequence simulated orders only occurred when the strategy profit dipped below 0. I don’t know exactly what is going on, but I suspect it could have to do with the FOR xx TO yy DO loop in the code. I have experienced earlier that a “FOR x=1 TO 1000 DO” loop of an indicator worked perfectly when launching the indicator, but the same loop performed only until 500 after it was integrated in a trading strategy (either directly or via CALL). Have you encountered similar things before? Could this be a bug in PorOrder? (I am using PRT Premium, v. 10.3)

    Thanks in advance for helping to clarify this!

    • Nicolas • 09/13/2018 #

      To correctly compute an average of N periods, you need N elapsed bars. Or N closed orders if N is the amount of orders to calculate the average.

    • waid • 09/13/2018 #

      Same problem as Franky boys
      I’d just directly put the code into DAX with 5-minutes timeframe without any modification. But the blue line (avg) is always flat (zero).
      Not sure whether the cause is due to the loop limit or not. Keep experimenting.
      version last update: 2019/01/03

  3. Frankyboy • 09/13/2018 #

    Thanks Nicolas! The problem is that in my version of ProOrder (trading strategies), the “FOR x=1 TO 1000 DO” only loops until 500 even if many more than 1000 bars are available. Strangely, in ProBuilder (for indicators), it works fine. I am already in contact with people from PRT. I hope this issues can be resolved soon…

  4. CharlesUmani • 09/13/2018 #

    can i modify to use it without any stop loss and take profit ? I just need fake orders nothing else please 🙂

    • Nicolas • 09/13/2018 #

      If your orders exit rely on conditions, I think that is possible to adapt the above codes.

  5. pro-index • 09/13/2018 #

    what is real strategy ? I can not understand.

  6. Gianluca • 09/13/2018 #

    Ciao you is there avaible also the part 2 for short orders?

  7. francois528 • 09/13/2018 #

    Bonjour, pourriez-vous inclure ce code dans cette stratégie Nicolas ?

  8. francois528 • 09/13/2018 #

    // ROBOT VECTORIAL DAX
    // M5
    // SPREAD 1.5
    // by BALMORA 74 – FEBRUARY 2019
    // ajouter ligne 18 45 et a partir de 115 par fifi743
    DEFPARAM CumulateOrders = false
    DEFPARAM Preloadbars = 50000

    //VARIABLES
    CtimeA = time >= 080000 and time = 080000 and time ppf then
    ppf=pp
    endif
    // stop hedge
    stpposinver =2
    //STRATEGIE
    //VECTEUR = CALCUL DE L’ANGLE
    ONCE PeriodeA = 10
    ONCE nbChandelierA= 15
    MMA = Exponentialaverage[PeriodeA](close)
    ADJASUROPPO = (MMA-MMA[nbchandelierA]*pipsize) / nbChandelierA
    ANGLE = (ATAN(ADJASUROPPO)) //FONCTION ARC TANGENTE

    CondBuy1 = ANGLE >= 45
    CondSell1 = ANGLE trigger) AND (pente MA and coeff>0.9
    CondSell2 = (pente CROSSES UNDER trigger) AND (pente > -1)

    //ENTREES EN POSITION
    AC=0
    VT=0
    FIN=0
    //
    ATR= AverageTrueRange[14](close)

    if coeff=100 and dhigh(0)-high>20 and open10 and hh=high and hh-ll>80 then
    POSLONG=0
    endif

    CONDBUY = CondBuy1 and CondBuy2 and CTimeA and atr>4
    CONDSELL = CondSell1 and CondSell2 and CtimeB and atr>4
    if close>pivot and CTimeA and cd and hh-ll>60 and hh[1]>hh and ll[1]=ll and Myrsi>75 and close8 and open[1]<close[1] and open4 THEN
    buy PositionSize contract at market
    SET STOP %LOSS 2
    ppf=0
    posinver=0
    AC=11
    ENDIF
    IF filtre=1 and atr>4 THEN
    buy PositionSize contract at market
    SET STOP %LOSS 2
    ppf=0
    posinver=0
    AC=1
    ENDIF

    //POSITION COURTE

    IF filtre=-1 and atr>4 THEN
    Sellshort PositionSize contract at market
    SET STOP %LOSS 2
    ppf=0
    posinver=0
    VT=1
    ENDIF
    IF CtimeB and close>pivot and coeffclose and hh-CLOSE<CLOSE-ll and open-close10 and close>average[10,1] and hh[1]<=hh and Myrsi4 THEN
    Sellshort PositionSize contract at market
    SET STOP %LOSS 2
    ppf=0
    posinver=0
    VT=11
    ENDIF
    //POSITION LONGUE
    //
    if longonmarket and high-close>4then
    PosLong=0
    endif
    tESTma=average[3,2]
    if OPEN[1] crosses over tESTma[1] and LOW[1]<LOW and openTESTMA then
    PosLong =1
    endif
    IF CONDBUY and Poslong THEN
    buy PositionSize contract at market
    SET STOP %LOSS 2
    ppf=0
    posinver=0
    AC=2
    ENDIF

    IF CONDSELL and open>ll[1] THEN

    Sellshort PositionSize contract at market
    SET STOP %LOSS 2
    ppf=0
    posinver=0
    VT=2
    ENDIF

    //VARIABLES STOP SUIVEUR

    ONCE trailingStopType = 1 // Trailing Stop – 0 OFF, 1 ON
    ONCE trailingstoplong = 4 // Trailing Stop Atr Relative Distance
    ONCE trailingstopshort = 4 // Trailing Stop Atr Relative Distance

    ONCE atrtrailingperiod = 14 // Atr parameter Value
    ONCE minstop = 10 // Minimum Trailing Stop Distance
    // ajouter par fifi743
    if posinver=0 then
    trailingStopType =1
    else
    trailingStopType =0
    endif

    // TRAILINGSTOP
    //———————————————-
    atrtrail = AverageTrueRange[atrtrailingperiod]((close/10)*pipsize)/1000
    trailingstartl = round(atrtrail*trailingstoplong)
    trailingstartS = round(atrtrail*trailingstopshort)
    if trailingStopType = 1 THEN
    TGL =trailingstartl
    TGS=trailingstarts
    if not onmarket then

    MAXPRICE = 0
    MINPRICE = close
    PREZZOUSCITA = 0
    ENDIF
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,close)
    if MAXPRICE-tradeprice(1)>=TGL*pointsize then
    if MAXPRICE-tradeprice(1)>=MINSTOP then
    PREZZOUSCITA = MAXPRICE-TGL*pointsize
    ELSE
    PREZZOUSCITA = MAXPRICE – MINSTOP*pointsize
    ENDIF
    ENDIF
    ENDIF
    if shortonmarket then
    MINPRICE = MIN(MINPRICE,close)
    if tradeprice(1)-MINPRICE>=TGS*pointsize then
    if tradeprice(1)-MINPRICE>=MINSTOP then
    PREZZOUSCITA = MINPRICE+TGS*pointsize
    ELSE
    PREZZOUSCITA = MINPRICE + MINSTOP*pointsize
    ENDIF
    ENDIF
    ENDIF
    if onmarket and PREZZOUSCITA>0 then
    EXITSHORT AT PREZZOUSCITA STOP
    SELL AT PREZZOUSCITA STOP
    ENDIF
    ENDIF

    //=============================FIN LONG==============================
    // impultion coeff=100
    for i=0 to 6 do
    if coeff[i]=100 then
    CD=1
    break
    else
    CD=0
    endif
    next
    if longonmarket and pp3.6 and pp>ppF-pp then
    sell at market
    FIN=1
    endif
    if longonmarket and time>170000 and barindex-tradeindex80 and open<close and high-closeppF-pp and positionprice<close then
    sell at market

    FIN=2
    endif
    if longonmarket and open[1]3 and coeff[1]>50 and open>close and high-open>10 and coeff>50 and pp>ppF-pp and positionpriceMMA[1]-MMA and hh[1]=hh and hh-closehigh and barindex-tradeindex<3 and open[1]3 and coeff[1]<25 and open<close and coeffcoeff and positionprice<close then
    Sellshort PositionSize contract at market
    SET STOP %LOSS stpposinver
    ppf=0
    VT=4
    ENDIF
    if longonmarket and open[1]2 and open5 and coeff[1]>50 anD coeff>90 and pp>ppF-pp and positionpriceclose[1] and high[1]-OPEN[1]>5 and open10 AND coeff[1]ppF-pp and positionprice<close then
    sell at market

    FIN=5
    endif
    if longonmarket and open[1]1 and high-open>1 and open>close and high[1]=high and low[1]>low and coeff[1]ppF-pp and positionpriceclose[2] and high[2]-open[2]>2 and close[2]=low[2] and open[1]>close[1] and open[1]=high[1] and close[1]=low[1] and abs(open-close)ppF-pp and positionpricehigh and coeff[1]35 and barindex-tradeindexMMA and close<MMA and open[3]<close[3] and open[2]<close[2] and open[1]close and open=high and closeclose then
    Sellshort PositionSize contract at market
    SET STOP %LOSS stpposinver
    ppf=0
    VT=5
    ENDIF
    if longonmarket and coeff=100 and hh[1]>hh and ll[1]>ll and MMA[1]>MMA and positionprice>close then
    Sellshort PositionSize contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    VT=6
    ENDIF
    if longonmarket and hh[1]=hh and ll[1]=ll and highest[10](high)>high and lowest[10](low)close[1] and open>close and high-open>5 and coeff[1]=coeff and coeffppF-pp and positionprice70 and coeff<3 and open[1]close and close-low5 and pp>ppF-pp and positionpriceMMA[1]-MMA and hh[1]<hh and ll[1]=ll and open[3]8 and open3 and coeffppF-pp and positionprice<close then
    sell at market

    FIN=9
    endif
    if longonmarket and hh[1]=hh and ll[1]=ll and open[1]<close[1] and high[1]-close[1]< high-close and open2 and high[1]=high and coeffppF-pp and positionpriceclose[2] and open[1]>close[1] and hh[1]<hh and ll[1]<ll and open8 and coeff[2]<10 and coeffppF-pp and positionpricehigh-low and close-MMA>10 and high[1]>high and open[1]<close[1] and coeff[1]close and coeffcoeff and hh[1]=hh and ll[1]ppF-pp and positionprice<close then
    sell at market

    FIN=11
    endif
    if longonmarket and open[3]85 and open[2]5 and open[1]close and coeffcoeff and pp>ppF-pp and positionprice<close then
    Sellshort PositionSize * posmax contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    VT=9
    ENDIF

    if longonmarket and high[1]-close[1]70 and high[3]-close[3]>5 and open[3]close[2] and open[1]close and coeff[1]<coeff and positionpricehh-ll and hh[1]=hh and coeff[3]<3and open[2]<close[2] and open[1]MMA[1]and open>close and coeff[1]<coeff and coeff[1]<8 and coeff<20 and closeclose then
    sell at market

    FIN=13
    endif
    if longonmarket and open[1]<close[1] and high[1]-close[1]close and coeff[1]10 and close crosses under MMA and positionprice>close then
    sell at market

    FIN=14
    endif
    //
    if longonmarket and high>MMA and hh[1]-high[1]close[2] and coeff[2]>30 and hh[2]-high[2]3 and high-open>4 and open[1]>close[1] and close[1] crosses under MMA[1] and open>close and opencoeff and positionprice>close then
    Sellshort PositionSize * posmax contract at market
    SET STOP %LOSS stpposinver
    ppf=0
    VT=10
    ENDIF
    if longonmarket and hh-close<close-ll and open[1]<close[1] and coeff[1]coeff and coeffclose and close=low and high-open>7 and positionprice<close then
    Sellshort PositionSize * posmax contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    VT=11
    ENDIF
    if longonmarket and hh-close<close-ll and coeff[1]=100 and open[1]4 and coeffclose and open-close3and pp>ppF-pp and positionprice<close then
    Sellshort PositionSize * posmax contract at market
    SET STOP %LOSS stpposinver
    ppf=0
    VT=12
    ENDIF
    if longonmarket and hh[1]=hh and ll[1]=ll and hh[1]-high[1]<hh-high and open[1]7 and open>close and coeff[1]>15 and coeffcoeff and high-open>6 and pp>ppF-pp and positionprice<close then
    sell at market

    FIN=15
    endif
    if longonmarket and hh[1]=hh and ll[1]<ll and hh[2]-high[2]<hh[1]-high[1] and open[2]5 and open[1]>close[1] and open<close and high-close6 and coeffcoeff and pp>ppF-pp and positionprice<close then
    sell at market

    FIN=16
    endif
    if longonmarket and hh[1]=hh and ll[1]<ll and open[2]6 and open[1]3 and open>close and high[1]low and coeff>15 and pp>ppF-pp and positionprice<close then
    sell at market

    FIN=17
    endif
    if longonmarket and open[1]6 and open>close and high[1]>high and close<low[1] and close crosses under MMA and positionprice<close then
    Sellshort PositionSize * posmax contract at market
    SET STOP %LOSS stpposinver
    ppf=0
    VT=13
    ENDIF
    if longonmarket and open[1]6 and open>close and high[1]>high and closeclose then
    sell at market

    FIN=18
    endif
    if longonmarket and barindex-tradeindex<5 and hh[1]<hh and hh-close<close-ll and ll[1]=ll and open[1]1 and open>close and high-open>4 and close-low<1 and high[1]low and coeff>30 and pp>ppF-pp and positionprice<close then
    sell at market

    FIN=19
    endif
    if longonmarket and open[2]close[1] and high[1]-open[1]>6 and coeff[1]<35 and hh[2]<hh[1] and ll[2]=ll[1] AND OPEN8 and pp>ppF-pp and positionpriceMMA and highll and positionperf(1)>0 and barindex-tradeindexclose and coeff=100 and positionprice>close then
    Sellshort PositionSize * posmax contract at market
    SET STOP %LOSS stpposinver
    ppf=0
    VT=14
    ENDIF
    if longonmarket and open[2]>close[2] and coeff[2]15 and open[1]8 and open>close and hh[1]-high[1]<hh-high and hh-closeppF-pp and positionpriceclose[3] and high[3]-open[3]>2 and open[2]3 and open[1]1 and OPEN>close and high=open and positionprice>close then
    Sellshort PositionSize * posmax contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    VT=15
    ENDIF
    if longonmarket and barindex-tradeindex>100 and low[1]-MMa[1]>low-MMA and low[1]>low and hh[2]<hh[1] and hh[1]=hh AND LL[1]<LL and hh-ll<30 and open[3]50 and coeff[2]=0 and open[1]CLOSE and coeff[2]<coeff[1] and coeff[1]ppF-pp and positionprice<close then
    sell at market

    FIN=22
    endif
    if longonmarket and barindex-tradeindex<10 and open[3]<close[3] and abs(open[2]-close[2])<1 and abs(open[1]-close[1])close and positionpricelow-MMA and hh-ll<60 and barindex-tradeindex<4 and hh-close<close-ll and hh[1]-high[1]<hh-high AND open[2]close[1] and abs(open-close)coeff and pp<ppF and positionprice<close then
    sell at market

    FIN=24
    endif
    if longonmarket and hh[2]<hh[1] and hh[1]=hh and ll[1]<ll and hh-closehigh and low[1]<=low and open[1]<close[1] and close[1]-open[1]close and coeffppF-pp and positionprice600 and positionprice>close then
    sell at market

    FIN=26
    endif
    if longonmarket and barindex-tradeindex<10 and cd and open[1]<close[1] and coeff[1]close and high-open>4 and low[1]-MMa[1]>low-MMA and high[1]>high and low[1]>low and pp>ppF-pp and positionprice10 and hh-MMA<MMA-ll and hh[1]<hh and ll[1]=ll and hh-ll<70 and hh-close<close-ll and open[1]close and high[1]<high and low[1]coeff and coeff[1]>35 and pp>ppF-pp and positionprice<close then
    sell at market

    FIN=28
    endif
    if longonmarket and open[2]1 and open[2]-low[2]<1 and open[1]=1 and openhh[1] and ll[1]=ll and coeff[2]ppF-pp and positionprice<close then
    sell at market

    FIN=29
    endif
    if longonmarket and open[2]6 and open[1]=6 AND OPEN>CLOSE and coeff[2]=coeff[1] and coeff[1]>coeff and pp>ppF-pp and positionprice20 and hh[1]=hh and ll[1]<ll and open[2]6 and open[1]=4 and open>close and close crosses under MA and coeff[2]>coeff[1] and pp>ppF-pp and positionpriceclose[2] and open[1]>close[1] and open>close and ll[1]>ll and hh[2]-ll[2]<50 and hh[1]=hh and MA crosses under MMA and coeff[1]90 and positionprice>close then
    sell at market

    FIN=32
    endif
    if longonmarket and coeff[4]<1 and coeff[2]<3 and open[1]4 and open>close and coeff>15 and close crosses under MA and ppclose[2] and high[2]-close[2]>3 and coeff[2]<5 and open[1]2 and open>close and MA crosses under MMA and LL[1]<LL and hh[1]=HH and pp<PPF then
    Sellshort PositionSize * posmax contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    VT=17
    ENDIF
    if longonmarket and open[2]<close[2] and open[1]3 and high[1]-close[1]>6 and open>close and high-open>6 and coeff[1]>coeff and coeffMA-MMA and positionprice>close then
    Sellshort PositionSize * posmax contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    VT=18
    ENDIF
    if longonmarket and open[2]8 and open[1]8 and open>close and hh[2]coeff and coeffppF-pp and positionprice<close then
    Sellshort PositionSize * posmax contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    VT=19
    ENDIF
    if longonmarket and barindex-tradeindexclose[1] and open>close and coeff[1]25 and MA crosses under MMA and MMA[1]>MMA and MA[1]>MA and ll[2]close then
    Sellshort PositionSize * posmax contract at market
    SET STOP %LOSS stpposinver
    VT=20
    ppf=0
    ENDIF
    if longonmarket and barindex-tradeindex>20 and cd and open[1]8 and open>close and coeff[1]<25 and coeff[1]<coeff and hh-closeppF-pp and positionprice20 and coeff[1]coeff and coeff>50 and open>close and close<MA and hh[1]=hh and ll[1]=ll and hh-ll<30 and pp<ppF and positionprice20 and open[1]3 and coeff[1]<10 and open2 and coeff<1 and hh[1]=hh and ll[1]<ll and pp<ppF and positionprice15 AND LL[1]>LL and(( open>close and high-open>10)or(open10)) and positionprice<close then
    sell at market
    FIN=351

    endif
    if longonmarket AND OPEN[3]close[2] and open[1]>close[1] and open>close and coeff[3]>25 and coeff[2]close and pp>ppF-pp and positionprice<close then
    sell at market
    FIN=352

    endif
    if longonmarket and close<MA and coeff[2]pivot and open[1]30 and open>close and coeff>15 and coeff[1]>coeff and pp>ppF-pp and positionprice<close then
    Sellshort PositionSize contract at market
    SET STOP %LOSS stpposinver
    FIN=353
    ppf=0

    ENDIF
    if longonmarket AND OPEN[2]10 and open[1]6 and open>close and coeffhigh and low[1]>low and coeff[1]>coeff and positionprice<close then
    sell at market
    FIN=354

    endif
    if longonmarket AND COEFF[2]30 and open[1]close and hh[1]coeff and positionpricePR and HIGHhh AND LL[1]>LL and pp>ppF-pp and positionprice<close then
    sell at market
    BREAK
    endif
    NEXT
    if longonmarket and barindex-tradeindexlow AND MMA-MMB>8 and hh[1]-high[1]<hh-high and LL[1]40 and coeff[2]>coeff[1] and coeff[1]<25 AND OPEN[2]<close[2] and hh[3]close[1] and open>close and high[1]>high and low[1]>low and pp>ppF-pp and positionprice<close then
    sell at market
    FIN=356
    endif
    if longonmarket and barindex-tradeindex90 and coeff>40 and open[1]5 and hh[2]close and high[1]<high and low[1]ppF-pp and positionprice<close then
    sell at market
    FIN=357
    endif
    if longonmarket And (close[1]-open[1])/2<open-close and hh[2]<hh[1] and hh-ll<60 and hh=high and barindex-tradeindex<5 and open[1]35 and Myrsi>80 and open>close and coeff>20 and coeff[1]>coeff and MyrsippF-pp and positionprice20 And OPEN2 and open>MMA and MMA-MMbcoeff and hh=high and hh[1]<hh and hh-ll90 and pp>ppF-pp and positionprice<close then
    sell at market
    FIN=359
    endif
    if longonmarket and open[1]25 and hh[1]-high[1]>5 and high[1]-close[1]>1 and low[1]<MMA[1] and MMA-MMBclose and open-close8 and pp>ppF-pp and positionprice<close then
    Sellshort PositionSize contract at market
    SET STOP %LOSS stpposinver
    FIN=360
    ppf=0
    ENDIF
    if longonmarket and open[1]25 and hh[1]-high[1]>5 and high[1]-close[1]>1 and low[1]close and open-close6 and coeff[1]>coeff and coeffppF-pp and positionprice25 and open<close and close-open25 and coeff[1]5 and hh[1]<hh and MMB-MMAclose then
    Sellshort PositionSize contract at market
    SET STOP %LOSS stpposinver
    FIN=362
    ppf=0
    ENDIF
    if longonmarket and open[1]75 and RSI[2](close[1])>90 and hh[2]1 and hh[1]=hh and ll[1]close and coeff>45 and coeff[1]>coeff and pp>ppF-pp and positionprice30 and close-open<5 and open[2]coeff[1] and open[1]<close[1] and open<close and coeff95 and pp>ppF-pp and positionprice<close then
    sell at market
    FIN=364
    endif
    //
    if longonmarket and barindex-tradeindex<3 and hh[1]=high[1] and hh[1]-high[1]<hh-high AND ll[1]<ll and hh-llhh-ll and dhigh(0)-high[1]>6 and open[1]6 and open>close and coeff90 and pp<ppF and positionprice<close then
    sell at market
    FIN=365
    endif
    if longonmarket and barindex-tradeindex<3 and hh=high and open6 and MYRSI>94 and coeff[1]>coeff and hh[1]ppF-pp and positionprice<close then
    sell at market
    FIN=366
    endif
    if longonmarket and barindex-tradeindexhigh and open[1]4 and open3 and open-low>15 and MYrsi>80 and coeff[1]>coeff and pp>ppF-pp and positionprice=close and highest[10](hh)>high and open[1]3 and MYrsi[1]>90 and MYrsi[1]>MYrsi and open>close and high -open>5 and close-low>10 and coeff[1]>coeff then
    sell at market
    FIN=368
    endif
    if longonmarket and low-MMA>20 and dhigh(0)-HH>70 and high[1]>high and low[1]100 and MMA-MMB>10 and hh[2]<hh[1] and hh[1]=hh and open[1]90 and open>close and Myrsi[1]>Myrsi and Myrsicoeff and coeffppF-pp and positionprice<close then
    sell at market
    FIN=369
    endif
    if longonmarket and open[1]<close[1] and hh[2]50 and MYrsi[1]>95 and hh[1]=high[1] and hh[1]=hh and open>close and high[1]=high and low[1]<low and MYrsicoeff and pp>ppF-pp and positionpricepivot and pivot>close and hh[1]=high[1] and open[1]4 and open[1]-low[1]>2 and close crosses under MMA and MYrsi<25 and coeff[1]close and coeff>15 and hh-ll>50 and pp>ppF-pp and positionprice<close then
    Sellshort PositionSize contract at market
    SET STOP %LOSS stpposinver
    FIN=371
    ppf=0
    ENDIF
    if longonmarket and pp<-0.1 and barindex-tradeindexMMA and MMA-MMbpivot and pivot>close and dhigh(0)>hh and dhigh(0)-hh>100 and hh-ll>50 and close crosses under MMA and MYRSI<20 and coeff[1]close then
    Sellshort PositionSize contract at market
    SET STOP %LOSS stpposinver
    FIN=372
    ppf=0
    ENDIF
    if longonmarket and pp<-0.2 and barindex-tradeindexhh and dhigh(0)-hh>50 and coeff[1]70 and close crosses under MMA and close crosses under MMB and MMA[1]-MMB[1]>MMA-MMb and Myrsiclose then
    Sellshort PositionSize contract at market
    SET STOP %LOSS stpposinver
    FIN=373
    ppf=0
    ENDIF
    if longonmarket and open[1]15 and open[1]-low[1]>10 and open80 and coeff>45 and Weekpivot>pivot and positionpricepivot and hh-ll<50 and open[1]6 and open[1]-low[1]>2 and MyrsiMyrsi and coeff<15 and positionpricepivot and hh-ll>50 and open[1]<close[1] and high[1]-close[1]10 and open>close and Myrsi<75 and coeff[1]35 and positionprice>close then
    Sellshort PositionSize contract at market
    SET STOP %LOSS stpposinver
    FIN=376
    ppf=0
    ENDIF
    if longonmarket and Dhigh(0)-hh>50 and high=hh and Weekpivot>pivot and hh-ll>30 and open[1]2 and open>close and close crosses under MMB and close crosses under MMA and MMA[1]-MMB[1]>MMA-MMB and coeff>35 and Myrsiclose then
    Sellshort PositionSize contract at market
    SET STOP %LOSS stpposinver
    FIN=377
    ppf=0
    ENDIF
    if longonmarket and close>pivot and low-MMA<3 and dhigh(0)-hhweekpivot and open[1]close and hh[1]4 and Myrsi[1]>Myrsi and Myrsi ppF-pp and positionpricehh-ll and weekpivot>pivot and closeclose and myrsi[1]>90 and Myrsi[1]>Myrsi and coeff>20 and coeff[1]=high [1] and close crosses under MMA and pp<ppF and positionprice<close then
    sell at market
    FIN=379
    endif
    if longonmarket and barindex-tradeindex<20 and hh-ll<40 and close crosses under MMA and close crosses under MMb and MYrsi45 and pivot>weekpivot and close>Pivot and ppclose then
    Sellshort PositionSize contract at market
    SET STOP %LOSS stpposinver
    FIN=377
    ppf=0
    ENDIF
    if longonmarket and cd and hh-ll>80 and barindex-tradeindex<5 and open[1]close and weekpivot>pivot and close>pivot and positionpricehigh and low[1]<low and barindex-tradeindex<10 and dhigh(0)-hh<20 and open[1]5 and open>close and coeff>15 and Myrsi[1]>90 and Myrsi80 and weekpivot>pivot and close>pivot and pp>ppF-pp and positionprice<close then
    Sellshort PositionSize contract at market
    SET STOP %LOSS stpposinver
    FIN=378
    ppf=0

    ENDIF
    ////============================FIN SHORT==========================

    //=========================================
    IF shortonmarket and pp1.9 and pp>ppF-pp then
    exitshort at market
    FIN=36
    endif
    if shortonmarket and barindex-tradeindex<5 and pp10 and open[1]>close[1] and close[1]-low[1]>7 and open>close and close-low>13 and positionprice>close then
    exitshort at market
    FIN=38
    endif
    if shortonmarket and positionperf(1)close[1] and abs(open-close)9 and positionprice>close then
    exitshort at market
    FIN=39
    endif

    if shortonmarket and barindex-tradeindex>70 and openppF-pp and pp>0.3 and abs(open-close)close then
    exitshort at market
    FIN=40
    endif

    if shortonmarket and open[1]>close[1] and close[1]-low[1]>5 and open>close and close-low>8 and coeffcoeff and positionprice>close then
    exitshort at market
    FIN=41
    endif
    if shortonmarket and high[1]>high and low[1]<low and open<close and coeff2 and high-close>2 and abs(open-close)>0.2 and pp>ppF-pp and positionprice>close then
    exitshort at market
    FIN=42
    endif
    if shortonmarket and barindex-tradeindex<15 and open[2]3 and open[1]>close[1] and close[1]-low[1]>2 and open>close and positionprice>close then
    exitshort at market
    FIN=43
    endif

    if shortonmarket and MMA[2]-MMA[1]>MMA[1]-MMA and hh-low>low-ll AND open10 and high-close<1 and coeff25 and barindex-tradeindex<10 and open[3]close[2] and open[1]<close[1] and open[1]-low[1]low[1] and high[2]>high[1] and coeff[1]>coeff and pp>ppF-pp and positionprice>close then
    exitshort at market
    FIN=44
    endif
    if shortonmarket and hh-close>close-ll and hh[1]=hh and low[1]-ll<low-ll and barindex-tradeindexclose[2]and low[2]>low[1] and open[1]high[1] and coeff[2]=coeff[1] and pp>ppF-pp and positionprice>close then
    exitshort at market
    FIN=45
    endif

    if shortonmarket and low>MMA and MMA[1]<MMA and barindex-tradeindex<=6 and coeff[2]close[1] and open>close and coeff-coeff[1]ppF-pp and positionprice>close then
    buy PositionSize contract at market
    SET STOP %LOSS stpposinver
    ppf=0
    AC=4
    ENDIF
    if shortonmarket and barindex-tradeindexclose and open=high and close=low and coeff>90 and pp>ppF-pp and positionprice>close then
    exitshort at market
    FIN=46
    endif

    if shortonmarket and coeff[1]>coeff and low[1]>low and close[1]close[1] and close[1]-low[1]>5 and coeff[1]>50 and open>close and close-low>4 AND high-open>4 and coeffppF-pp and positionprice>close then
    exitshort at market
    FIN=47
    endif
    if shortonmarket and hh-close>close-ll and hh-ll70 and coeff[1]<2 and coeffcoeff and pp>ppF-pp and positionprice>close then
    exitshort at market
    FIN=48
    endif
    if shortonmarket and ll[2]>ll[1] and coeff[1]=100 and open[1]>close[1] and close[1]-low[1]>10 and open<close and coeffppF-pp and positionprice>close then
    exitshort at market
    FIN=49
    endif
    if shortonmarket AND coeff[1]close[1] and high[1]-open[1]>5 and open>close and close-low>10 and hh[1]=hh and ll[1]>ll and hh-close>close-ll and pp>ppF-pp and positionprice>close then
    exitshort at market
    FIN=50
    endif
    if shortonmarket and low[1]>low AND COEFF[2] >20 and open[2]>close[2] and close[2]-low[2]>3 and open[1]=close[1] and close[1]-low[1]>4 and open>close and coeff2 and coeff[1]=0 and pp>ppF-pp and positionprice>close then
    buy PositionSize *posmax *2 contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    AC=5
    ENDIF
    if shortonmarket AND open[1]>close[1] and close[1]-low[1]>2 and coeff[1]<10 and open3 and coeff 5 and hh[1]>hh and hh-close>close-ll and pp>ppF-pp and positionprice>close then
    exitshort at market
    FIN=51
    endif
    if shortonmarket AND open[1]>close[1] and coeff[1]close and close-low>8 and high=open and pp>ppF-pp and positionprice>close then
    buy PositionSize *posmax *2 contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    AC=6
    ENDIF
    if shortonmarket and barindex-tradeindex55 and coeff[2]>coeff and hh-close>close-ll and hh-llclose[1] and close[1]-low[1]>3 and coeff[1]>50 and open<close and close-open5 and coeffppF-pp and positionprice>close then
    exitshort at market
    FIN=52
    endif
    if shortonmarket and barindex-tradeindex<8 AND OPEN[2]<close[2] and open[2]-low[2]10 and open[1]>close[1] and close[1]-low[1]>1 and open>close and close-low>5 and coeff[1]>coeff and coeffppF-pp and positionprice>close then
    exitshort at market
    FIN=53
    endif
    if shortonmarket and barindex-tradeindex<5 AND OPEN[2]<close[2] and coeff[2]<3 and open[1]3 and open[1]>MMA[1] and open>close and positionprice>close then
    exitshort at market
    FIN=54
    endif
    if shortonmarket and hh-close>close-ll and barindex-tradeindexmma-high and hh[1]=hh and ll[1]=ll and abs(open[2]-close[2])<1 and coeff[2]close[1] and open<close and high[1]<high and low[1]ppF-pp and positionprice>close then
    exitshort at market
    FIN=55
    endif
    if shortonmarket and abs(open[2]-close[2])<1 and coeff[2]close[1] and close[1]-low[1]>2 and open35 and close crosses over MMA and positionprice<close then
    buy PositionSize *posmax contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    AC=7
    ENDIF
    if shortonmarket and hh-ll<50 and hh[1]=hh and ll[1]=ll and MMA[1]<MMA and COEFF[2]<10 and coeff[1]<25 and coeff=100 and open<close and close crosses over MMA and positionprice<close then
    buy PositionSize *posmax contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    AC=8
    ENDIF
    if shortonmarket and barindex-tradeindexclose[3] and close[3]-low[3]>5 and open[2]3 and open[1]>close[1] and open<close and low[3]<low[2] and low[2]<low[1] and low[1]<low and high[1]MMA-high and ppclose then
    buy PositionSize *posmax contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    AC=9
    ENDIF
    //
    if shortonmarket and CD and open[2]<close[2] AND open[2]-low[2]6 and open[1]>close[1] and close[1]-low[1]>6 and openhigh and low[1]<low and positionprice<close then
    buy PositionSize *posmax contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    AC=10
    ENDIF
    if shortonmarket and barindex-tradeindexMMA-High and hh[1]>hh and ll[1]=ll and hh-close>close-ll and CD and open[2]>close[2] and open[1]10 and coeff[1]<3 and abs(open-close)<1 and low[1]<low and high[1]coeff and coeffppF-pp and positionprice>close then
    exitshort at market
    FIN=56
    endif
    if shortonmarket and barindex-tradeindexhh and abs(open[1]-close[1])<1 and open<close and MA crosses over MMA and positionprice<close then
    buy PositionSize *posmax contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    AC=11
    ENDIF
    if shortonmarket and barindex-tradeindexMMA[1] and open[1]>close[1] and close[1]-low[1]>4 and coeff[2]coeff and open6 and pp>ppF-pp and positionprice>close then
    exitshort at market
    FIN=57
    endif
    if shortonmarket and CD and open[2]<close[2] and open[1]<close[1] and open<close and close crosses over MA and positionpriceclose[2] and close[2]-low[2]>15 and coeff[2]<6 and coeff[1]close[1] and close[1]-low[1]>8 and open<close and close crosses over MA and positionprice<close then
    buy PositionSize *posmax contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    AC=13
    ENDIF
    if shortonmarket and barindex-tradeindexclose[2] and open[1]<close[1] and coeffhh[1] and hh[1]=hh and ll[1]=ll and pp>ppF-pp and positionprice>close then
    exitshort at market
    FIN=58
    endif
    // OK A METTRE DE COTE
    if shortonmarket AND COEFF>52 and HH[1]>HH AND LL[1]>=LL and(( open>close and close-low>10)or(open10)) and positionprice>close then
    exitshort at market
    FIN=59
    endif
    if shortonmarket and filt=1 and pp>ppF-pp and positionprice>close then
    exitshort at market
    FIN=60
    endif
    if shortonmarket and coeff>80 and RSI[2](close)ll and open>close and close-low>10 and hh-ll5 and ll=low and pp>ppF-pp and positionprice>close then
    exitshort at market
    FIN=60
    endif
    if shortonmarket and high[1]<high and low[1]<low and close=high and hh-ll15 and hh[1]>=hh and ll[1]<=ll and abs(open[1]-close[1])<2 and coeff[1]15 and openppF-pp and positionprice>close then
    exitshort at market
    FIN=61
    endif
    if shortonmarket and CD And hh[2]>hh[1] and ll[1]>ll and hh[1]=hh and open8 and coeff>45 and pp>ppF-pp and positionprice>close then
    exitshort at market
    FIN=62
    endif
    if shortonmarket and coeff[1]>coeff and coeff5 and Myrsi crosses over Myrsi[1]and Myrsi[1]close-ll and hh-ll<40 and open5 and high-close>4 and pp>ppF-pp and positionprice>close then
    exitshort at market
    FIN=62
    endif
    if shortonmarket and close70 and MMB[1]-MMA[1]>MMB-MMA and hh[1]=hh and hh-ll>100 and dlow(0)=ll and time>090000 and close crosses over MMA and MYrsi>75 and coeff>25 and pp<-0.2 and positionprice<close then
    buy PositionSize *posmax contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    AC=15
    ENDIF
    if shortonmarket and barindex-tradeindex<3 and MYrsi[1]60 and low[1]>=low and high[1]100 and MMB[1]-MMA[1]>MMB-MMA and open[1]>close[1] and open<close and coeff[1]40 and pp<-0.2 and positionprice<close then
    buy PositionSize *posmax contract at market
    SET STOP %LOSS stpposinver
    posinver=1
    ppf=0
    AC=16
    ENDIF
    if shortonmarket and barindex-tradeindexclose[1] and open[1]-low[1]>20 and ll[1]=low[1] and Low[1]<low and low[1]-ll[1]100 and high[1]>=high and open15 and Myrsi[1]30 and pp<0 and positionpriceweekpivot and barindex-tradeindexclose[1] and close[1]-low[1]>20 and open<close and Myrsi[1]40 and coeff>25 and pp<=0 and positionpriceMMA AND MMB-MMA>10 and high[1]<high and ppclose-ll and dhigh(0)-hhweekpivot and MYrsi>75 and barindex-tradeindex<5 and coeff[2]<10 and coeff[1]<15 and open70 and hh[1]>hh and hh-ll>70 and positionpricepivot and hh-ll<30 and Myrsi[1]75 and dlow(0)90 and close crosses over MMA and close crosses over MMB and MMA-MMB<1 and hh[1]weekpivot and positionprice100 and close crosses over MMA and pp<-0.1 and barindex-tradeindexpivot and close65 and Myrsi>70 and positionprice70 and open[1]<close[1] and openMMB and Myrsi>75 and Myrsi[1]pivot and close<pivot and pp<-0.1 and positionpriceclose[1] and coeff[1]>50 and hh[2]>hh[1] and ll[2]>ll[1] and open10 and pp>0.2 and weekpivot>pivot and close<pivot and coeffppF-pp and positionprice>close then
    exitshort at market
    FIN=62

    ENDIF
    if ac and vt and fin then
    endif

    // ppb =-1.06
    // ppv = -1.45
    //graph pp
    //GRAPH AC
    //GRAPH VT
    //GRAPH FIN
    //graph weekpivot
    //graph pivot

    • avatar
      thebigdeal • 09/13/2018 #

      bonjour francois, je vous que vous utiliser vectoriel daxM5 comme strategie, je pense que c’est l’une des meilleures du moment fiable et constante haut rendement …
      1) est ce bien le cas vous concernant ?
      2) vous semblez utiliser celle de fifi 743 ?? est ce le cas ….
      3) vous avez introduit dans son code // ROBOT VECTORIAL DAX
      // M5
      // SPREAD 1.5
      // by BALMORA 74 – FEVRIER 2019
      // ajouter ligne 18 45 et a partir de 115 par fifi743
      DEFPARAM CumulateOrders = false
      DEFPARAM Preloadbars = 50000

      // VARIABLES
      CtimeA = time> = 080000 and time = 080000 and time ppf then
      ppf = pp
      endif
      Jy comprends rien en code pourriez vous me le redonner au complet avec l’arret de la stratégie au bout d’un certainnombre de perte et la reprise automatique quand sa va mieux
      merci
      yann

    • Nicolas • 09/13/2018 #

      Comment savoir si “ça va mieux” si on ne trade plus ? 🙂

  9. Maximus • 09/13/2018 #

    Hi Nicolas, you have developed a relevant risk management tool by adding a moving average to an order performance curve, I find it absolutely fabulous!
    If I may, and if that has not yet been explored, would it also be possible to use this cumulative performance curve and its moving average to increase the size of the positions when it moves into positive territory? The performance would be increased …
    Thank you

    • Nicolas • 09/13/2018 #

      It would also increase the risk to cross below the moving average more frequently

  10. launell • 09/13/2018 #

    bonjour, est il possible d avoir le meme code mais pour les shorts ?

  11. MRTWEEK • 09/13/2018 #

    Bump! 🙂 where can I find part 2 ?

  12. Fab28 • 09/13/2018 #

    Bonjour
    Existe t’il une partie 2 et où pouvons nous trouvez le code de la partie 1 ?

    Ce code est il autonome ou doit t’on l’ajouter à notre propre stratégie ?
    S’il doit être ajouter, où doit il être placé ?
    Faut il modifier des variables dans notre code ou dans celui-ci ?

    Bref, sujet très intéressant !!!

    Merci d’avance pour vos conseils

avatar
Register or

Top