Cannot Set Trailing Stop as % through IG

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #83471 quote
    hendymk
    Participant
    New

    Hi,

     

    When I backtest my system I set it as a 0.25 % trailing stop loss. When I try to make my system go live I get the error message “Trailing stops defined as a percentage cannot be used for pro order …. you can use points or the currency of the asset” my code is.

    // Conditions to enter long positions
    IF NOT LongOnMarket AND average[50](close) crosses over average[100](close) THEN
    BUY 4 CONTRACTS AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    If LongOnMarket AND average[100](close) crosses over average[50](close)THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    IF NOT ShortOnMarket AND average[100](close) crosses over average[50](close) THEN
    SELLSHORT 4 CONTRACTS AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    IF ShortOnMarket AND average[50](close) crosses over average[100](close) THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets : Enter your protection stops and profit targets here
    SET STOP %TRAILING 0.25
    

    No matter how I try to code the trailing stop as a value it will not work and my results get skewed. Please can someone help me ?

    #83701 quote
    Nicolas
    Keymaster
    Master

    You should use a soft coded trailing stop in percentage, to replace the default instruction, here are some links of examples:

    https://www.prorealcode.com/topic/stoploss-stuck-after-being-set/#post-71117

    or you could give a try to this code snippet of a trailing stop in percentage:

    trailingPercent = 0.5
    //trailing stop function
    if onmarket then
    trailingstart = tradeprice(1)*(trailingpercent/100) //trailing will start @trailinstart points profit
    trailingstep = tradeprice(1)*(trailingpercent/100) //trailing step to move the "stoploss"
    endif
    
    //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 THEN
    newSL = tradeprice(1)+trailingstep
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>trailingstep THEN
    newSL = newSL+trailingstep
    ENDIF
    ENDIF
    
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart THEN
    newSL = tradeprice(1)-trailingstep
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>trailingstep THEN
    newSL = newSL-trailingstep
    ENDIF
    ENDIF
    
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    
    //put the first stoploss
    if onmarket and newSL=0 and activatestoploss then
    set stop loss trailingstart
    endif
    #115199 quote
    axellus
    Participant
    Junior

    Hello Nicholas,

    I tried the code and it seems to work very good. However, I get an error that “activatestoploss” is undefined. I just removed it and seems to still work good.

    I have a hard time figuring out what I removed tho and why it didn’t work in the first place. Care to enlighten me?

    Best regards,

    JoshPhoenix thanked this post
    #115201 quote
    Vonasi
    Moderator
    Master

    ‘activatestoploss’ is most likely just a boolean switch to turn on or off the use of the trailing stop loss code. You could have set it as a variable in your strategy to test with or without the trailing stop. By deleting that condition you have just made it so that the trailing stop code is always active.

    #115815 quote
    axellus
    Participant
    Junior

    Hello Nicolas, I have a problem when I want to use this stop loss in a demo account for live trading.
    It says “Combined stops cannot be used with ProOrder”. I am only using the code you wrote for stop loss.

    Thank you in advance,
    Axel

    #115817 quote
    robertogozzi
    Moderator
    Master

    No, you must have written something wrong, this is the code from the first post, then I added the variable to enable/disable the trailing stop code, then appended Nicolas’code (I suggest commenting out line 23):

    ONCE ActivateStopLoss = 1
    // Conditions to enter long positions
    IF NOT LongOnMarket AND average[50](close) crosses over average[100](close) THEN
    BUY 4 CONTRACTS AT MARKET
    ENDIF
     
    // Conditions to exit long positions
    If LongOnMarket AND average[100](close) crosses over average[50](close)THEN
    SELL AT MARKET
    ENDIF
     
    // Conditions to enter short positions
    IF NOT ShortOnMarket AND average[100](close) crosses over average[50](close) THEN
    SELLSHORT 4 CONTRACTS AT MARKET
    ENDIF
     
    // Conditions to exit short positions
    IF ShortOnMarket AND average[50](close) crosses over average[100](close) THEN
    EXITSHORT AT MARKET
    ENDIF
     
    // Stops and targets : Enter your protection stops and profit targets here
    SET STOP %TRAILING 0.25
    trailingPercent = 0.5
    //trailing stop function
    if onmarket then
    trailingstart = tradeprice(1)*(trailingpercent/100) //trailing will start @trailinstart points profit
    trailingstep = tradeprice(1)*(trailingpercent/100) //trailing step to move the "stoploss"
    endif
    
    //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 THEN
    newSL = tradeprice(1)+trailingstep
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>trailingstep THEN
    newSL = newSL+trailingstep
    ENDIF
    ENDIF
    
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart THEN
    newSL = tradeprice(1)-trailingstep
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>trailingstep THEN
    newSL = newSL-trailingstep
    ENDIF
    ENDIF
    
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    
    //put the first stoploss
    if onmarket and newSL=0 and activatestoploss then
    set stop loss trailingstart
    endif
    #192177 quote
    Marlaynicolas
    Participant
    New

    Bonjour je me présente sebastien je trade depuis 2017 .

    Enchanté de faire votre connaissance à tous .

    Tout d’abord j’apprécie votre site de partage de connaissance , merci encore.

    J’aime créer mes robots algo et j’aurai besoin de votre aide sur certains que j’ai créer pour du scalping 10 secondes dax et cac .

    Je partagerai cette âpres midi mes algo et si nous pouvions ensemble régler les pertes ou plutôt réduire le montant de pertes cela pourrait  permettre améliorer leurs rentabilités.

    J’ai par vos qualités incorporé le break even de Nicolas.

    Ma question est si c’est possible , je voudrais incorporer dans une unité de temps de 10 secondes un stop suiveur qui correspondrait au dernier plus bas en unité de temps 1 m?

    Je vous joins cette âpres midi mon algo et afin que vous puissiez l’évaluer.

    merci pour vos réponse et vos connaissances

    Hello I introduce myself sebastien I have been trading since 2017. Nice to meet you all. First of all I appreciate your knowledge sharing site, thank you again. I like to create my algo robots and I will need your help on some that I created for scalping 10 seconds dax and cac. I will share this afternoon my algo and if we could together settle the losses or rather reduce the amount of losses this could improve their profitability. Thanks to your qualities, I incorporated Nicolas’ break even. My question is if it’s possible, I would like to incorporate in a 10 seconds timeframe a trailing stop which would correspond to the last low in 1m timeframe? I join you this afternoon my algo and so that you can evaluate it. thank you for your answer and knowledge.

    #192178 quote
    Marlaynicolas
    Participant
    New

    pardon pour les fautes oups

    sorry for the mistakes oops

    #192183 quote
    robertogozzi
    Moderator
    Master

    @Marlaynicolas

    Only post in the language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums

    Do NOT append your questions to exixting topics. Start a new topic, instead, in the correct support forum (which are listed in yellow below) with as most details as possible and giving your topic a meaningful title.

    Thank you 🙂

    #192370 quote
    Marlaynicolas
    Participant
    New

    thanks you but my english is bad robertto i’m sorry.

    #192385 quote
    robertogozzi
    Moderator
    Master

    Use Google translator, it works like a charm if you write correctly in your native language.

    #246513 quote
    JoshPhoenix
    Participant
    New

    Thanks Nick, this just stopped me from swearing 🙂

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

Cannot Set Trailing Stop as % through IG


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
hendymk @hendymk Participant
Summary

This topic contains 11 replies,
has 3 voices, and was last updated by JoshPhoenix
9 months, 2 weeks ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/24/2018
Status: Active
Attachments: No files
Logo Logo
Loading...