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

 

阿列克谢-斯捷潘延科 谢谢你。


Valeriy Yastremskiy 也许是因为代码不完整,因为我删除了所有不必要的功能。


//+----------------------------------------------------------------------------+
//|                                                          AverageRange.mq4  |
//|                                                    Ким Игорь В. aka KimIV  |
//|                                                       http://www.kimiv.ru  |
//|                                                                            |
//|  14.09.2005  Скрипт для расчёта:                                           |
//|              средней волатильности инструмента High-Low                    |
//|              среднего размера тела свечи       ABS(Open-Close)             |
//|              среднего размера тени свечи                                   |
//|                                                                            |
//|  17.11.2007  Возможность использования заданного количества баров          |
//+----------------------------------------------------------------------------+
#property copyright "Ким Игорь В. aka KimIV"
#property link      "http://www.kimiv.ru"
#property  show_inputs

extern datetime BeginDateCalc = D'2013.01.01';
extern datetime EndDateCalc   = D'2013.12.31';
extern int      NumberOfBars  = 100;         


//+----------------------------------------------------------------------------+
//|  script program start function                                             |
//+----------------------------------------------------------------------------+
void start() {
   int    i;           
   int    b  = 0;     
   int    bb = 0;      
   int    h  = 0;      
   int    l  = 0;     
   int    s  = 0;      
   int    t  = 0;      
   string st = "";        

  for (i = Bars; i > 0; i--) {
    
    if ((Time [i] >= BeginDateCalc && Time [i] <= EndDateCalc && NumberOfBars <= 0)
    || (NumberOfBars > 0 && NumberOfBars >= i)) {
      
      if (bb == 0) bb = i;
      s += (High [i] - Low [i]) / Point;
      t += MathAbs (Open [i] - Close [i]) / Point;
      
      if (Open [i] > Close [i]) {
        h += (High [i] - Open [i]) / Point;
        l += (Close [i] - Low [i]) / Point;
      } else {
        h += (High [i] - Close [i]) / Point;
        l += (Open [i] - Low [i]) / Point;
      }
      
      b++;
    }
  }

  st =      "Начало: " + TimeToStr (Time [bb], TIME_DATE | TIME_MINUTES) + "\n";
  st = st + "Конец: " + TimeToStr (Time [bb - b + 1], TIME_DATE | TIME_MINUTES) + "\n";
  st = st + "Использовано баров: " + b + "\n";
  st = st + "Средняя волатильность: " + s / b + " п.\n";
  st = st + "Средний размер тела: " + t / b + " п.\n";
  st = st + "Средний размер верхней тени: " + h / b + " п.\n";
  st = st + "Средний размер нижней тени: " + l / b + " п.";

  Comment (st);
}
//+----------------------------------------------------------------------------+
Aleksei Stepanenko
Aleksei Stepanenko
  • www.mql5.com
Профиль трейдера
 
Valeriy Yastremskiy #:

说实话,我不明白Kim的逻辑,为什么条形时间超过设定值和计算条数为负数的条件下,计算条数大于条数,Barz))))。而同时,它只是纠正了自定义参数)

而且,它甚至没有显示用户弄错了的提醒)

从逻辑上讲,如果指定了NumberOfBars(大于0),那么时间就会被忽略,只考虑最新的条形图。

但用户可能会在日期上犯错,或者如果在报价中出现漏洞,那么就不会打印出任何东西,它只是返回DivideByZero :-)

 
嗨,

,谁能知道如何将报价从mt5转换到mt4?或者有什么方法可以利用mt5到mt4的更好的历史,除了TDS2😊。
 
Pavel Malyshko #:
嗨, ,谁能知道如何将报价从mt5转换到mt4?或者有什么方法可以利用mt5到mt4的更好的历史,除了TDS2😊。

出口/进口
 
MakarFX #:
出口/进口

所以mt5有不同的报价格式,mt4不会读取它们,这就是问题所在...😎

 
Pavel Malyshko #:

所以mt5有不同的报价格式,mt4不会读取它们,这就是问题所在...😎

