MQL4,一個bias策略測試時出現問題

 

當我的BIAS參數大於101,就無法使用EVERYTICK回測EA。程式碼有哪裡出了問題嗎?

#property copyright ""
#property link      ""
#property strict
//-----------------------------
extern int MAK3 = 233;    //趨勢線根數參數
extern double Lot = 0.1; //手數
//---------BiasControlTable----------
extern double BIAS = 0.1; //(1.0%=1.0)大於多少BIAS才進單
extern double BIASV = 1.0; //(110%=1.1)大於前幾根BIAS百分比才進
extern int BiasK =1; //(3=3根)大於前幾根平均BIAS才進
extern int MABi1 =30; //BIAS參數
//----------BaseCT---------
extern int AccMony = 10000; //本金倉位(會影響總獲利%)
extern double TotalSL = 20; //止損百分比%
extern int Magic=20210806;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
datetime lastT;
double B1,S1,HighS,LowB,Bx,Bs;
int B,S;
bool BBTP,SSTP;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(lastT == Time[1])
      return;
   lastT = Time[1];
   double MAC1 = iMA(NULL,0,MAK3,0,MODE_SMA,PRICE_CLOSE,1);
   BaisBlance(Bs,1);
   BaisBlance(Bx,BiasK);

   if(Bs>BIAS && Bs>=Bx/BiasK*BIASV)
     {
      if(Close[1]>MAC1)
        {
         BUY();
        }
      if(Close[1]<MAC1)
        {
         SELL();
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
void SELL()
  {
   OrderSend(NULL,OP_SELL,Lot,Bid,3,0,0,NULL,Magic,Magic,clrRed);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void BUY()
  {
   OrderSend(NULL,OP_BUY,Lot,Ask,3,0,0,NULL,Magic,Magic,clrBlue);
  }
//+------------------------------------------------------------------+
// BUY單平倉
void closeBuyall()
  {
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
        {
         if(OrderType()==0 && OrderMagicNumber()==Magic)   //BUY單:0 或S ELL單:1
           {
            OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),clrGreen);
           }
         else(OrderDelete(OrderTicket(),clrGreen));
        }
     }
  }
//+------------------------------------------------------------------+
// Sell單平倉
void closeSellall()
  {
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
        {
         if(OrderType()==1 && OrderMagicNumber()==Magic)   //BUY單:0 或S ELL單:1
           {
            OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),clrGreen);
           }
         else(OrderDelete(OrderTicket(),clrGreen));
        }
     }
  }
//-------------------------------------------
void BaisBlance(double &bi,int Biask)
  {
   bi=0;
   for(int i=0; i<Biask; i++)
      bi = bi + 100*(MathAbs(Close[i+1]-iMA(NULL,0,MABi1,0,MODE_SMA,PRICE_CLOSE,i+1))/iMA(NULL,0,MABi1,0,MODE_SMA,PRICE_CLOSE,i+1));
   return;
  }
//+------------------------------------------------------------------+

附加的文件:
02.mq4  8 kb
01.png  118 kb
 
//-------------------------------------------
void BaisBlance(double &bi,int Biask)
  {
   bi=0;
   for(int i=0; i<Biask; i++)
      bi = bi + 100*(MathAbs(Close[i+1]-iMA(NULL,0,MABi1,0,MODE_SMA,PRICE_CLOSE,i+1))/iMA(NULL,0,MABi1,0,MODE_SMA,PRICE_CLOSE,i+1));
   return;
  }

数据不足101柱,MA为0,即使用了0作为除数……

需要加入0判断,再计算bi