Cannot Set Trailing Stop as % through IG
Forums › ProRealTime English forum › ProOrder support › Cannot Set Trailing Stop as % through IG
- This topic has 10 replies, 2 voices, and was last updated 2 years ago by robertogozzi.
Tagged: trailing stop
-
-
10/24/2018 at 9:35 PM #83471
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.
12345678910111213141516171819202122// Conditions to enter long positionsIF NOT LongOnMarket AND average[50](close) crosses over average[100](close) THENBUY 4 CONTRACTS AT MARKETENDIF// Conditions to exit long positionsIf LongOnMarket AND average[100](close) crosses over average[50](close)THENSELL AT MARKETENDIF// Conditions to enter short positionsIF NOT ShortOnMarket AND average[100](close) crosses over average[50](close) THENSELLSHORT 4 CONTRACTS AT MARKETENDIF// Conditions to exit short positionsIF ShortOnMarket AND average[50](close) crosses over average[100](close) THENEXITSHORT AT MARKETENDIF// Stops and targets : Enter your protection stops and profit targets hereSET STOP %TRAILING 0.25No 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 ?
10/29/2018 at 11:06 AM #83701You 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:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546trailingPercent = 0.5//trailing stop functionif onmarket thentrailingstart = tradeprice(1)*(trailingpercent/100) //trailing will start @trailinstart points profittrailingstep = tradeprice(1)*(trailingpercent/100) //trailing step to move the "stoploss"endif//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart THENnewSL = tradeprice(1)+trailingstepENDIF//next movesIF newSL>0 AND close-newSL>trailingstep THENnewSL = newSL+trailingstepENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart THENnewSL = tradeprice(1)-trailingstepENDIF//next movesIF newSL>0 AND newSL-close>trailingstep THENnewSL = newSL-trailingstepENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//put the first stoplossif onmarket and newSL=0 and activatestoploss thenset stop loss trailingstartendif12/18/2019 at 9:40 PM #115199Hello 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,
12/18/2019 at 9:47 PM #115201‘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.
01/03/2020 at 1:05 AM #115815Hello 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,
Axel01/03/2020 at 2:54 AM #115817No, 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):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869ONCE ActivateStopLoss = 1// Conditions to enter long positionsIF NOT LongOnMarket AND average[50](close) crosses over average[100](close) THENBUY 4 CONTRACTS AT MARKETENDIF// Conditions to exit long positionsIf LongOnMarket AND average[100](close) crosses over average[50](close)THENSELL AT MARKETENDIF// Conditions to enter short positionsIF NOT ShortOnMarket AND average[100](close) crosses over average[50](close) THENSELLSHORT 4 CONTRACTS AT MARKETENDIF// Conditions to exit short positionsIF ShortOnMarket AND average[50](close) crosses over average[100](close) THENEXITSHORT AT MARKETENDIF// Stops and targets : Enter your protection stops and profit targets hereSET STOP %TRAILING 0.25trailingPercent = 0.5//trailing stop functionif onmarket thentrailingstart = tradeprice(1)*(trailingpercent/100) //trailing will start @trailinstart points profittrailingstep = tradeprice(1)*(trailingpercent/100) //trailing step to move the "stoploss"endif//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart THENnewSL = tradeprice(1)+trailingstepENDIF//next movesIF newSL>0 AND close-newSL>trailingstep THENnewSL = newSL+trailingstepENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart THENnewSL = tradeprice(1)-trailingstepENDIF//next movesIF newSL>0 AND newSL-close>trailingstep THENnewSL = newSL-trailingstepENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//put the first stoplossif onmarket and newSL=0 and activatestoploss thenset stop loss trailingstartendif04/25/2022 at 9:37 AM #192177Bonjour 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 connaissancesHello 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.
04/25/2022 at 9:38 AM #192178pardon pour les fautes oupssorry for the mistakes oops
04/25/2022 at 9:50 AM #192183Only 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 🙂
04/28/2022 at 1:55 PM #192370thanks you but my english is bad robertto i’m sorry.
04/29/2022 at 7:01 AM #192385Use Google translator, it works like a charm if you write correctly in your native language.
-
AuthorPosts
Find exclusive trading pro-tools on