a combination of 2 stop losses, need help coding
Forums › ProRealTime English forum › ProOrder support › a combination of 2 stop losses, need help coding
- This topic has 2 replies, 2 voices, and was last updated 6 years ago by jebus89.
-
-
02/14/2018 at 10:19 PM #62783
Hi guys! I need some help.
Ive included 2 types of trailing stop loss, found on this forum. I belive the MFE calculates the maximum profit you see in a trade, while the TSL calculates after candle is finished. am i right? Or are both the stop losses calculating when candle is closed only?
If the MFE is calculating from the EQ curve at all times, is it possible to combine these 2?
as an example to show what i mean: ive seen a trade go to 85€ in profit and the stop loss should be activated when im above 80€, but in this example the trade fell down to only 75€ in profit when the candle closed, meaning my trailing stop loss didnt activate and i had to watch the trade go all the way down to 0.
just to be extra clear: i want the TSL trailing stop, but i want it to be able to see that my trade peaked above 80€ even tho it was below 80€ when the candle closed.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485MFE://************************************************************************// MFE trailing stop function//************************************************************************///trailing stoptrailingstop = 80StartTrailingStopValue = 10//resetting variables when no trades are on marketif not onmarket thenMAXPRICE = 0priceexit = 0endif//case LONG orderif longonmarket thenMAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current tradeif close-tradeprice(1) > StartTrailingStopValue*pointsize thenif MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop thenpriceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price levelendifendifendif//exit on trailing stop price levelsif onmarket and priceexit>0 thenEXITSHORT AT priceexit STOPSELL AT priceexit STOPendif9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999//************************************************************************// TSL trailing stop function//************************************************************************//************************************************************************//trailing stop functiontrailingstart = 80// 20trailing will start @trailinstart points profittrailingstep = 10// 5trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//************************************************************************02/14/2018 at 10:46 PM #62786All calculations will always be done at the close of a candle so if price has gone really high and then fallen back a long way you will always miss that action and only be able to calculate new a stoploss once the candle has closed.
You could try changing the MFE trailing stoploss calculations to be calculated on the high rather than the close and see if you can get that to work better for you as technically the close is not the maximum MFE the high is.
I’m a bit too tired to try it out myself right now but would be glad to see your results 🙂
02/14/2018 at 11:09 PM #62791All calculations will always be done at the close of a candle so if price has gone really high and then fallen back a long way you will always miss that action and only be able to calculate new a stoploss once the candle has closed. You could try changing the MFE trailing stoploss calculations to be calculated on the high rather than the close and see if you can get that to work better for you as technically the close is not the maximum MFE the high is. I’m a bit too tired to try it out myself right now but would be glad to see your results
Aha, okay, damn 😀
I guess ill try to just change it to high then, thanks. Im done for the evening but will post results using different stops to show difference.
-
AuthorPosts
Find exclusive trading pro-tools on