新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 - 页 564

 
Ihor Herasko:

上述代码中shift和iy变量的值没有被检查出阵列 的异常值。因此,一切都符合逻辑。在使用前检查它们的值,错误就会消失。

而且更具体地说,你应该知道CountBars和TimeFrame变量是如何生成的。

CountBars =400和TimeFrame =30,是在外部静态设置的。

在M30上一切正常,在M15上则飞了出去。

如何检查shift和iy的异常值

   if(TimeFrame>Period()) 
     {
      ArrayCopySeries(santa1,5,Symbol(),TimeFrame);
      summ=CountBars+TimeFrame/Period();
      shift=0;
      for(int iy=0; shift<summ; shift++) 
        {
        if(iy>ArraySize(santa1))continue;
        if(shift>ArraySize(santa1))continue;
         if(Time[shift]<santa1[iy]) iy++;//вот эта santa1[iy] "array out of range"

         list[shift]=bufbuy[iy];
        }
     }
 

也许有人会花时间查一下错误在哪里。

#property strict
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Yellow
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_color4 Yellow
#property indicator_color5 Aqua

extern bool Crash=FALSE;
extern int TimeFrame=30;
extern int Length = 7;
extern int Method = 3;
extern int Smoothing=2;
extern int Filter=2;
extern bool RealTime=TRUE;
extern bool Steady= FALSE;
extern bool Color = TRUE;
extern bool Alerts= TRUE;

