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

 
inter78:

事实上,我做了,但我不喜欢漫长的反应时间

时间不长,只是打个勾......但总的来说,你需要阅读帮助。 你不能通过 "尝试 "来学习MQL,它是基于С++的,但它与МТ平台相联系,所以你需要研究帮助。

你的代码中已经有了文件处理和与全局变量 和图形的工作 ...每次打勾都有很多不必要的操作

如果你想快速执行,请使用OnChartEvent(),它不会在测试器中生成,但首先开始研究MQL4的帮助。

 
Igor Makanu:

操作时间不长,是一个一个的嘀......但总的来说,开始阅读帮助,你不能靠 "直觉 "来学习MQL,MQL是基于C++的,但它与MT平台绑定,你不看帮助是不行的。

你的代码中已经有了文件处理和与全局变量 和图形的工作 ...每次打勾都有很多不必要的操作

如果你想快速执行,请使用OnChartEvent(),它不会在测试器中生成,但首先开始研究MQL4的帮助。

我可能要请技师来让它清醒过来。我将不能够。这个指标在处理无限数量的开放图表时非常方便。这些按钮显示符号的当前利润和买入和卖出订单的数量。
 

大家好。

在代码库中发现了一个有用的Ind-Fractals指标。然而,它在每个条形上都画出分形,而不是正确地计算它们。我想使用这个指标,但它 "坏了"((帮助我找到一个错误,我曾试图联系作者,但他不回复信息。为方便起见,这里重复了代码。

#property copyright "Copyright © 2005, MetaQuotes Software Corp.

#属性链接 "http://www.metaquotes.net"

//----

#property indicator_chart_window

#property indicator_buffers 8

#property indicator_color1 Red

#property indicator_color2 Red

#property indicator_color3 Blue

#property indicator_color4 Blue

#property indicator_color5 Lime

#property indicator_color6 Lime

#property indicator_color7 Sienna

#property indicator_color8 Sienna

//---- 输入参数

外部bool Comm=true。

//---- 缓冲区

双倍ExtMapBuffer1[]。

双倍ExtMapBuffer2[]。

双倍ExtMapBuffer3[]。

双倍ExtMapBuffer4[]。

双倍ExtMapBuffer5[]。

双倍ExtMapBuffer6[]。

双倍ExtMapBuffer7[]。

双倍ExtMapBuffer8[]。

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

//|自定义指标初始化功能

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

int init()

{

//---- 指标

SetIndexStyle(0,DRAW_ARROW);//指标线样式

SetIndexArrow(0,217); //规定了箭头类型

SetIndexBuffer(0,ExtMapBuffer1);//将指标缓冲区 与一维动态数组的双倍类型绑定。该功能有2个版本。

SetIndexEmptyValue(0,0.0);//设置指标线的空值。

SetIndexStyle(1,DRAW_ARROW)。

SetIndexArrow(1,218);

SetIndexBuffer(1,ExtMapBuffer2)。

SetIndexEmptyValue(1,0.0)。

SetIndexStyle(2,DRAW_ARROW)。

SetIndexArrow(2,217);

SetIndexBuffer(2,ExtMapBuffer3)。

SetIndexEmptyValue(2,0.0)。

SetIndexStyle(3,DRAW_ARROW)。

SetIndexArrow(3,218)。

SetIndexBuffer(3,ExtMapBuffer4)。

SetIndexEmptyValue(3,0.0)。

SetIndexStyle(4,DRAW_ARROW)。

SetIndexArrow(4,217);

SetIndexBuffer(4,ExtMapBuffer5)。

SetIndexEmptyValue(4,0.0)。

SetIndexStyle(5,DRAW_ARROW)。

SetIndexArrow(5,218)。

SetIndexBuffer(5,ExtMapBuffer6)。

SetIndexEmptyValue(5,0.0)。

SetIndexStyle(6,DRAW_ARROW)。

SetIndexArrow(6,217);

SetIndexBuffer(6,ExtMapBuffer7)。

SetIndexEmptyValue(6,0.0)。

SetIndexStyle(7,DRAW_ARROW)。

SetIndexArrow(7,218)。

SetIndexBuffer(7,ExtMapBuffer8)。

SetIndexEmptyValue(7,0.0)。

return(0); }

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

//|Custor指示器去初始化功能|

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

int deinit() {return(0); }

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

bool Fractal(string F,int Per,int shift) {

如果(Period()>Per)返回(-1)。

Per=Per/Period()*2+MathCeil(Per/Period()/2)。

如果(shift<Per)返回(-1)。

如果(shift>Bars-Per)返回(-1)。

for(int i=1;i<=Per;i++) {

如果(shift+i>=Bars || shift-i<0) 返回(-1)。

如果(F=="U") {

如果(High[shift+i]>High[shift])返回(-1)。

如果(High[shift-i]>=High[shift])返回(-1); }

如果(F=="L") {

如果(Low[shift+i]<Low[shift])返回(-1)。

如果(Low[shift-i]<=Low[shift])返回(-1); } }

return(1); }

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

int start()

{

int D1=1440,H4=240,H1=60,M15=15,B;

双P。

int counted_bars=IndicatorCounted();//最后一次调用指标后未改变的条数。

B=Bars-counted_bars。

如果(counted_bars==0) B--;

if(Period()==D1)P=150*Point;// period返回当前图表周期。

如果(Period()==H4)P=70*Point。

如果(Period()==H1)P=40*Point。

if(Period()==30)P=30*Point;

如果(Period()==M15)P=20*Point。

如果(Period()==5)P=10*Point;

如果(Period()==1)P=5*Point;

for(int shift=B;shift>0;shift--)

{

如果(Fractal("U",M15,shift)==1) ExtMapBuffer1[shift]=High[shift]+P;

否则ExtMapBuffer1[shift]=0。

if(Fractal("L",M15,shift)==1) ExtMapBuffer2[shift]=Low[shift]-P。

否则ExtMapBuffer2[shift]=0。

if(Fractal("U",H1,shift)==1) ExtMapBuffer3[shift]=High[shift]+P;

否则ExtMapBuffer3[shift]=0。

if(Fractal("L",H1,shift)==1) ExtMapBuffer4[shift]=Low[shift]-P。

否则ExtMapBuffer4[shift]=0。

if(Fractal("U",H4,shift)==1) ExtMapBuffer5[shift]=High[shift]+P;

否则ExtMapBuffer5[shift]=0。

if(Fractal("L",H4,shift)==1) ExtMapBuffer6[shift]=Low[shift]-P。

否则ExtMapBuffer6[shift]=0。

如果(Fractal("U",D1,shift)==1) ExtMapBuffer7[shift]=High[shift]+P;

否则ExtMapBuffer7[shift]=0。

if(Fractal("L",D1,shift)==1) ExtMapBuffer8[shift]=Low[shift]-P;

否则ExtMapBuffer8[shift]=0。

}

if(Comm) Comment("D1 - brown\n H4 - green\n H1 - blue\nM15 - red")。


return(0);

}

MetaQuotes Software Corp.
MetaQuotes Software Corp.
  • www.metaquotes.net
Миллионы трейдеров и сотни брокеров не могут ошибаться — они выбрали MetaTrader 5 для торговли на Форексе и финансовых рынках! Узнать больше
 

我在这里因为这种代码被骂过,这是我第一次有这种情况 :-)

该代码应插入 一个用Alt+S打开的表格中。

 
psyman:

我在这里因为这种代码被骂过,这是我第一次有这种情况 :-)

