Упрощенно, вход сразу в позицию т.к. цена была ниже с точки отсчета (500 баров тестирования).
Но можно и это учесть.
Код: Выделить всё
function Initialize()
{
   StrategyName = "SimpleTrade";
   AddParameter("BuyPrice", 253, "", 1);
   AddParameter("SellPrice", 258, "", 1);
   AddParameter("Lot", 1000, "", 1);
   AddInput("Input1", Inputs.Candle, 5, true, "SBER=МБ ЦК");
   LongLimit = 1000;
   ShortLimit = -1000;
   AddGlobalVariable("NeedClose", Types.Boolean, false);
}
function OnUpdate()
{
   //evge 31.01.2022 https://alfadirect4.ru
   
   var CP = CurrentPosition();
   
   if (CP != 0 && NeedClose) { CloseLongLimit(SellPrice, Lot); NeedClose = false; }
   if (CP == 0 && !NeedClose) { EnterLongLimit(BuyPrice, Lot); NeedClose = true; }
   
}
 Изображения (1057)
 Изображения (1057) Архивы (82)
 Архивы (82) Текстовые файлы (9)
 Текстовые файлы (9) Документы (7)
 Документы (7) Скрипты Альфа-Директ 4 (30)
 Скрипты Альфа-Директ 4 (30)