The code I sent for your BE and trail will do the following:
Set initial SL at -15 ticks.
Move SL to breakeven when you are +8 ticks in profit.
Move SL up two ticks when you are +10 ticks in profit and every two from then on.
You changed my original code a little but I have it move to breakeven when price = +8 and then kick in the trail when price is > 9 (which translates to 10). Subtle changes can make all the difference.
As far as your exit is concerned, if you now have it set to current bar, it should exit the instant you get a cross. If you want to make sure it closes as a cross, go back to . This exit is a bit of a guess, as I don't use one and so am not certain of how it responds to FirstTickOfBar, but it's a good guess.
Let me know if I have your trail strategy right and how this works out. Again, the trail will work in simulation mode in case you don't want to wait for actual market conditions to test.
Thanks for your best wishes. The strategy worked funny starting 3:28, ie in-and-out within a second (per enclosed trade log). I also notice the following:
1. Trade No 4 Long @557: It went up to 582 and there's a BE SL trade @557 (cancelled status) before its closing @572. If the trail code was working, should there be some trail stop orders listed on the Orders tab?
2. Starting Trade No 6, it triggered in-and-out trades until 3:43 (you will see the trade markers on the enclosed chart).
I have absolutely no idea what I did wrong when adding the trail code. Sorry! Enclosed is my strategy with the trail code + the required indicators in case you want to run it (the strategy is supposed to work best on a 4-tick MedianRenko chart).
My super-mega Thank You for checking it for me please! Thank You .. Thank You!
The following user says Thank You to wgreenie for this post:
The good news is I fixed your trail. Please make the following changes to your code:
SetStopLoss("Long ", CalculationMode.Ticks, 15, false); should be
SetStopLoss("", CalculationMode.Ticks, 15, false);
Also, in the trail part, (not the BE part) use:
SetStopLoss(longEntryID, CalculationMode.Price, newPrice, false); and
SetStopLoss(shortEntryID, CalculationMode.Price, newPrice, false);
The other problems you're having seem to be coming from your exit code. I ran into the same problems you did, until I commented that part out. The bad news, unfortunately, is that I don't know how to fix it. Maybe someone else more experienced with exits can give you a hand there. I'm sorry I couldn't be of more help. Let me know if you're able to solve it or if any other issues come up. And again, good luck.
The following user says Thank You to dsraider for this post:
Thanks Dave for making the trail work. Time to celebrate!
I've made the suggested changes and will sim trade it tomorrow. Will try both false and true for CalculateOnBarClose unless you advise that true will not work for trail. Funny that the same Exit conditions (for those without trail) have been working over a week and no looping trades.
A member opines that
"Crazy multiple trades sometimes happens when set at CalculateOnBarClose = false. I think the strat gets overwhelmed."
Let's see what may happen tomorrow before my further investigation on the Exit conditions. My heartfelt thanks again Dave!
That is strange. Maybe if I were more experienced I'd be able to do more, but I'm really just a very, very stubborn newbie. I think setting it to true will not give you the results you want but I guess it doesn't hurt to try. Keep me posted. I hope you figure out the rest.
Thanks Dave. I did set the exit conditions back one bar like we did with the entry. Just added "FirstTickOfBar" per your kind suggestion.
Close<Low and Close>High is one of the exit conditions for Long and Short respectively. I just noticed this version is more profitable than Close<Low and Close>High when I backtested the strategy. (Oh, it's an inadvertent error when I fixed the "back one bar" earlier.)
I wonder if I should keep this as-is or try both versions live tomorrow. What do you think?
You're right on Dave! We canNOT trust backtest results especially MedianRenko ones. I learned this after backtesting my draft strategies and got really really excited LOL! Yes, only sim results (or maybe Market Replay ones) are more reliable.