你必须把代码粘贴 到一个按Alt+S打开的表格中。

你会被责骂吗?没有任何方式。你想怎么写代码就怎么写。但是......如果你想得到问题的答案,请试着尊重那些你正在寻求帮助的人。就这么简单。

 

关于交易、自动交易系统和策略测试的论坛

对MQL4新手的任何问题,对算法和代码的帮助和讨论

Artyom Trishkin, 2018.10.18 08:07

这么说吧:在编辑器中创建一个指标模板,在创建时添加适当数量的输入变量和绘图缓冲区。

接下来,让我们从具体的任务中分析一下该怎么做。

我上次就是这么做的,只是改变了变量和数组的名称。

当使用iMA时,它只在周和日,即蜡烛包含100点以上的情况下起作用,它在较低的时间框架上没有任何作用。原因似乎是四舍五入。




如果使用iMAOnArray,所有TFs的i-ras窗口都是空的。日志中没有任何错误。




//+------------------------------------------------------------------+
//|                                                        _null.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot OC
#property indicator_label1  "O-C"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrSteelBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         ip1Buf[];

input int ip1=100;
double tmp1[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
  
IndicatorBuffers(2);
string s_name1;

s_name1="O-C (" + IntegerToString(ip1) + ")";

IndicatorShortName(s_name1);
SetIndexLabel(0, s_name1);
SetIndexBuffer(1, tmp1);


//--- indicator buffers mapping
   SetIndexBuffer(0,ip1Buf);
   
//---
   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[])
  {


int i;

      Print("rates_total = ",rates_total);
      for(i=1; i<rates_total-1; i++)
      {
      //Print("i = ",i);
      tmp1[i]=MathMax(open[i],close[i])-MathMin(open[i],close[i]);      
     // tmp1[i]=close[i];      
      //ip1Buf[i]=iMA(NULL,0,1,0,0,tmp1[i],0);
      ip1Buf[i]=iMAOnArray(tmp1,1,1,0,0,0);
      
      }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


 
psyman:

如果使用iMAOnArray,所有TF上的i-ra窗口都是空的。日志中没有任何错误。

你在使用iMAOnArray()时周期为1,即iMAOnArray()的值基本上是数组tmp1的值。

如果你想弄清楚你在计算什么,就把循环缩短for(i=1; i<10; i++)

并解印所有你想计算的数据,虽然不计算一些复杂的公式可能更容易,但使用iMAOnArray()建立iMA和iMAOnArray()--iMA和iMAOnArray()都是相同的计算....唉,如果你能在这个论坛上得到一个技术问题的答案,你就应该学会计算和处理这些信息。

 
psyman:

上次我这样做,只是改变了变量和数组的名称。

当使用iMA i-r时,只在周和日工作,在蜡烛中超过100点,它不在较低的TF上画任何东西。其原因似乎是四舍五入。




如果使用iMAOnArray,所有TFs的i-ras窗口都是空的。日志中没有任何错误。





第一个周期计算第一个缓冲区的数值。

第二周期通过第一周期计算的数值来计算MA。

考虑一下iMAOnArray()是什么意思。在阵列上写下MA。你如何翻译它?每个人的指尖上都有一个谷歌翻译器。放-译-收。阵列上的MA。

这意味着它是一个基于初步计算和填充阵列的移动平均线。

相应地:第一周期--准备必要的阵列,第二周期--根据第一周期准备的阵列构建移动平均线。

那你是怎么做的?你在第一个数组中输入一个值(其他值还没有准备好),并尝试在这个值上建立MA。

我给了你一个模板。

关于交易、自动交易系统和策略测试的论坛

任何关于MQL4初学者的问题,帮助和讨论算法和代码

Artyom Trishkin, 2018.10.18 09:39

指标。

//+------------------------------------------------------------------+
//|                                                       TestMA.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                             https://mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://mql5.com/ru/users/artmedia70"
#property version   "1.00"
#property indicator_chart_window
#ifdef __MQL4__
#property strict
#property indicator_buffers 2
#else 
#property indicator_buffers 3
#property indicator_plots   2
#endif 
//--- plot MAstd
#property indicator_label1  "Calculation MA"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  4
//--- plot MAcalc
#property indicator_label2  "Standart MA"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrDarkOrange
#property indicator_style2  STYLE_DOT
#property indicator_width2  2
//--- input parameters
input int      InpPeriod                     =  10;            // Period
input ENUM_MA_METHOD       InpMethod         =  MODE_EMA;      // Method
input ENUM_APPLIED_PRICE   InpAppliedPrice   =  PRICE_CLOSE;   // Applied price  
//--- indicator buffers
double         BufferMAcalc[];
double         BufferMAstd[];
double         BufferPrice[];
//---
int            digits;
int            period_ma;
int            handle_ma;
CAvg           avg();
//--- includes

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
#ifdef __MQL4__
   IndicatorBuffers(3);
#endif 
    period_ma=(InpPeriod<1? 1 : InpPeriod);
   digits=Digits()+1;
//--- indicator buffers mapping
   SetIndexBuffer(0,BufferMAcalc,INDICATOR_DATA);
   SetIndexBuffer(1,BufferMAstd,INDICATOR_DATA);
   SetIndexBuffer(2,BufferPrice,INDICATOR_CALCULATIONS);
//---
   ArraySetAsSeries(BufferMAcalc,true);
   ArraySetAsSeries(BufferMAstd,true);
   ArraySetAsSeries(BufferPrice,true);
//---
#ifdef __MQL5__
   ResetLastError();
   handle_ma=iMA(NULL,PERIOD_CURRENT,period_ma,0,InpMethod,InpAppliedPrice);
   if(handle_ma==INVALID_HANDLE)
     {
      Print("Error creation iMA(",(string)period_ma,"): ",GetLastError());
      return INIT_FAILED;
     }
#endif 
//---
   Comment("\nMA type: ",avg.MethodToString(InpMethod),", price: ",avg.PriceToString(InpAppliedPrice),", period: ",(string)period_ma);
//---
   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[])
  {
//--- Установка массивов буферов как таймсерий
#ifdef __MQL5__
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);
#endif 
//--- Проверка количества доступных баров
   if(rates_total<fmax(period_ma,4)) return 0;
