Multiple entry executions but only trailing SL on one

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #240405 quote
    CrazzycameelCrazzycameel
    Participant
    New

    Hello!

    I am currently working on a long only strategy, where I have two different entry executions, for reference they look like this:

    entry method 1:

    if time >= timestart and time < timeend then
    IF DAYCALL and bulltrend and golong and CB1H and close > entry1 and not longonmarket then
    buy positionsize contract at market
    SET STOP %LOSS 1.3
    SET TARGET %PROFIT 2.15
    ENDIF
    ENDIF

    and

    entry method 2:

    if DAYCALL and Rev1 and BollTrig0 and trendup and not longonmarket then
    buy positionsize contract at market
    SET STOP %LOSS 1.3
    SET TARGET %PROFIT 2.15
    ENDIF

     

    currently I am managing stoploss with a trailing SL that looks like this:

    //trailing stop function
    trailingstart = 20 //trailing will start @trailinstart points profit
    trailingstep = 6 //trailing step to move the "stoploss"
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
     
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    ENDIF

     

    however this makes it so that applies to both entry methods, I would only like to have trailing SL for entry method 1, where as entry method 2, i just want SL to be put breakeven and never move again.

    Is there any solution to distinguish this?

     

    best regards

    Jonathan

    #240410 quote
    Anjuna MarineAnjuna Marine
    Participant
    New

    You could run two separate strategies? Keep it simple.

    #240415 quote
    CrazzycameelCrazzycameel
    Participant
    New

    unfortunately not, as i dont want there to be a scenario where they execute at the same time

    #240416 quote
    GraHalGraHal
    Participant
    Master

    Try …

    Method1 = 1
    If Method1 Then
    if time >= timestart and time < timeend then
    IF DAYCALL and bulltrend and golong and CB1H and close > entry1 and not longonmarket then
    buy positionsize contract at market
    SET STOP %LOSS 1.3
    SET TARGET %PROFIT 2.15
    ENDIF
    ENDIF
    //trailing stop function
    trailingstart = 20 //trailing will start @trailinstart points profit
    trailingstep = 6 //trailing step to move the "stoploss"
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
     
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    ENDIF
    ENDIF
    #240417 quote
    CrazzycameelCrazzycameel
    Participant
    New

    does unfortunately not do it. Method 2 still trails the stoploss the same way. but i think you you’re onto something about defining the different methods to split them up, im just not very experience on that end yet

    #240419 quote
    GraHalGraHal
    Participant
    Master
    Method1 = 1
    If Method1 Then
    if time >= timestart and time < timeend then
    IF DAYCALL and bulltrend and golong and CB1H and close > entry1 and not longonmarket then
    buy positionsize contract at market
    SET STOP %LOSS 1.3
    SET TARGET %PROFIT 2.15
    ENDIF
    ENDIF
    //trailing stop function
    trailingstart = 20 //trailing will start @trailinstart points profit
    trailingstep = 6 //trailing step to move the "stoploss"
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
     
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    ENDIF
    ENDIF
    
    Method2 = 1
    If Method2 Then
    if DAYCALL and Rev1 and BollTrig0 and trendup and not longonmarket then
    buy positionsize contract at market
    SET STOP %LOSS 1.3
    SET TARGET %PROFIT 2.15
    ENDIF
    ENDIF
    #240420 quote
    GraHalGraHal
    Participant
    Master

    Try below to only take a position under one Method … I’ve not tested and not had coffee yet! 🙂

    Method1 = 1
    If Method1 Then
    if time >= timestart and time < timeend then
    IF DAYCALL and bulltrend and golong and CB1H and close > entry1 and not longonmarket then
    buy positionsize contract at market
    Method2 = 0
    SET STOP %LOSS 1.3
    SET TARGET %PROFIT 2.15
    ENDIF
    ENDIF
    //trailing stop function
    trailingstart = 20 //trailing will start @trailinstart points profit
    trailingstep = 6 //trailing step to move the "stoploss"
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
     
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    ENDIF
    ENDIF
     
    Method2 = 1
    If Method2 Then
    if DAYCALL and Rev1 and BollTrig0 and trendup and not longonmarket then
    buy positionsize contract at market
    Method1 = 0
    SET STOP %LOSS 1.3
    SET TARGET %PROFIT 2.15
    ENDIF
    ENDIF
    #240424 quote
    GraHalGraHal
    Participant
    Master

    Just had a shot of caffeine, this should work better (not tested) …

    If NOT onmarket Then
    Method1 = 1
    Method2 = 1
    
    If Method1 Then
    if time >= timestart and time < timeend then
    IF DAYCALL and bulltrend and golong and CB1H and close > entry1 and not longonmarket then
    buy positionsize contract at market
    Method2 = 0
    SET STOP %LOSS 1.3
    SET TARGET %PROFIT 2.15
    ENDIF
    ENDIF
    //trailing stop function
    trailingstart = 20 //trailing will start @trailinstart points profit
    trailingstep = 6 //trailing step to move the "stoploss"
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
     
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    ENDIF
    ENDIF
     
    Method2 = 1
    If Method2 Then
    if DAYCALL and Rev1 and BollTrig0 and trendup and not longonmarket then
    buy positionsize contract at market
    Method1 = 0
    SET STOP %LOSS 1.3
    SET TARGET %PROFIT 2.15
    ENDIF
    ENDIF
    ENDIF
    Crazzycameel and Iván González thanked this post
    #240429 quote
    GraHalGraHal
    Participant
    Master

    Delete Line 42 in above.

    #240434 quote
    GraHalGraHal
    Participant
    Master

    Also add below …

    GRAPH Method1 // add as Line 52
    GRAPH Method2 // add as Line 53

    If you want to post the .itf including your variables then I would test out on my Platform.

    Anybody feel free to add / join in etc.

    #240438 quote
    GraHalGraHal
    Participant
    Master

    So here we are, a question that is relevant to this Topic … using Nicolas Trailing Stop (as in the code above) with SELL AT newSL STOP at Line 38 … will the SET STOP %LOSS 1.3 at Line 10 still work?

    OR will the ‘Line 38 Stop instruction’ cancel / make redundant the ‘Line 10 Stop Instruction’??

    Anybody know or hazard a guess? 

    #240439 quote
    CrazzycameelCrazzycameel
    Participant
    New

    Have dropped the ITF below, and the full strategy code following:

    //RUNS ON 1HOUR TIMEFRAME
    
    defparam cumulateorders = false
    defparam preloadbars = 10000
    
    positionsize = 8
    
    timestart = 090000
    timeend = 220000
    
    TIMEFRAME (DAILY)
    clxd, ignored, ignored, ignored, ignored, ignored, ignored, ignored, ignored, ignored, ignored, ignored, ignored, ignored, ignored = CALL "Clean SP x ML ON v2 Indicator"
    
    TIMEFRAME (DAILY, updateonclose)
    ignored, nobuy, dshortframe, dlongframe, bulltrend, DaytriggerBULL, DAYCALL, ignored, ignored, ignored,ignored, ignored, ignored, ignored, ignored = CALL "Clean SP x ML ON v2 Indicator"
    
    TIMEFRAME (4 hour)
    ignored, ignored, ignored, ignored, ignored, ignored, ignored, clx4, ignored, ignored, ignored, ignored, ignored, ignored, ignored = CALL "Clean SP x ML ON v2 Indicator"
    
    TIMEFRAME (DEFAULT)
    ignored, ignored, ignored, ignored, ignored, ignored, ignored, ignored, cp, CB1H, entry1, Rev1, BollTrig0, trendup, nodayentry = CALL "Clean SP x ML ON v2 Indicator"
    
    golong = (close < nobuy)
    
    
    //ENTRY METHOD 1
    if time >= timestart and time < timeend then
    IF DAYCALL and bulltrend and golong and CB1H and close > entry1 and not longonmarket then
    buy positionsize contract at market
    SET STOP %LOSS 1.3
    SET TARGET %PROFIT 2.15
    ENDIF
    ENDIF
    
    
    //ENTRY METHOD 2
    if DAYCALL and Rev1 and BollTrig0 and trendup and not longonmarket then
    buy positionsize contract at market
    SET STOP %LOSS 1.3
    SET TARGET %PROFIT 2.15
    ENDIF
    
    
    
    
    //TRAILING STOP function. WANT TO USE THIS ONE FOR METHOD 1.
    trailingstart = 20 //trailing will start @trailinstart points profit
    trailingstep = 6 //trailing step to move the "stoploss"
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize //(minus för att pris ska bli BE på execution, eftersom både denna och den undre exekverar+6 i första rörelsen)
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
    
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    ENDIF
    
    
    
    
    //BREAKEVEN function. WANT TO USE THIS ONE FOR METHOD 2.
    once breakeven1 =1
    if breakeven1 then
    breakevenPC = 0.4
    PointsToKeep = (tradeprice(1)*(0.032/100))
    startBreakeven = tradeprice(1)*(breakevenPC/100)
    
    if breakeven1>0 then
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF
    IF LONGONMARKET AND high-tradeprice(1)>=startBreakeven*pipsize THEN
    breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
    ENDIF
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    endif
    endif
    
    
    
    //OTHER EXITS
    if longonmarket and abs(open-close)<1 and high<high[1] and positionperf>0 and high-close>2.75 then
    sell at market
    endif
    
    
    OTD = Barindex - TradeIndex(1) > IntradayBarIndex
    
    if longonmarket and clxd and clx4 and positionperf < 0 and OTD and not nodayentry then
    sell at market
    endif

     

    Have not yet tried out the alternatives you have dropped during the day as i am on the run for a bit, but will hopefully get a few hours this evening. I appreciate the help big time, mate

    GraHal thanked this post
    Clean-SP-x-ML-ON-v2-Indicator.itf
    #240441 quote
    fifi743fifi743
    Participant
    Master

    impossible with prt only with mt4

    #240445 quote
    GraHalGraHal
    Participant
    Master

    using Nicolas Trailing Stop

    Does not cancel / make redundant a Set Stop %Loss or Set Stop pLoss instruction.

    #240446 quote
    CrazzycameelCrazzycameel
    Participant
    New

    The following code does it for me:

    If NOT onmarket Then
    Method1 = 1
    Method2 = 1
    ENDIF
    
    
    //ENTRY METHOD 1
    If Method1 Then
    if time >= timestart and time < timeend then
    IF DAYCALL and bulltrend and golong and CB1H and close > entry1 and not longonmarket then
    buy positionsize contract at market
    Method2 = 0
    SET STOP %LOSS 1.3
    SET TARGET %PROFIT 2.15
    ENDIF
    ENDIF
    ENDIF
    
    //TRAILING STOP function FOR METHOD 1
    trailingstart = 20 //trailing will start @trailinstart points profit
    trailingstep = 6 //trailing step to move the "stoploss"
    
    ///reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
    
    ///manage long positions
    IF LONGONMARKET and Method1 THEN
    //first move
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
    
    ///stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    ENDIF
    
    
    
    //ENTRY METHOD 2
    If Method2 Then
    if DAYCALL and Rev1 and BollTrig0 and trendup and not longonmarket then
    buy positionsize contract at market
    Method1 = 0
    SET STOP %LOSS 1.3
    SET TARGET %PROFIT 2.15
    ENDIF
    ENDIF
    
    //BREAKEVEN function FOR METHOD 2.
    once breakeven1 =1
    if breakeven1 then
    breakevenPC = 0.4
    PointsToKeep = (tradeprice(1)*(0.032/100))
    startBreakeven = tradeprice(1)*(breakevenPC/100)
    
    if breakeven1>0 then
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF
    IF LONGONMARKET and Method2 = 1 AND high-tradeprice(1)>=startBreakeven*pipsize THEN
    breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
    ENDIF
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    endif
    endif
    
    
    //GRAPH Method1 coloured ("red")
    //GRAPH Method2 coloured ("blue")
    
    //graphonprice newSL coloured ("green")
    //graphonprice breakevenLevel coloured ("fuchsia")
    GraHal thanked this post
Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Multiple entry executions but only trailing SL on one


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 14 replies,
has 4 voices, and was last updated by CrazzycameelCrazzycameel
1 year, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/15/2024
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...