Good day fellow Amibroker Coders
I'm having difficulty with a few lines of code. Please bare with me since I'm a complete noob when it comes to coding. After staring at the code for hours, browsing the web/forum and refraining from immediately looking for someone to spoon feed me the answer, I eventually couldn't resist to post my question here.
The code snippet is not the exact idea I'm trying to implement but the principal remains the same. I'm trying to update/tighten my dynamic trailing stop after an certain event occurs, in this case lets say when price is extended x $ amount away from the moving average.
As one can see in the image it is plotted correctly (blue line) and should've taken me out the trade earlier. However, the stop wasn't updated and the trade exited with the original % trail (red line)
herewith the code:
SetPositionSize(5, spsPercentOfEquity); SetOption("MaxOpenPositions", 20); LongEntry = C > MA(C,150); Stretch = 15 < (C-MA(C,150)); StopL = IIf(Stretch,10,25); // if price is stretched more than $15 use a stop of 10% otherwise use a stop of 25% Buy = LongEntry; Sell = 0; ApplyStop(stopTypeTrailing, stopModePercent, StopL, 0, True, 1); Equity(1,0); // evaluate stops, all quotes inTrade = Flip(Buy,Sell); // True when buy, False when Sell SetOption("EveryBarNullCheck", True); // Checks for null bars stopline = IIf(inTrade, HighestSince (Buy, H - (H*StopL/100)), Null); Plot(stopline, "StopLine", colorRed, styleLine,0,0,0,0); PlotShapes(Buy*shapeUpArrow, colorBrightGreen, 0,L); PlotShapes(Sell*shapeDownArrow, colorRed, 0,H);