Need help coding new trailing stop loss
Forums › ProRealTime English forum › ProOrder support › Need help coding new trailing stop loss
- This topic has 8 replies, 4 voices, and was last updated 5 years ago by Vonasi.
-
-
02/12/2019 at 11:52 AM #91163
So im using this alot:
123456789101112131415161718192021222324252627282930//************************************************************************// MFE trailing stop function//************************************************************************///trailing stoptrailingstop = 50StartTrailingStopValue = 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 STOPendifAnd my question is: Could someone help me change this trailing stop to include:
When trade is profitable and the trailing stop loss begins, i want the stop loss to move up (more tight) for every Bar that has passed where trade is not hitting new highs.
Example: see pic.
Edit: So lets say a trade is going your way, your 100 pips in profit, the MTF stop loss is now = 50 pips profit.
Lets say that the trade is not hitting new highs, so for every Bar/candle that goes by without a new high, the stop loss keeps tightening up.
The idea is that If tthe market continues to rally up, the stop loss will follow the price higher and higher, as is normal with the MTF trailing stop loss today. But if the market stops rallying up andf starts moving sideways the market MIGHT come crashing down. Lets say it goes sideways for 15 bars before crashing down. I would love my stop loss to not be 50, but maybe 70 by that time..
Hope this is clear.
02/12/2019 at 12:42 PM #91171Instead of using it as an increasing step, you could turn it into a downward step, that is instead of 10 being added to your TRADEPRICE, whay don’t you subtract it from HIGH (if it was a higher HIGH)?
02/12/2019 at 12:53 PM #91174I attach a pic to make it clearer.
02/12/2019 at 12:59 PM #91177Im not sure that would do what i want?
I would like the MTF trailing stop to work as it is today, just to add a feature thats saying
“If there is no new higher close, then move trailing stop +n pips higher, but if the next candle has a higher close than close[1] then it should not move the stop loss, unless the new higher close is the highest close in the trade, then the normal MTF code would move the stop loss as it does today.”
02/12/2019 at 1:39 PM #91184This thread might be of interest to you.
https://www.prorealcode.com/topic/self-adjusting-trailing-stop-based-on-market-movements/
02/12/2019 at 7:08 PM #91234I tried this modified code, but I could not find any trade to fully test it:
12345678910111213141516171819202122232425262728293031323334353637//************************************************************************// MFE trailing stop function//************************************************************************///trailing stoptrailingstop = 20StartTrailingStopValue = 10KeepUpPace = 5 //move SL these Pips only when no new higher has formed, but still price is higher than treshold and higher than previous SL//resetting variables when no trades are on marketif not onmarket thenMAXPRICE = 0priceexit = 0TempHigh = 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 levelTempHigh = highelsif close-tradeprice(1) > priceexit AND priceexit > 0 THENIF high <= TempHigh AND close <= close[1] THENpriceexit = priceexit + (KeepUpPace * pointsize)endifendifendifendif//exit on trailing stop price levelsif onmarket and priceexit>0 thenEXITSHORT AT priceexit STOPSELL AT priceexit STOPendif//graph close//graph high//graph priceexit//graph TempHigh//graph close[1]1 user thanked author for this post.
02/13/2019 at 8:34 PM #9132802/14/2019 at 3:22 PM #9140302/14/2019 at 4:30 PM #91408Mkyr – you can either post your idea in this forum and someone might be able to assist you out of the kindness of their heart or alternatively you can use the programming services available here:
https://www.prorealcode.com/trading-programming-services/
I also notice that you have posted a very similar request in another topic. Please do not double post as it just leads to confusion and wasted effort for those trying to help you.
-
AuthorPosts
Find exclusive trading pro-tools on