//--- Проверка и расчёт количества просчитываемых баров
   int limit=rates_total-prev_calculated;
   if(limit>1)
     {
      limit=rates_total-1;
      ArrayInitialize(BufferMAcalc,EMPTY_VALUE);
      ArrayInitialize(BufferMAstd,EMPTY_VALUE);
      ArrayInitialize(BufferPrice,0);
     }
//--- Подготовка данных
#ifdef __MQL5__
   int count=(limit>1 ? rates_total : 1),copied=0;
   copied=CopyBuffer(handle_ma,0,0,count,BufferMAstd);
   if(copied!=count) return 0;
#endif 
//--- Расчёт индикатора
   for(int i=limit; i>=0 && !IsStopped(); i--)
     {
      #ifdef __MQL4__ BufferMAstd[i]=iMA(NULL,PERIOD_CURRENT,period_ma,0,InpMethod,InpAppliedPrice,i); #endif 
       BufferPrice[i]=avg.AppliedPrice(InpAppliedPrice,NULL,PERIOD_CURRENT,i);
      BufferMAcalc[i]=avg.GetMA(rates_total,InpMethod,period_ma,i,BufferPrice);
     }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

你可以扔掉与五有关的一切,得到一个四的模板。虽然这个模板是多平台的--你可以把它用于两个终端--只需设置你的缓冲区和它们的数量。在这个模板中,有两张图和一个计算,可以在这里看到。

