Traielrstop/step with Stoploss
Forums › ProRealTime English forum › ProBuilder support › Traielrstop/step with Stoploss
- This topic has 14 replies, 2 voices, and was last updated 2 years ago by marinusvrij.
-
-
04/29/2022 at 11:42 AM #192405
Hello agasin,
I have a question about scripting the following options.
i have a stoploss in my code as also a trailerstop with a trailerstep. The backtest on this script is very good but somehow when the
algo set on live the Stoploss only appears and when the price of the indices targets the Trailerstop / step nothing happens.. the Stoploss will be there – when the price targets the trailerstop / step the stoploss must disappear.
Also when the algo is putting up for live there is no feedback from the the backtrest that there is a error in the code…
Some one who cna help me ?
there should be a scrypt who can combine these two (or 3) options in one script.
04/29/2022 at 11:45 AM #192406How is it set your trailing stop please? Is it a soft coded one from the forum? Or are you using the SET STOP TRAILING instruction please? We need more information to understand what is happening in live trading.
Did you check the orders rejection list please?
04/29/2022 at 12:25 PM #192415Hello
There is no rejection in any journal. Or maybe you can show me where it must be written down
The Algo opens the position on the indicator with the normal stoploss (not via the …… ) but as i saidwhen the pricaction reach the trailerstop/step the algo won’t use this command
while the backtest doesn’t show any errors (Tick by Thick)
underneath mentioned thje script
//trailerstep
trailingstart = 25 //trailing will start @trailinstart points profit
trailingstep = 5 //trailing step to move the “stoploss”
//0 is off 1 is on
trailerStepFlag = 1with thanks
Marco
04/29/2022 at 12:51 PM #192418ps. i’m not using the stoprtrailing code from the wizard..
Again, there are no rejecting orders the algo does its thing but only with th estoploss and doesn’t use the script for the trailerstop/step
greetings
Marco
04/29/2022 at 3:20 PM #192436Are you using a limited risk account?
What is “the normal stoploss”, how do you set it?
Difficult to know where is the trouble with your code as you did not post the full content of the trailing stop part, it seems to come from the forum however?
04/29/2022 at 4:04 PM #192439Hello
Indeed, i use a stoploss 150 euro…
And i dont have a limited risk account and yes i use the code from the forum. ( wich is of no use as i use a stoploss of 1 % of my balance)
May the code from the forum is not right? herunder the code – where also some code is secured..
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120//trailersteptrailingstart = 12 //trailing will start @trailinstart points profittrailingstep = 3 //trailing step to move the "stoploss"//0 is off 1 is ontrailerStepFlag = 1//stoplossstopLoss = 150dynTS = 0dynTrail = 40TIMEFRAME(5 MINUTES, UPDATEONCLOSE)// Stops en targets : Voer uw beschermende stops en winst targets hier in// secured xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//SigalslongSignal = 0shortSignal = 0//long = (xxxxxxxxxxxxxxxsecuredxxx//short =(xxxxxxxxxxxxsecuredxxxxxxxxxxxxxxxxxx// Condities om long posities te openenIF NOT LongOnMarket AND long AND active THENBUY numContr CONTRACTS AT MARKETlongSignal = 1ENDIF// Condities om long posities te sluitenIf LongOnMarket AND short THENSELL AT MARKETENDIF//Close positions for end of the dayIF (time >= closePositions) and LONGONMARKET THENSELL AT MARKETENDIF// Condities om short posities te openenIF NOT ShortOnMarket AND short AND active THENSELLSHORT numContr CONTRACTS AT MARKETshortSignal = 1ENDIF// Condities om short posities te sluitenIF ShortOnMarket AND long THENEXITSHORT AT MARKETENDIF//Close positions for end of the dayIF (time >= closePositions) and ShortOnMarket THENEXITSHORT AT MARKETENDIFtimeframe(1 minutes)ONCE noSignal = 1// reset newSL LongIF longSignal AND noSignal THENnewSL = 0dynStop = 0noSignal = 0ENDIFIF NOT longSignal and NOT noSignal THENnoSignal = 1ENDIF// reset newSL shortIF shortSignal AND noSignal THENnewSL = 0dynStop = 0noSignal = 0ENDIFIF NOT shortSignal and NOT noSignal THENnoSignal = 1ENDIFIF trailerStepFlag THENIF LONGONMARKET THEN//next movesIF newSL>0 AND close-newSL>=trailingstart*pipsize THENnewSL = newSL+(trailingstep*pipsize)ENDIF//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstep*pipsize THENnewSL = tradeprice(1)+(trailingstep*pipsize)ENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//next movesIF newSL>0 AND newSL-close>=trailingstart*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIF//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstep*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFENDIF// dynamic trailer stepIF dynTS THENONCE dynStop = 0IF LONGONMARKET THENIF dynStop = 0 THENdynStop = tradeprice(1) - dynTrailENDIFIF dynStop > close - dynTrail THENdynStop = close - dynTrailENDIFENDIFIF SHORTONMARKET THENIF dynStop = 0 THENdynStop = tradeprice(1) + dynTrailENDIFIF dynStop < close + dynTrail THENdynStop = close + dynTrailENDIFENDIFIF dynStop>0 THENSELL AT dynStop STOPEXITSHORT AT dynStop STOPENDIFENDIF// Stops en targetsSET STOP $LOSS stopLoss04/29/2022 at 4:16 PM #192442Ps.
The Dynamic trailer is set on OFF so that doesnt’work but is not of use in this code.
greetings
Marco
04/29/2022 at 5:08 PM #192445Remove lines with “newsl=0”
and place that code at the top, below TIMEFRAME(1 minutes):
123if not onmarket thennewsl=0endif1 user thanked author for this post.
04/29/2022 at 6:27 PM #192447Hello
Thanks , i went live and i think it works… only the pips in the code are disturbing for me…
Greetings
Marco
04/29/2022 at 10:48 PM #192452Hello,
I tried the adjustments and the backtest shows more then 36% upto 45% of neutral trades… very strange ( this is with the same Trailerstep/stop and stoploss – with the newsl=o code i get 80% of profit trades in my backtest)
can you explain this?
kind regards
05/11/2022 at 10:39 AM #193048Why don’t you just GRAPH the newsl to see how it behaves in the market? You’ll see how and when it is calculated, and how and when orders are closed on that trailing stop price:
1GRAPHONPRICE newslAlways GRAPH your variables when there is something you don’t understand, otherwise it is very difficult to analyze the results of the algo 🙂
05/11/2022 at 11:11 AM #193051Hello
I always Graph my result to see if its works
But in this case the advise you gave – to erase the News=0 lines was not good,
More then 50% were neutral trades
Kind regards
Marco
05/11/2022 at 11:15 AM #193052Hello Nicoals
i have solved the problem myself , just a few adjustments on the script.. and it worked..
butr thanks anyway for the effort.
Also
Also this algo works now- (with a few adjustments in the script of the trailerstop and step)–
The “problem” I have now “but the trailerstep is calculated in TF candle and I want it dynamic with the price action.
With other words : the step is done after ending the candle ( in wich timeframe it was scripted)
Kind regards
Marco
Marco
ps i cannot send email any more to Market@….
regards
Marco
05/12/2022 at 10:41 AM #193100In order to interact during a candle, you have to use multi timeframe.
Look at those examples:
https://www.prorealcode.com/topic/move-sl-during-current-candle/#post-79130 (most stoploss to breakeven during candle).
https://www.prorealcode.com/topic/ouverture-immediate-position/#post-81939 (trigger an order during candlestick).
https://www.prorealcode.com/topic/how-to-open-and-close-in-1-bar/#post-146272 (open / close an order during the same bar).
05/12/2022 at 11:10 AM #193105Thanks Nicoals,
i will try them all and see what suits best.
With thanks
Marco
-
AuthorPosts