extern int CountBars=400;
double sik[];
double list[];
double bufbuy[];
double par6[];
double par1[];
double par2[];
double par3[];
double nugni[];
bool flag2 = TRUE;
bool flag1 = TRUE;
datetime time1 = 0;
datetime time2 = 0;
int stad=0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init() 
  {
   string lex;
   IndicatorBuffers(8);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(0,list);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(1,par1);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(2,par2);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,233);
   SetIndexBuffer(3,par3);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,234);
   SetIndexBuffer(4,nugni);
   SetIndexBuffer(5,sik);
   SetIndexBuffer(6,par6);
   SetIndexBuffer(7,bufbuy);
   if(Length<2) Length=2;
   if(Method < MODE_SMA) Method = 0;
   if(Method> MODE_LWMA) Method = 3;
   if(Smoothing<0) Smoothing=0;
   if(Filter<0) Filter=0;
   if(TimeFrame<Period() && TimeFrame!=0) TimeFrame=Period();
   switch(TimeFrame) 
     {
      case 1:
         lex="M1";
         break;
      case 5:
         lex="M5";
         break;
      case 15:
         lex="M15";
         break;
      case 30:
         lex="M30";
         break;
      case 60:
         lex="H1";
         break;
      case 240:
         lex="H4";
         break;
      case 1440:
         lex="D1";
         break;
      case 10080:
         lex="W1";
         break;
      case 43200:
         lex="MN1";
         break;
      default:
         lex="";
     }
   string str_lol="trend "+lex+" |  "+Length+" , "+Method+" , "+Smoothing+" , "+Filter+"  | ";
   IndicatorShortName(str_lol);
   return (0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start() 
  {
   int santa1[];
   int summ;
   string str_lol;
   if(Bars<100) 
     {
      IndicatorShortName("Bars less than 100");
      return (0);
     }
   if(time1<iTime(NULL,TimeFrame,0)) 
     {
      flag1 = FALSE;
      flag2 = FALSE;
      time1=iTime(NULL,TimeFrame,0);
     }
   if(!RealTime) 
     {
      if(time2 == iTime(NULL, TimeFrame, 0)) return (0);
      time2=iTime(NULL,TimeFrame,0);
      stad=TimeFrame/Period()+1;
      if(stad==0) stad=1;
     }
   double MA1 = 0;
   double MA2 = 0;
   double MA3 = 0;
   double MA4 = 0;
   double MA5 = 0;
   if(CountBars>iBars(NULL,TimeFrame) || CountBars>Bars-Length-1) CountBars=MathMin(Bars-Length-1,iBars(NULL,TimeFrame)-Length-1);
   if(Crash && CountBars>0) 
     {
      CountBars-=10;
      IndicatorShortName("Crash: "+CountBars+"     ");
     }
   if(Crash && CountBars<0) IndicatorShortName("Crash");
   int shift=CountBars;
   list[shift+1]=Close[shift+1];
   bufbuy[shift+1]=Close[shift+1];
   while(shift>=0) 
     {
      MA1 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_HIGH, shift);
      MA2 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_LOW, shift);
      MA3 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_OPEN, shift);
      MA4 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_CLOSE, shift);
      MA5 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_CLOSE, shift + Smoothing);
      if(Steady==TRUE) 
        {
         MA4 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_MEDIAN, shift);
         MA5 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_MEDIAN, shift + Smoothing);
        }
      sik[shift]=MathAbs(((MA4-MA5)/MathMax(MA1-MA2,MathMax(MA1-MA5,MA5-MA2))+(MA4-MA3)/(MA1-MA2))/2.0) *((MA4-MA5+
                         (MA4-MA3))/2.0);
      list[shift]=list[shift+1]+sik[shift];
      if(Filter>0)
         if(MathAbs(list[shift]-(list[shift+1]))<Filter*Point) list[shift]=list[shift+1];
      if(TimeFrame>Period()) bufbuy[shift]=list[shift];
      shift--;
     }
   if(TimeFrame>Period()) 
     {
      ArrayCopySeries(santa1,5,Symbol(),TimeFrame);
      summ=CountBars+TimeFrame/Period();
      shift=0;
      for(int iy=0; shift<summ; shift++) 
        {
        if(iy>ArraySize(santa1))continue;
        if(shift>ArraySize(santa1))continue;
         if(Time[shift]<santa1[iy]) iy++;//вот эта 
         list[shift]=bufbuy[iy];
        }
     }
   for(shift=CountBars; shift>=0; shift--) 
     {
      par6[shift]=par6[shift+1];
      if(list[shift] -(list[shift + 1])> 0.0) par6[shift] = 1;
      if(list[shift + 1] - list[shift] > 0.0) par6[shift] = -1;
      if(Color==TRUE) 
        {
         if(par6[shift]>0.0) 
           {
            par1[shift]=list[shift];
            if(par6[shift+1]<0.0) par1[shift+1]=list[shift+1];
            par2[shift]=EMPTY_VALUE;
              } else {
            if(par6[shift]<0.0) 
              {
               par2[shift]=list[shift];
               if(par6[shift+1]>0.0) par2[shift+1]=list[shift+1];
               par1[shift]=EMPTY_VALUE;
              }
           }
        }
      if(Alerts==TRUE) 
        {
         par3[shift] = EMPTY_VALUE;
         nugni[shift] = EMPTY_VALUE;
         if(par6[shift] == 1.0 && par6[shift + 1] == -1.0) par3[shift] = list[shift + 1] - (Ask - Bid);
         if(par6[shift] == -1.0 && par6[shift + 1] == 1.0) nugni[shift] = list[shift + 1] + (Ask - Bid);
        }
     }

   return (0);
  }
//+------------------------------------------------------------------+
 
PolarSeaman:

也许有人会花时间查一下错误在哪里。

#property strict
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Yellow
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_color4 Yellow
#property indicator_color5 Aqua

extern bool Crash=FALSE;
extern int TimeFrame=30;
extern int Length = 7;
extern int Method = 3;
extern int Smoothing=2;
extern int Filter=2;
extern bool RealTime=TRUE;
extern bool Steady= FALSE;
extern bool Color = TRUE;
extern bool Alerts= TRUE;