//--- indicator buffers mapping
   SetIndexBuffer(0,BufferMAcalc,INDICATOR_DATA);
   SetIndexBuffer(1,BufferMAstd,INDICATOR_DATA);
   SetIndexBuffer(2,BufferPrice,INDICATOR_CALCULATIONS);
//---
 

=另外,你使用iMAOnArray()的周期为1,即iMAOnArray()的值基本上是数组tmp1的值


我已经尝试了不同的值来使用,1仍然是这些实验的最后一个变量。

由于某些原因,ip1Buf[4]=2147483647.0在所有TF上的i-r缓冲区写的是同一个数字,例如,而数组的值都是不同的tmp1[4]=0.1300000000000097,等等。

但即使如此,也应该画出一条直线,而在i-r图表上绝对没有,刻度是从0到0的标记。



 
psyman:

=另外,你使用iMAOnArray()的周期为1,即iMAOnArray()的值基本上是数组tmp1的值


我已经尝试了不同的值来使用,1仍然是这些实验的最后一个变量。

由于某些原因,所有TF上的i-ras缓冲区都被写入相同的数字,例如ip1Buf[4] = 2147483647.0,尽管数组的值都是不同的tmp1[4] = 0.1300000000000097,等等。

但即使在这种情况下,也应该画出一条直线,而在i-r图表上绝对没有,刻度是从0到0的标记。



2147483647.0 好开始使用搜索引擎!https://www.mql5.com/ru/forum/224831

再一次,我刚刚写了Artem,你需要自己阅读,从一个简单的开始......在图表上用指标画出收盘价,然后试着让它变得更复杂,在一个周期内做同样的事情,在第二个周期内根据已经计算出的收盘价的缓冲区做МА计算。

2147483647 в буфере
2147483647 в буфере
  • 2018.01.15
  • www.mql5.com
День Добрый! Подскажите, пожалуйста, что это за хрень. Не первый раз сталкиваюсь...
原因: