Problems displaying plot on tickers

I have a problem that my strategy plot does not show up on all Tickers.

Here is the code:

SetBarsRequired( sbrAll );

PriceField = ParamField("Stop Price Field",2); // Default is Low
ExitPriceField = ParamList("Exit Criteria","End-of-Day,Intraday");
ExitField = IIf(ExitPriceField=="End-of-Day",Close,Low);

SpikeBounceLevel = Optimize("SB",-500,-1000,500,10);

SpikeBounce = Ref(Foreign("~1MonthNHNL","Close"),-1) <= SpikeBounceLevel AND Foreign("~1MonthNHNL","Close") > SpikeBounceLevel;

Buy = SpikeBounce;

Sell = 0;
trailARRAY = Null;
trailstop = 0;

ATRPeriods = Param("Stop Loss ATR",63,1,100,1);
ATRRange = ATR( ATRPeriods );
ATRFactor = Param("ATR Factor",1.5,0,5,0.1);
StopLevel = ATRFactor * ATRRange;

for( i = 1; i < BarCount; i++ )
{	StopLine = PriceField[ i ] - stoplevel[i]; // Stop Loss Value is normaly Low minus ATR value

   if( trailstop == 0 AND Buy[ i ] ) 
      trailstop = StopLine; // Set Initial stop below Entry Signal bar
   else Buy[ i ] = 0; // remove excess buy signals

   if( trailstop > 0 AND ExitField[ i ] < trailstop ) // Determine if Exit Price (Low or Close) is below trailing stop
      Sell[ i ] = 1; // Sell if trailing stop is below Exit Criteria i.e. Close for End-Of-Day or Low for Intraday
      trailstop = 0;

   if( trailstop > 0 )
      trailstop = Max( StopLine, trailstop ); // Determine Trailing Stop
      trailARRAY[ i ] = trailstop;


Plot( trailARRAY,"trailing stop level", colorRed,styleLine,Null,Null,1);

_TRACE("This is selected value of Bounce: " + SpikeBounce ); 
_TRACE("This is selected value of Buy: " + Buy ); 
_TRACE("This is selected value of Open: " + Open ); 


Below are examples of some charts/tickers where you can see the buy arrows/trailing stop/exit arrows being plotted correctly. The tickers are $SPX, AMZN.



Below are example charts/tickers where you can not see the buy arrows/trailing stop/exit arrows being plotted correctly. The tickers are &ES, INTU.



If I flick through the NASDAQ 100 ticker list about 5 tickers will show the plot and the other 95 show nothing.

I have been searching through the forum and Knowledge Base, tried to troubleshoot with Trace and stripping down and simplifying the code where possible, but have not found a solution yet. Obviously the code is incorrect/incomplete but I can not figure where the error is.

Would appreciate some help on this.
Let me know if you need more information.

In the code presented the problem is probably that the stop value is not available at the start of the stock data until ATRPPeriods have occurred.


for( i = ATRPeriods; i < BarCount; i++ )

@JohnHT Thank you for code. That fixed 98% of the problem. After I added your code there were still 2 tickers (from the Nasdaq 100) where it did not work. I checked the chart of these 2 tickers and saw the at one point in history there price was so low that a Low - ATR type stop put my stop below zero. So I had to limit the minimum of my trailing stop to $0.01 by changing code to add a MAX as follows:

StopLine = Max(0.01,PriceField[ i ] - stoplevel[i]);

Your help was very much appreciated.

1 Like