extern int CountBars=400;
double sik[];
double list[];
double bufbuy[];
double par6[];
double par1[];
double par2[];
double par3[];
double nugni[];
bool flag2 = TRUE;
bool flag1 = TRUE;
datetime time1 = 0;
datetime time2 = 0;
int stad=0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init() 
  {
   string lex;
   IndicatorBuffers(8);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(0,list);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(1,par1);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(2,par2);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,233);
   SetIndexBuffer(3,par3);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,234);
   SetIndexBuffer(4,nugni);
   SetIndexBuffer(5,sik);
   SetIndexBuffer(6,par6);
   SetIndexBuffer(7,bufbuy);
   if(Length<2) Length=2;
   if(Method < MODE_SMA) Method = 0;
   if(Method> MODE_LWMA) Method = 3;
   if(Smoothing<0) Smoothing=0;
   if(Filter<0) Filter=0;
   if(TimeFrame<Period() && TimeFrame!=0) TimeFrame=Period();
   switch(TimeFrame) 
     {
      case 1:
         lex="M1";
         break;
      case 5:
         lex="M5";
         break;
      case 15:
         lex="M15";
         break;
      case 30:
         lex="M30";
         break;
      case 60:
         lex="H1";
         break;
      case 240:
         lex="H4";
         break;
      case 1440:
         lex="D1";
         break;
      case 10080:
         lex="W1";
         break;
      case 43200:
         lex="MN1";
         break;
      default:
         lex="";
     }
   string str_lol="trend "+lex+" |  "+string(Length)+" , "+string(Method)+" , "+string(Smoothing)+" , "+string(Filter)+"  | ";
   IndicatorShortName(str_lol);
   return (0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start() 
  {
   int santa1[];
   int summ;
   string str_lol;
   if(Bars<100) 
     {
      IndicatorShortName("Bars less than 100");
      return (0);
     }
   if(time1<iTime(NULL,TimeFrame,0)) 
     {
      flag1 = FALSE;
      flag2 = FALSE;
      time1=iTime(NULL,TimeFrame,0);
     }
   if(!RealTime) 
     {
      if(time2 == iTime(NULL, TimeFrame, 0)) return (0);
      time2=iTime(NULL,TimeFrame,0);
      stad=TimeFrame/Period()+1;
      if(stad==0) stad=1;
     }
   double MA1 = 0;
   double MA2 = 0;
   double MA3 = 0;
   double MA4 = 0;
   double MA5 = 0;
   if(CountBars>iBars(NULL,TimeFrame) || CountBars>Bars-Length-1) CountBars=MathMin(Bars-Length-1,iBars(NULL,TimeFrame)-Length-1);
   if(Crash && CountBars>0) 
     {
      CountBars-=10;
      IndicatorShortName("Crash: "+string(CountBars)+"     ");
     }
   if(Crash && CountBars<0) IndicatorShortName("Crash");
   int shift=CountBars;
   list[shift+1]=Close[shift+1];
   bufbuy[shift+1]=Close[shift+1];
   while(shift>=0) 
     {
      MA1 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_HIGH, shift);
      MA2 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_LOW, shift);
      MA3 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_OPEN, shift);
      MA4 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_CLOSE, shift);
      MA5 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_CLOSE, shift + Smoothing);
      if(Steady==TRUE) 
        {
         MA4 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_MEDIAN, shift);
         MA5 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_MEDIAN, shift + Smoothing);
        }
      sik[shift]=MathAbs(((MA4-MA5)/MathMax(MA1-MA2,MathMax(MA1-MA5,MA5-MA2))+(MA4-MA3)/(MA1-MA2))/2.0) *((MA4-MA5+
                         (MA4-MA3))/2.0);
      list[shift]=list[shift+1]+sik[shift];
      if(Filter>0)
         if(MathAbs(list[shift]-(list[shift+1]))<Filter*Point) list[shift]=list[shift+1];
      if(TimeFrame>Period()) bufbuy[shift]=list[shift];
      shift--;
     }
   if(TimeFrame>Period()) 
     {
      ArrayCopySeries(santa1,5,Symbol(),TimeFrame);
      summ=CountBars+TimeFrame/Period();
      shift=0;
      for(int iy=0; shift<summ; shift++) 
        {
        if(iy>ArraySize(santa1))continue;
        if(shift>ArraySize(santa1))continue;
         if(Time[shift]<santa1[iy]) iy++;//вот эта 
         list[shift]=bufbuy[iy];
        }
     }
   for(shift=CountBars; shift>=0; shift--) 
     {
      par6[shift]=par6[shift+1];
      if(list[shift] -(list[shift + 1])> 0.0) par6[shift] = 1;
      if(list[shift + 1] - list[shift] > 0.0) par6[shift] = -1;
      if(Color==TRUE) 
        {
         if(par6[shift]>0.0) 
           {
            par1[shift]=list[shift];
            if(par6[shift+1]<0.0) par1[shift+1]=list[shift+1];
            par2[shift]=EMPTY_VALUE;
              } else {
            if(par6[shift]<0.0) 
              {
               par2[shift]=list[shift];
               if(par6[shift+1]>0.0) par2[shift+1]=list[shift+1];
               par1[shift]=EMPTY_VALUE;
              }
           }
        }
      if(Alerts==TRUE) 
        {
         par3[shift] = EMPTY_VALUE;
         nugni[shift] = EMPTY_VALUE;
         if(par6[shift] == 1.0 && par6[shift + 1] == -1.0) par3[shift] = list[shift + 1] - (Ask - Bid);
         if(par6[shift] == -1.0 && par6[shift + 1] == 1.0) nugni[shift] = list[shift + 1] + (Ask - Bid);
        }
     }

   return (0);
  }
