PositionSize = 10000; // Fixed value for each position in BackTesting
Quantity = PositionSize / BuyPrice; // Quantity of shares to purchase
/* Time Frame Change:--------------------------------------------------------------*/
// Here we set the time frame to weekly and use the weekly close price for the moving average calculation
// You would put you code in here to get weekly array data
TimeFrameSet(inWeekly);
maW = MA( Close, 20 ); // simple moving average using weekly close
CW = C; // Close in weekly
TimeFrameRestore(inDaily);
Buy = Cross(Close, TimeFrameExpand (maW, inWeekly, expandLast)); // Buys in Daily backtest mode but using MA from weekly Time Frame to detect cross
Sell = Cross(TimeFrameExpand (maW, inWeekly, expandLast), Close); // Sells in Daily backtest mode but using MA from weekly Time Frame to detect cross
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
/* Exploration: --------------------------------------------------------------*/
Filter = Buy OR Sell AND StrLen( Name () ) == 3;
SetSortColumns( 2 );
AddColumn( IIf(Buy, 'B', IIf( Sell, 'S', 'N') ), "Signal", formatchar, IIf( Buy, colorGreen, IIf( Sell, colorRed, colorBlue)) );
AddColumn( IIf(Buy, PositionSize, Null), "Position Size", 1);
AddColumn( IIf(Buy, Quantity, Null), "Qty", 1);
/* Charting: --------------------------------------------------------------*/
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open= %g High= %g Low= %g Close= %g (%.1f%%) Volume= " + WriteVal( V/1, 1.0 ) +
"\n"+"{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorPaleTurquoise ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
Plot( TimeFrameExpand (maW, inWeekly, expandLast), "maW", colorAqua, styleLine ); // Plots weekly MA on daily chart
/* Plot Buy and Sell Signal Arrows */
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);