代码在编译时总是提示begin-end不匹配

//------------------------------------------------------------------------

// 简称:TrendFollowing

// 类型:自动交易策略

// 版本:v2.2(符合TB事件驱动模型)

//------------------------------------------------------------------------


Params

   Numeric FastLength(5);    

   Numeric SlowLength(20);    

   Numeric ATRLength(14);    

   Numeric StopLossK(2);      

   Numeric TakeProfitK(3);    


Vars

   Series<Numeric> MA_Fast;    

   Series<Numeric> MA_Slow;    

   Series<Numeric> ATRVal;      

   Series<Numeric> StopLossPrice(0);  

   Series<Numeric> TakeProfitPrice(0);

   Series<Numeric> TrueRange;        


Begin

   // 指标计算(必须放在OnBar事件外)

   MA_Fast = AverageFC(Close,FastLength);

   MA_Slow = AverageFC(Close,SlowLength);

   

   // ATR计算(符合TB事件驱动模型)

   TrueRange = Max(Max(High - Low, Abs(High - Close[1])), Abs(Low - Close[1]));

   ATRVal = AverageFC(TrueRange, ATRLength);

   

   // 事件驱动逻辑

   OnBar()

   {

       // 开仓信号

       If(CrossOver(MA_Fast,MA_Slow) && MarketPosition !=1)

       {

           Buy(0,Close);

           StopLossPrice = Close - StopLossK*ATRVal;

           TakeProfitPrice = Close + TakeProfitK*ATRVal;

       }

       End If

       

       If(CrossUnder(MA_Fast,MA_Slow) && MarketPosition !=-1)

       {

           SellShort(0,Close);

           StopLossPrice = Close + StopLossK*ATRVal;

           TakeProfitPrice = Close - TakeProfitK*ATRVal;

       }

       End If

       

       // 多头平仓逻辑

       If(MarketPosition ==1)

       {

           StopLossPrice = Max(StopLossPrice, High[1] - StopLossK*ATRVal);

           If(Low <= StopLossPrice || High >= TakeProfitPrice)

           {

               Sell(0,Min(Open,StopLossPrice));

           }

           End If

       }

       End If

       

       // 空头平仓逻辑

       If(MarketPosition ==-1)

       {

           StopLossPrice = Min(StopLossPrice, Low[1] + StopLossK*ATRVal);

           If(High >= StopLossPrice || Low <= TakeProfitPrice)

           {

               BuyToCover(0,Max(Open,StopLossPrice));

           }

           End If

       }

       End If

   }

End

该代码在编译时总是提示begin-end不匹配,请问大家时怎么回事?可以帮忙完善一下吗?

持仓与信号不匹配,时可否跳出警示窗口
编译
为什么会显示 小括号不匹配?
CurrentBar 编译时 系统提示无法识别的字符串
大括号不匹配
总是在启动时提示出错,是什么问题,如何解决
新建公式编译时,提示程序体不存在,错误号为1001
总是提示错误:无法识别的字符串bar
编译时提示错误,错误号2002,帮忙看看是否有问题
为什么总是提示错误号1002

//------------------------------------------------------------------------


// 简称:TrendFollowing


// 类型:自动交易策略


// 版本:v2.2(符合TB事件驱动模型)


//------------------------------------------------------------------------

Params

  Numeric FastLength(5);    

  Numeric SlowLength(20);    

  Numeric ATRLength(14);    

  Numeric StopLossK(2);      

  Numeric TakeProfitK(3);    

Vars

  Series<Numeric> MA_Fast;    

  Series<Numeric> MA_Slow;    

  Series<Numeric> ATRVal;      

  Series<Numeric> StopLossPrice(0);  

  Series<Numeric> TakeProfitPrice(0);

  Series<Numeric> TrueRange;        

Events

OnBar(ArrayRef<Integer> indexs)

  {

  MA_Fast = AverageFC(Close,FastLength);

  MA_Slow = AverageFC(Close,SlowLength);

  // ATR计算(符合TB事件驱动模型)

  TrueRange = Max(Max(High - Low, Abs(High - Close[1])), Abs(Low - Close[1]));

  ATRVal = AverageFC(TrueRange, ATRLength);

  If(CrossOver(MA_Fast,MA_Slow) && MarketPosition !=1)

      {

      Buy(0,Close);

  StopLossPrice = Close - StopLossK*ATRVal;

     TakeProfitPrice = Close + TakeProfitK*ATRVal;

 }

   If(CrossUnder(MA_Fast,MA_Slow) && MarketPosition !=-1)

    {

   SellShort(0,Close);

      StopLossPrice = Close + StopLossK*ATRVal;

      TakeProfitPrice = Close - TakeProfitK*ATRVal;

  }

    // 多头平仓逻辑

      If(MarketPosition ==1)

      {

          StopLossPrice = Max(StopLossPrice, High[1] - StopLossK*ATRVal);

          If(Low <= StopLossPrice || High >= TakeProfitPrice)

          {

              Sell(0,Min(Open,StopLossPrice));

          }

      }

    If(MarketPosition ==-1)

      {

          StopLossPrice = Min(StopLossPrice, Low[1] + StopLossK*ATRVal);

          If(High >= StopLossPrice || Low <= TakeProfitPrice)

     {


              BuyToCover(0,Max(Open,StopLossPrice));


          }

      }

}


👍

👍,谢谢了