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

 
Artyom Trishkin:
我们需要更深入地了解...

更深一层,那是哪里

所有的尝试,在新的指标下,都会导致挂起。

而与指标,这是不变的,有一个瞬间的打嗝。

解决办法可能是什么?

 
mila.com:

更深一层,那是哪里

所有的尝试,在新的指标下,都会导致挂断。

而在指标不变的情况下,会有一个瞬间的制动。

解决办法可能是什么?

在你的指标中--而不是在其中使用其他自定义指标的数据,特别是--搜索任何维度的分形,只需制作一个搜索这种分形的函数,并与它们一起工作。
 
Artyom Trishkin:
只要做函数来寻找这样的分形,并与之合作。

对你来说,这是一件简单的事情)。

但对我来说,这是一项不可能完成的任务。

这样的功能?


bool isDnFractal(int bar,int max,const double &low[])
  {
//---
   for(int i=1; i<=max; i++) {
      if(i<=leftSide && low[bar]>low[bar-i])    return(false);
      if(i<=rightSide && low[bar]>=low[bar+i])  return(false);
      }
//---
   return(true);
  }

这是一个较低的分形

如何使用它?

 
mila.com:

对你来说,这更容易做到)。

但对我来说,这是一个不可能完成的任务。

如何将该指标的功能植入我的指标中?


bool isDnFractal(int bar,int max,const double &low[])
  {
//---
   for(int i=1; i<=max; i++) {
      if(i<=leftSide && low[bar]>low[bar-i])    return(false);
      if(i<=rightSide && low[bar]>=low[bar+i])  return(false);
      }
//---
   return(true);
  }

那么,你需要它返回所需条形图上的分形的价格。在这里,我做了一个简单的指标。它有两个函数,你可以从里面拿出来在你的里面使用--我专门把它们组织成函数--有检查无效值的功能。

//+------------------------------------------------------------------+
//|                                             iFreeNumFractals.mq4 |
//|              Copyright 2016, Artem A. Trishkin, Skype artmedia70 |
//|                       https://login.mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Artem A. Trishkin, Skype artmedia70"
#property link      "https://login.mql5.com/ru/users/artmedia70"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot UpperFractal
#property indicator_label1  "UpperFractal"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot LowerFractal
#property indicator_label2  "LowerFractal"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrSteelBlue
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- input parameters
input          int      LeftNum=2;     // Количество баров слева
int leftNum;     // Количество баров слева
input          int      RightNum=2;    // Количество баров справа
int rightNum;    // Количество баров справа
//--- indicator buffers
double         BufferUpperFractal[];
double         BufferLowerFractal[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,BufferUpperFractal);
   SetIndexBuffer(1,BufferLowerFractal);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   PlotIndexSetInteger(0,PLOT_ARROW,159);
   PlotIndexSetInteger(1,PLOT_ARROW,159);
   SetIndexArrow(0,217);
   SetIndexArrow(1,218);
//---
   leftNum=(LeftNum<1?1:LeftNum);
   rightNum=(RightNum<1?1:RightNum);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   if(rates_total<leftNum+rightNum) return(0);
   int limit=rates_total-prev_calculated;
   if(limit>0) {
      ArrayInitialize(BufferUpperFractal,0.0);
      ArrayInitialize(BufferUpperFractal,0.0);
      limit=rates_total-leftNum-1;
      }
   //---
   for(int i=limit; i>rightNum; i--) {
      if(GetFreeUpperFractal(i,limit,high,leftNum,rightNum)>0) BufferUpperFractal[i]=high[i];
      if(GetFreeLowerFractal(i,limit,low ,leftNum,rightNum)>0) BufferLowerFractal[i]=low[i];
      }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+----------------------------------------------------------------------------+
double GetFreeLowerFractal(int shift,const int limit,const double &low[],int left_dimension=2,int right_dimension=2) {
   if(left_dimension<1)  left_dimension=1;
   if(right_dimension<1) right_dimension=1;
   if(shift-right_dimension<1 || shift+left_dimension>limit-1) return(-1);
   for(int i=shift; i>shift-right_dimension; i--) if(low[i]>low[i-1]) return(-1);
   for(int i=shift; i<shift+left_dimension; i++)  if(low[i]>low[i+1]) return(-1);
   return(low[shift]);
}
//+----------------------------------------------------------------------------+
double GetFreeUpperFractal(int shift,const int limit,const double &high[],int left_dimension=2,int right_dimension=2) {
   if(left_dimension<1)  left_dimension=1;
   if(right_dimension<1) right_dimension=1;
   if(shift-right_dimension<1 || shift+left_dimension>limit-1) return(-1);
   for(int i=shift; i>=shift-right_dimension; i--) if(high[i]<high[i-1]) return(-1);
   for(int i=shift; i<=shift+left_dimension; i++)  if(high[i]<high[i+1]) return(-1);
   return(high[shift]);
}
//+----------------------------------------------------------------------------+
 