//+
 

伙计们,告诉我如何将数据添加到文件的新行上

我的写作功能。

void Write(string file,string text,bool print)
  {
   filehandle=FileOpen(file,FILE_WRITE|FILE_CSV,'|');
   FileWriteString(filehandle,text);
   FileClose(filehandle);
  }

这是我发给它的东西。

Write(subfolder+"\\"+string(TF)+"\\TS"+string(ts)+"\\"+string(st)+"_"+string(st2)+".txt",
                                 string(mv)+"|"+
                                 string(b)+"|"+
                                 string(rs)+"|"+
                                 string(m1)+"|"+
                                 string(m2)+"|"
                                 ,NoPrint);

我需要在它下面添加更多的线。

Write(subfolder+"\\"+string(TF)+"\\TS"+string(ts)+"\\"+string(st)+"_"+string(st2)+".txt",
                                 string(mv)+"|"+
                                 string(b)+"|"+
                                 string(rs)+"|"+
                                 string(m1)+"|"+
                                 string(m2)+"|"
                                 ,NoPrint);
 
Nikolay Gaylis:

伙计们,告诉我如何将数据添加到文件的新行上

我的写作功能。

这是我发给它的东西。

我需要在这条线下面添加更多的数据。

带有SEEK_END标志的FileSeek()将帮助你。

<
 
Nikolay Gaylis:

你在代码中替换了

//+------------------------------------------------------------------+

//+

但它并没有帮助)

 

伙计们,你们能告诉我为什么Alpari上的顾问经常失败[无效量],尽管手数不超过最大值,交易从23-45到1-00。

我附上了日志,在其他经纪公司没有这样的错误。

附加的文件:
Alpari_Logs.txt  35 kb
 

我从这里的例子中提取了代码,正在处理它

我定义了一个方法

bool CControlsDialog::OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam){

        //....

}

它抱怨说它已经被定义了,并且有一个主体。

问题:它的定义在哪里?

Документация по MQL5: Стандартная библиотека / Панели и диалоги / CButton
Документация по MQL5: Стандартная библиотека / Панели и диалоги / CButton
  • www.mql5.com
//|                                               ControlsButton.mq5 | //|                        Copyright 2017, MetaQuotes Software Corp. | //|                                             https://www.mql5.com | //| defines                                                          |  INDENT_LEFT                         (11)      ...
 
Roman Sharanov:

我从这里的例子中提取了代码,正在处理它

我定义了一个方法

它抱怨说它已经被定义了,并且有一个主体。

问题:它的定义在哪里?

试着在终端文件夹中 搜索。我找到了ControlsDialog.mqh文件,其中的OnEvent()
 

晚上好!

我在思考如何添加一个通用的(针对不同的工具)代码来计算基于存款百分比的交易手数。

我是这样做的。

input double MaximumRisk=0.02;                  //Риск в сделке от депозита

{Lots = NormalizeDouble(((AccountBalance()*MaximumRisk)/((MathAbs(Price-SL))/Point)/((MarketInfo(Symbol(),MODE_LOTSIZE)*(MarketInfo(Symbol(),MODE_ASK)+Point))
-(MarketInfo(Symbol(),MODE_LOTSIZE)*MarketInfo(Symbol(),MODE_ASK)))),Digits);}

价格(开盘价)和SL(止损)是分开计算的。

对于报价货币为美元的货币对(如EURUSD),SPX500指数和黄金--都能正确计算,但对于报价货币为美元的货币对(如USDJPY),则无法工作。

拜托,我错过了什么?

原因: