ApplyStop() Not Firing

I’m having an issue with my ApplyStop() in my strategy that I can’t seem to resolve. The trailing/chandelier stop defined in my ApplyStop() does not fire at all. The strategy is relatively simple with both BUY and SELL signals functioning as intended and I have included a snippet below with the rules omitted (let me know if there is something more needed).

I have read the documentation numerous times and am really not sure what I’m missing. I have also read a number of ApplyStop() related posts that haven’t provided the insight needed.

I’m not sure if it’s due to some precedence rule I’m unaware of where the stop must be defined before X or if I have misunderstood how it operates.

All feedback appreciated and much love.

/* Set Options */
SetOption("InitialEquity", 10000);
SetOption("AllowSameBarExit", False);
SetOption("MaxOpenPositions", 10);
SetOption("CommissionMode", 2);
SetOption("CommissionAmount", 5);
SetOption("UsePrevBarEquityForPosSizing", True);
SetBacktestMode(backtestRegular);

/* Buy Conditions */
enterLong = ; // Buy trigger

/* Buy */
BuyPrice = (1.00 - (paramBuyPctBelow / 100)) * Ref(Low, -1); // BuyPrice 1% below previous bar
Buy = (Ref(enterLong, -1)) AND (Low < (1.00 - (paramBuyPctBelow / 100)) * Ref(Low, -1)); // Buy on next bar after buy signal if price reaches 1% below previous bar

/* Sell */
exitLong = ; // Sell trigger
SellPrice = Open;
Sell = Ref(exitLong, -1); // Sell on next bar open after sell signal at 

/* Stop-Loss */
riskPerShare = paramATRMultiplier * Ref(ATRInd, -1);
ApplyStop(stopTypeTrailing, stopModePoint, riskPerShare, True, True);

Please read the Knowledge Base:

and

Cheers Tomasz, unfortunately I've read these so many times they've just become words on a page. My pos sizing uses the method defined in the second article and works without issue.

I can't see the difference between my code and that of the KB resources. Although I am trying to implement a chandelier/ATR trailing stop as opposed to a stop based of profit gained. I copied the single line implementation from the ApplyStop() function reference page.

/* single-line implementation of Chandelier exit */

ApplyStop(stopTypeTrailing, stopModePoint, 3*ATR(14), True, True );

Most likely the values that you pass are different than those that you think you are passing. Use Exploration to display intermediate values to get better understanding of what is happening in your code: How do I debug my formula?

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.