MT5导出到csv,MT4读取所有内容

 
Oksana_Timakova Point;

为什么我需要除以点?

...

我强烈推荐它。

s+=MathRound((High [i] - Low [i]) / Point);

否则你会得到一个 "哎呀"))。

void OnStart(){
   double first=0.00001;
   double point=0.00001;
   for(uint i=0;i<10;++i){
      double value=NormalizeDouble(first+i*point,5);
      int res=(int)((value-first)/point);
      if (res!=i)
         PrintFormat("Alert: (%.5 f-%.5 f)/%.5 f!=%u, but ==%i",value,first,point,i,res);
   }
}
2021.09.12 11:06:26.041 Script test EURGBP,H1: removed
2021.09.12 11:06:26.038 test EURGBP,H1: uninit reason 0
2021.09.12 11:06:26.038 test EURGBP,H1: Alert: (0.00007-0.00001)/0.00001!=6, but ==5
2021.09.12 11:06:26.038 test EURGBP,H1: Alert: (0.00003-0.00001)/0.00001!=2, but ==1
2021.09.12 11:06:26.038 test EURGBP,H1: initialized
2021.09.12 11:06:25.998 Script test EURGBP,H1: loaded successfully
 

如何使指标窗口完全隐藏价格图表?

我不能通过ChartSetInteger(0,CHART_HEIGHT_IN_PIXELS,0,0)来实现,我必须先设置指标的大小,然后再把价格窗口的高度加进去。

int chart_height=(int)ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0);
IndicatorSetInteger(INDICATOR_HEIGHT,200+chart_height);


然而,如果你在底部打开订单窗口,指标窗口的尺寸就会变得比屏幕尺寸大,而且梗概又会显示价格。

我不知道如何测量订单窗口,此外,它一直在变化。

该怎么做?

 

请帮助我们!

帮助把这个代码翻译成mql5...

我想了解如何与手柄合作。

//+------------------------------------------------------------------+
//|                                                Stochastic.v1.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers  2
#property indicator_plots    2
#property indicator_minimum -51
#property indicator_maximum  51
#property indicator_level1   0
#property indicator_levelstyle 0
#property indicator_levelcolor clrDimGray
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDimGray
#property indicator_style1  STYLE_SOLID
#property indicator_width1  0
//--- plot Label2
#property indicator_label2  "Label2"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  0
//--- input parameters
input int             WeekCount   = 1;     // Ограничение истории в неделях(0-вся история)
input int             StochPeriod = 14;
input ENUM_TIMEFRAMES TimeFrame   = PERIOD_CURRENT;
//--- indicator buffers
double   Label1Buffer[];
double   Label2Buffer[];
int      index=-1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorDigits(2);
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);
   SetIndexBuffer(1,Label2Buffer);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   ArrayInitialize(Label1Buffer,0);
   ArrayInitialize(Label2Buffer,0);
   int limit,i;
   int barPlus=iBarShift(_Symbol,_Period,iTime(_Symbol,PERIOD_W1,WeekCount));
   limit=rates_total-prev_calculated-1;
   if(WeekCount!=0)limit=barPlus-2;
   if(limit<1) return(0);
   for(i=limit;i>=0;i--)
     {
      index=iBarShift(_Symbol,TimeFrame,time[i],false);
      Label1Buffer[i]=iStochastic(_Symbol,TimeFrame,StochPeriod,3,3,MODE_SMA,1,MODE_MAIN,index)-50; 
     }
   for(i=limit;i>=0;i--)
     {
      Label2Buffer[i]=iMAOnArray(Label1Buffer,0,StochPeriod*3,0,MODE_SMA,i);
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

我希望得到您的帮助。

 
MakarFX #:

请帮助我们!

帮助把这个代码翻译成mql5...

我想了解如何与手柄合作。

我希望得到您的帮助。

唯一的问题是关于这句话

  Label1Buffer[i]=iStochastic(_Symbol,TimeFrame,StochPeriod,3,3,MODE_SMA,1,MODE_MAIN,index)-50; 
-50 冗余和阵列