This is the simplest of simple low level strategy using a loop. It is simply buying on the Entry_Date input, and selling on the Exit_Date input. It works fine in a backtest, but when I plot it on the chart, the sell down arrow only appears if I put the dates close together. If the entry date and exit date are on the same screen, it shows. But if I move the exit date further out the exit arrow does not appear anymore. But when I hit the "Apply" button from the editor, it will flash on the screen, but not stick. It immediately disappears.
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
Entry_Date = Param("Entry_Date",1060109,0,2000000,1);
Exit_Date = Param("Exit_Date",1180402,0,2000000,1);
Buy = 0;
BuyPrice = 0;
Sell = 0;
SellPrice = 0;
Short = 0;
Cover = 0;
mydatetime = DateTimeToStr(GetCursorXPosition());
bi = BarIndex();
dn = DateNum();
tn = TimeNum();
SetOption("MaxOpenPositions", 9999);
SetOption("InitialEquity", 1000000);
SetOption("AllowSameBarExit",false);
SetBacktestMode( backtestRegular );
for (i = 0; i < BarCount; i++)
{
if (i == 0 )
{
mp = 0;
}
if (i > 1 AND i < BarCount - 1)
{
if (mp == 0)
{
// # ENTER LONG -----------------------------------------------------
LongEntryCond = dn[i] == Entry_Date ;
if (LongEntryCond)
{
Buy[i] = 1;
BuyPrice[i] = Open[i];
BarsInTrade = 0;
mp = 1;
}
}
if ( mp == 1 )
{
BarsInTrade += 1;
if (BarsInTrade > 1)
{
// # Date Exit -----------------------------------------------------
if ( mp == 1 AND dn[i] == Exit_Date)
{
Sell[i] = 1;
SellPrice[i] = Close[i];
mp = 0;
BarsInTrade = 0;
}
}
}
}
imp[i] = mp;
}
printf("mp: " + NumToStr(imp, 1.0));
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorBlue, 0, BuyPrice, Offset=-15);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorYellow, 0, SellPrice, Offset=-15);