Hello,
I am seeking assistance with afl code to correctly plot indicators when there is limited data in the stock array. The weekly trading system uses a new 52 week high and a market regime filter to buy. The market filter is the market index (XAO) above a 30 week SMA (shown as ribbon below). The sell signal is based on a 3xATR(14) Chandelier stop.
In the example below, the stock MP1 commenced trading on 16 December 2015. The market regime ribbon, Chandelier stop line and buy/sell arrows do not display as required for the first 30 bars. A 2 year back-test from 1 Januray 2016 has a buy on 08 January 2016 & sell on 01 April 16 (buy & sell arrows not displaying).
I would welcome advice to correctly code the indicators for the first 30 bars.
Thanks in advance.
// Options
SetOption("InitialEquity", 100000);
SetPositionSize(10, spsPercentOfEquity);
SetOption("AllowPositionShrinking", True );
SetOption(MinPosValue, 1000);
SetOption("CommissionMode", 2); // 0 = commission table, 1 = percent of trade, 2 = $ per trade
SetOption("CommissionAmount", 10);
SetTradeDelays(1,1,1,1);
BuyPrice = SellPrice = Open;
// Arrays
HighestValue = Ref(HHV(C, 52),-1);
VolumeOK = MA(V,4) > 500000;
PriceOK = C >= 0.10 AND C <= 20;
PositionScore = 1/C;
Stoplength = 3*ATR(14);
inIndex = NorgateIndexConstituentTimeSeries("$XAO");
Index = Foreign("$XAO", "C", True);
IndexOK = Index >= MA(Index, 30);
ribbonColor = IIf(IndexOK, colorGreen, colorRed);
Plot(2,"", ribbonColor, styleArea | styleOwnScale, 0, 100);
// Buy & Sell Signals
Buy = C >= HighestValue AND IndexOK AND PriceOK AND VolumeOK AND inIndex;
Sell = 0;
ApplyStop(stopTypeTrailing, stopModePoint, Stoplength, False, True ); // Check stops using only trade price and exit at regular trade price
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
//Plotting
Equity(1, 0); //evaluate stops, all quotes
intrade = Flip(Buy, Sell);
SetOption("EveryBarNullCheck", True);
Stopline = IIf(intrade, HighestSince(Buy, H - Stoplength), Null);
Plot(Stopline, "Chandelier Stop Loss", colorRed, styleline, 0,0,0,0);
Plot(HighestValue, "52wk High", colorBlue,styleLine,0,0,0,0);
PlotShapes(Buy*shapeUpArrow, colorGreen, O, L);
PlotShapes(Sell*shapeDownArrow, colorRed, O, H);