Pause trading till next open when stop loss hit

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #137001 quote
    dougie80
    Participant
    New

    Hi, Please can somebody point me in the right direction,  I would like code to pause the system till next open when a loss is booked after a stoploss is hit, Thanks.

    #137006 quote
    robertogozzi
    Moderator
    Master

    There you go:

    Once TradeON = 1
    If TradeON = 0 then
       TradeON = 1
    Endif
    If StrategyProfit < StrategyProfit[1] then
       TradeON = 0
    Endif
     .
     .
    If MyLongConditions  and TradeON Then
       Buy 1 Contract at Market
    Endif
     .
     .
    If MyShortConditions and TradeON Then
       Buy 1 Contract at Market
    Endif
      .
      .
    dougie80 thanked this post
    #137175 quote
    dougie80
    Participant
    New

    Hi Robert,

    I made an attempt at inserting the code but it is not performing as expected still multiple losses on same day. D2 is the original equity curve before code was inserted please take a look at the code thanks.

    // M5
    // SPREAD 1.5
    // by BALMORA 74 – FEBRUARY 2019
    
    DEFPARAM CumulateOrders = false
    DEFPARAM Preloadbars = 50000
    
    //VARIABLES
    CtimeA = time >= 080000 and time <= 180000
    CtimeB = time >= 080000 and time <= 180000
    
    // TAILLE DES POSITIONS
    ONCE PositionSizeLong = 1
    ONCE PositionSizeShort = 1
    
    //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 <= – 37
    
    //VECTEUR = CALCUL DE LA PENTE ET SA MOYENNE MOBILE
    ONCE PeriodeB = 20
    ONCE nbChandelierB = 35
    lag = 5
    MMB = Exponentialaverage[PeriodeB](close)
    pente = (MMB-MMB[nbchandelierB]*pipsize) / nbchandelierB
    trigger = Exponentialaverage[PeriodeB+lag](pente)
    CondBuy2 = (pente > trigger) AND (pente < 0)
    CondSell2 = (pente CROSSES UNDER trigger) AND (pente > -1)
    
    Once TradeON = 1
    If TradeON = 0 then
    TradeON = 1
    Endif
    If StrategyProfit < StrategyProfit[1] then
    TradeON = 0
    Endif
    
    If condbuy and TradeON Then
    Buy 1 Contract at Market
    Endif
    
    If condsell and TradeON Then
    Buy 1 Contract at Market
    Endif
    
    //ENTREES EN POSITION
    CONDBUY = CondBuy1 and CondBuy2 and CTimeA
    CONDSELL = CondSell1 and CondSell2 and CtimeB
    
    //POSITION LONGUE
    IF CONDBUY THEN
    buy PositionSizeLong contract at market
    SET STOP %LOSS 1.3
    SET STOP pLOSS 80
    
    ENDIF
    
    //POSITION COURTE
    IF CONDSELL THEN
    Sellshort PositionSizeShort contract at market
    SET STOP %LOSS 1.3
    SET STOP pLOSS 80
    
    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 = 0 // Minimum Trailing Stop Distance
    
    // 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
    
    IF ONMARKET AND DAYOFWEEK=5 AND TIME>=210000 THEN
    SELL AT MARKET
    EXITSHORT AT MARKET
    ENDIF
    ENDIF
    ENDIF
    if onmarket and PREZZOUSCITA>0 then
    EXITSHORT AT PREZZOUSCITA STOP
    SELL AT PREZZOUSCITA STOP
    ENDIF
    ENDIF
    Screen-Shot-2020-06-25-at-20.13.10.png Screen-Shot-2020-06-25-at-20.13.10.png Vectorial-DAX-M5-v_D_V3.itf
    #137179 quote
    robertogozzi
    Moderator
    Master

    You asked to wait 1 bar, that’s what it’s doing.

    If you want to pause the whole  day then replace line 2 of my code with

    If IntraDayBarIndex = 0 then

    Please, always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.

    Thank you 🙂

    dougie80 thanked this post
    #137261 quote
    dougie80
    Participant
    New
    // ROBOT VECTORIAL DAX
    // M5
    // SPREAD 1.5
    // by BALMORA 74 - FEBRUARY 2019
    
    DEFPARAM CumulateOrders = false
    DEFPARAM Preloadbars = 50000
    
    
    //VARIABLES
    CtimeA = time >= 080000 and time <= 180000
    CtimeB = time >= 080000 and time <= 180000
    
    
    // TAILLE DES POSITIONS
    ONCE PositionSizeLong = 1
    ONCE PositionSizeShort = 1
    
    
    //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 <= - 37
    
    
    //VECTEUR = CALCUL DE LA PENTE ET SA MOYENNE MOBILE
    ONCE PeriodeB = 20
    ONCE nbChandelierB = 35
    lag = 5
    MMB = Exponentialaverage[PeriodeB](close)
    pente = (MMB-MMB[nbchandelierB]*pipsize) / nbchandelierB
    trigger = Exponentialaverage[PeriodeB+lag](pente)
    CondBuy2 = (pente > trigger) AND (pente < 0)
    CondSell2 = (pente CROSSES UNDER trigger) AND (pente > -1)
    
    Once TradeON = 1
    IF IntraDayBarIndex = 0 THEN
    TradeON = 1
    Endif
    If StrategyProfit < StrategyProfit[1] then
    TradeON = 0
    Endif
    
    
    If CONDBUY  and TradeON Then
    Buy 1 Contract at Market
    Endif
    
    
    If CONDSELL and TradeON Then
    Buy 1 Contract at Market
    Endif
    
    
    //ENTREES EN POSITION
    CONDBUY = CondBuy1 and CondBuy2 and CTimeA and TradeON
    CONDSELL = CondSell1 and CondSell2 and CtimeB and TradeON
    
    
    //POSITION LONGUE
    IF CONDBUY THEN
    buy PositionSizeLong contract at market
    SET STOP %LOSS 1.3
    SET STOP pLOSS 80
    
    ENDIF
    
    //POSITION COURTE
    IF CONDSELL THEN
    Sellshort PositionSizeShort contract at market
    SET STOP %LOSS 1.3
    SET STOP pLOSS 80
    
    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              = 0    // Minimum Trailing Stop Distance
    
    
    // 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
    
    IF ONMARKET AND DAYOFWEEK=5 AND TIME>=210000 THEN
    SELL AT MARKET
    EXITSHORT AT MARKET
    ENDIF
    ENDIF
    ENDIF
    if onmarket and PREZZOUSCITA>0 then
    EXITSHORT AT PREZZOUSCITA STOP
    SELL AT PREZZOUSCITA STOP
    ENDIF
    ENDIF
    

    Hi Robert, Thanks I made the suggested replacement and I am still getting subsequent trades opening that day, thanks for your help.

    #137262 quote
    robertogozzi
    Moderator
    Master

    You did not add TradeON to your conditions (line 10 and 15 in my code).

    Add it to your lines 67 and 75.

    My first code was made to wait ONE bar, while my next suggestions was to wait ONE day (till new day opens).

    dougie80 thanked this post
    #137464 quote
    Fran55
    Participant
    Veteran

    The code still dont work.

    #137469 quote
    robertogozzi
    Moderator
    Master

    It’s beacause STRATEGYPROFIT (like ONMARKET, etc…) take a bar to be able to update its status, so when you do Stop & Reverse ProOrder can’t know whether there was a gain or a loss.

    To achieve the correct result you should add

    and Not OnMarket

    to your conditions to enter a trade.
    In case you want to do Stop & Reverse you need to take note of that and accept that you will probably suffer TWO losses before there’s a temporary stop.

    At line 52 and 57 you always use BUY both for long and short conditions, is that intentional?

    #137586 quote
    Fran55
    Participant
    Veteran

    Ok Roberto, el código es bueno, thanks.

     

    But, other problem.

    If cumulateórders = true, the Code no function.

    #137589 quote
    robertogozzi
    Moderator
    Master

    If you use and Not OnMarket it will not work!

    #137658 quote
    Fran55
    Participant
    Veteran

    UPS… Thanks.

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.

Pause trading till next open when stop loss hit


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
dougie80 @dougie80 Participant
Summary

This topic contains 10 replies,
has 3 voices, and was last updated by Fran55
5 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/24/2020
Status: Active
Attachments: 2 files
Logo Logo
Loading...