为了将获取任意分形的函数从指标中分离出来,我们不应该通过引用传递数组high[]和low[]以及极限值。

由于我们的代码与MQL5非常接近,我们将不得不拒绝High[]、Low[]、iHigh() 和iLow()函数。这就是它在这个指标中的样子。

//+------------------------------------------------------------------+
//|                                             iFreeNumFractals.mq4 |
//|              Copyright 2016, Artem A. Trishkin, Skype artmedia70 |
//|                       https://login.mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Artem A. Trishkin, Skype artmedia70"
#property link      "https://login.mql5.com/ru/users/artmedia70"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot UpperFractal
#property indicator_label1  "UpperFractal"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot LowerFractal
#property indicator_label2  "LowerFractal"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrSteelBlue
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- input parameters
input          int      LeftNum=2;     // Количество баров слева
int leftNum;     // Количество баров слева
input          int      RightNum=2;    // Количество баров справа
int rightNum;    // Количество баров справа
//--- indicator buffers
double         BufferUpperFractal[];
double         BufferLowerFractal[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,BufferUpperFractal);
   SetIndexBuffer(1,BufferLowerFractal);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   // PlotIndexSetInteger(0,PLOT_ARROW,217);
   // PlotIndexSetInteger(1,PLOT_ARROW,218);
   SetIndexArrow(0,217);
   SetIndexArrow(1,218);
//---
   leftNum=(LeftNum<1?1:LeftNum);
   rightNum=(RightNum<1?1:RightNum);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   if(rates_total<leftNum+rightNum) return(0);
   int limit=rates_total-prev_calculated;
   if(limit>0) {
      ArrayInitialize(BufferUpperFractal,0.0);
      ArrayInitialize(BufferUpperFractal,0.0);
      limit=rates_total-leftNum-1;
      }
   //---
   for(int i=limit; i>rightNum; i--) {
      if(GetFreeUpperFractal(Symbol(),PERIOD_CURRENT,i,leftNum,rightNum)>0) BufferUpperFractal[i]=high[i];
      if(GetFreeLowerFractal(Symbol(),PERIOD_CURRENT,i,leftNum,rightNum)>0) BufferLowerFractal[i]=low[i];
      }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+----------------------------------------------------------------------------+
double GetFreeLowerFractal(const string symbol_name,ENUM_TIMEFRAMES timeframe,int shift,int left_dimension=2,int right_dimension=2) {
   int bars=Bars(symbol_name,timeframe);
   if(left_dimension<1)  left_dimension=1;
   if(right_dimension<1) right_dimension=1;
   if(shift-right_dimension<1 || shift+left_dimension>bars-1) return(-1);
   for(int i=shift; i>shift-right_dimension; i--) if(GetPriceLow(symbol_name,timeframe,i)>GetPriceLow(symbol_name,timeframe,i-1)) return(-1);
   for(int i=shift; i<shift+left_dimension; i++)  if(GetPriceLow(symbol_name,timeframe,i)>GetPriceLow(symbol_name,timeframe,i+1)) return(-1);
   return(GetPriceLow(symbol_name,timeframe,shift));
}
//+----------------------------------------------------------------------------+
double GetFreeUpperFractal(const string symbol_name,ENUM_TIMEFRAMES timeframe,int shift,int left_dimension=2,int right_dimension=2) {
   int bars=Bars(symbol_name,timeframe);
   if(left_dimension<1)  left_dimension=1;
   if(right_dimension<1) right_dimension=1;
   if(shift-right_dimension<1 || shift+left_dimension>bars-1) return(-1);
   for(int i=shift; i>=shift-right_dimension; i--) if(GetPriceHigh(symbol_name,timeframe,i)<GetPriceHigh(symbol_name,timeframe,i-1)) return(-1);
   for(int i=shift; i<=shift+left_dimension; i++)  if(GetPriceHigh(symbol_name,timeframe,i)<GetPriceHigh(symbol_name,timeframe,i+1)) return(-1);
   return(GetPriceHigh(symbol_name,timeframe,shift));
}
//+----------------------------------------------------------------------------+
double GetPriceHigh(const string symbol_name, ENUM_TIMEFRAMES timeframe, int shift){
   double array[1];
   if(CopyHigh(symbol_name,timeframe,shift,1,array)==1) return(array[0]);
   return(-1);
}
//+----------------------------------------------------------------------------+
double GetPriceLow(const string symbol_name, ENUM_TIMEFRAMES timeframe, int shift){
   double array[1];
   if(CopyLow(symbol_name,timeframe,shift,1,array)==1) return(array[0]);
   return(-1);
}
//+----------------------------------------------------------------------------+
然而,我们还应该从函数GetPriceHigh()和GetPriceLow()中检查出-1。
 
