Поэтому стоп в таком виде.
Код: Выделить всё
function Initialize()
{
   StrategyName = "FollowEMA";
   AddParameter("Period", 20, "EMA Period", 1);
   AddParameter("Step", 0.02, "PSAR Step", 1);
   AddParameter("Maximum", 0.2, "PSAR Maximum", 1);
   AddParameter("SL", 2, "Stop Loss", 1);
   AddInput("Input1", Inputs.Candle, 1, true, "");
   LongLimit = 1000;
   ShortLimit = -1000;
   AddChartIndicator("EMA", new Dictionary <string, string>{{"Period", "Period"}});
   AddChartIndicator("ParabolicSAR", new Dictionary <string, string>{{"Step","Step"},{"Maximum","Maximum"}});   
}
function OnUpdate()
{
   var I = Input1;
   var C = Input1.Close;
   var E = EMA(I, Period);
   var P = PSAR(I, Step, Maximum);
   var CP = CurrentPosition();
            
   if (C[0] > E[0] && CP == 0)
   {
      CancelActiveOrders(true);
      EnterLongLimit(E[0]);
   }
   if (CurrentPLper() <= -SL) 
   {
        CancelActiveOrders(true);
        CloseLong();
   } 
   
   else
      
   if (C[0] < P[0] && CP > 0)
   {
      CancelActiveOrders(true);
      CloseLongLimit(P[0]);      
   }
   
}


