a combination of 2 stop losses, need help coding
- This topic has 2 replies, 2 voices, and was last updated 7 years ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
Similar topics:
Forums › ProRealTime English forum › ProOrder support › a combination of 2 stop losses, need help coding
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.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
MFE: //************************************************************************ // MFE trailing stop function //************************************************************************ ///trailing stop trailingstop = 80 StartTrailingStopValue = 10 //resetting variables when no trades are on market if not onmarket then MAXPRICE = 0 priceexit = 0 endif //case LONG order if longonmarket then MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade if close-tradeprice(1) > StartTrailingStopValue*pointsize then if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level endif endif endif //exit on trailing stop price levels if onmarket and priceexit>0 then EXITSHORT AT priceexit STOP SELL AT priceexit STOP endif 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 //************************************************************************ // TSL trailing stop function //************************************************************************ //************************************************************************ //trailing stop function trailingstart = 80// 20trailing will start @trailinstart points profit trailingstep = 10// 5trailing 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 //************************************************************************ |
All 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 🙂
All 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.
Find exclusive trading pro-tools on