你好,建议如何使用15分钟的时间框架制作专家顾问,每20分钟检查一次数值,比如在9-20,9-40,然后是交叉RSI,如果在20分钟内越过该水平,则检查价格变化。这就是我需要解决的问题。
if (Hour()==9 && (Minute() == 20) && (RSI>70))
Price2==Bid;
     {
      if (Hour()==9 && (Minute() == 40) && (Bid<Price2))
  
         {
          ticket=OrderSend(Symbol(),OP_SELL, Lts, Bid, SP,0,0, NULL, Magic, 0, Blue);
          return(0);
         }
     }

也就是说,假设在9-20时,RSI被越过。我想让我的EA记住9-20的价格,并在9-40检查相对于9-20的价格的最后20分钟。如果它正在下降,它将打开一个空头。非常感谢你。
 
strongflex:
你好,建议如何使用15分钟的时间框架制作专家顾问,每20分钟检查一次数值,比如在9-20,9-40,然后是交叉RSI,如果在20分钟内越过该水平,则检查价格变化。这就是我需要解决的问题。
if (Hour()==9 && (Minute() == 20) && (RSI>70))
Price2==Bid;
     {
      if (Hour()==9 && (Minute() == 40) && (Bid<Price2))
  
         {
          ticket=OrderSend(Symbol(),OP_SELL, Lts, Bid, SP,0,0, NULL, Magic, 0, Blue);
          return(0);
         }
     }

也就是说,假设在9-20时,RSI被越过。我想让我的EA记住9-20的价格,并在9-40检查相对于9-20的价格的最后20分钟。如果它正在下降,它将打开一个空头。非常感谢你。

:)

如果你在9.22运行专家顾问怎么办?

如果出现了系统或终端故障呢?价格就会损失。

也就是说,当这个检查的时间到来时,你必须寻找20分钟前的情况。时间已经到了,其中的分钟数大于或等于20的倍数--查看柱状图上RSI的状态,这是20分钟前的情况。如果它有正确的交叉点,那么就按计划进行......

然而,在M15上,你无法确定确切的穿越时间和确切的价格,但你可以看看M1上的价格--至少准确15倍以上。

 
Artyom Trishkin:

:)

如果你在9.22的时候运行EA呢?

如果出现了系统或终端故障怎么办?价格就会损失。

也就是说,当这个检查的时间到来时,你必须寻找20分钟前的情况。时间已经到了,其中的分钟数大于或等于20的倍数--查看柱状图上RSI的状态,这是20分钟前的情况。如果它有理想的交叉点,那么我们就按计划进行......。

然而,在M15上,你无法确定确切的穿越时间和确切的价格,但你可以看看M1上的价格--至少准确15倍以上。

好吧,我想我做不到)))伙计们,谁能写这部分的代码? 我将支付1000卢布
 
strongflex:
好吧,我明白,我不能应付)))),谁能写这部分代码? 我将支付1000卢布。
double rci20 = iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,20);//RCI 20 минут назад.
   Comment("RSI = ",rci20);

而那一千块钱呢?

(只是开玩笑)

 
Alekseu Fedotov:
double rci20 = iRSI(NULL,PERIOD_M1,14,PRICE_CLOSE,20);//RCI 20 минут назад.
   Comment("RSI = ",rci20);

而那一千块钱呢?

(开玩笑)

RSI需要15分钟的时间。我们需要EA在开市后每20分钟检查一次(9-00,9-20,9-40等),假设在10-20有一个从低于70水平到高于70水平的交叉,它就会记住这个价格,在10-40检查,如果价格低于10-20,它就会打开一个空头。
原因: