trailing stop not accepted when going live

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #152247 quote
    Mendark
    Participant
    New

    Hi guys, anybody can explain me why when I am adding a trailing condition in my strategy the platform doesn’t allow me to run the system and when I delete the trailing conditions from the strategy the platform run my strategy?? Thanks

    #152250 quote
    robertogozzi
    Moderator
    Master

    SET STOP TRAILING is accepted,thiough recommended.

    What error does it return?

    Usually a common mistake is to use TWO different kinds of stop, such as:

    SET STOP LOSS 100 TRAILING 10

    which is not allowed, SET STOP LOSS and SET STOP TRAILING cannot be in the same line and cannot be in the same strategy. If they are in the same line an error is reported, while if they are on different lines they are accepted, but the second line always overrides the previous one.

    Mendark thanked this post
    #152255 quote
    Mendark
    Participant
    New

    Hi, this is the code I am using for

    defparam cumulateorders = false
    
    //order launch (example) would be set to any other entry conditions
    //c1 = close>close[1]
    c2 = close<close[1]
    
    //if c1 then
    //BUY 1 LOT AT MARKET
    //SET STOP PLOSS 50
    //endif
    
    if c2 then
    SELLSHORT 1 LOT AT MARKET
    SET STOP PLOSS 50
    endif
    
    //************************************************************************
    //trailing stop function
    trailingstart = 20 //trailing will start @trailinstart points profit
    trailingstep = 5 //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 (breakeven)
    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
    
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
    newSL = tradeprice(1)-trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
    newSL = newSL-trailingstep*pipsize
    ENDIF
    ENDIF
    
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    //************************************************************************
    
    GRAPH newSL as “trailing”
    #152256 quote
    Mendark
    Participant
    New

    When I try to launch the automatic proreal time in the live market it`s show me this

    probacktest.png probacktest.png
    #152261 quote
    XORANDNOT
    Participant
    Senior

    It means : Delete the last line of your code.

    Mendark thanked this post
    #152265 quote
    Mendark
    Participant
    New

    oh yeah, I have just realized now. DONE. appreciate your help, many thanks.

    #152268 quote
    robertogozzi
    Moderator
    Master

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

    Thank you 🙂

    #152392 quote
    Mendark
    Participant
    New
    breakeven = 30
    keeppoints = 5
    
    if not onmarket then 
    flag = 0
    endif
    
    IF longonmarket and close - tradeprice >= Breakeven*pipsize THEN
    flag = 1
    endif
    
    if flag then
    sell at (tradeprice + keeppoints) stop
    endif

    Hi guys, I am new in programming so there is anybody who can help me how to build a breakeven code for short positions ? what do I have to change exactly to make it work for short one ? thank you for your patience.

    MODERATORS EDIT: One post deleted and merged and code tidied up. Topic also moved to correct forum. Please try to be more careful with future posts.

    #152399 quote
    Nicolas
    Keymaster
    Master
    #152402 quote
    robertogozzi
    Moderator
    Master

    Replace line 30 with:

    sell at (tradeprice + keeppoints*PipSize) stop
    breakeven  = 30 * pipsize
    keeppoints = 5  * pipsize
    if not onmarket then 
       flag = 0
    endif
    // Long
    IF longonmarket and close - tradeprice >= Breakeven THEN
       flag = 1
    endif
    // Short
    IF shortonmarket and tradeprice - close >= Breakeven THEN
       flag = 1
    endif
    IF Flag = 1 then
       IF LongOnMarket THEN
          sell at (tradeprice + keeppoints) stop
       ELSIF ShortOnMarket THEN
          exitshort at (tradeprice - keeppoints) stop
       ENDIF
    Endif
    Mendark thanked this post
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

trailing stop not accepted when going live


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Mendark @mendark Participant
Summary

This topic contains 9 replies,
has 4 voices, and was last updated by robertogozzi
5 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/30/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...