初学者的问题 MQL5 MT5 MetaTrader 5 - 页 162

 

我在mql4中写了一个最简单的指标,我想把它翻译成mql5,我已经挣扎了一个星期了,但它没有工作!我想把它翻译成mql5。我越来越紧张了,我讨厌mql5,因为我已经在mql5中写了88行简单的34行指标了!我不知道该怎么办。

这里是mql4上的代码。

#property indicator_separate_window
#property  indicator_level1 0
#property indicator_buffers 3

extern int kol_vo_bar = 15;
extern string Symbol_1 = "GBPJPY";
extern string Symbol_2 = "EURJPY";

double SpreadA[];
double SpreadB[];
double Spread[];

int init()
{
   SetIndexBuffer(0,SpreadA);
   SetIndexBuffer(1,SpreadB);
   SetIndexBuffer(2,Spread);
   SetIndexStyle(0,DRAW_SECTION,EMPTY,2,Red);
   SetIndexStyle(1,DRAW_SECTION,EMPTY,2,Blue);
   SetIndexStyle(2,DRAW_HISTOGRAM,EMPTY,1,Gray);
   return(0);
}

int start()
{
   int k;
   for(k = 0; k < iBars(Symbol_1,0); k++)
   {
            SpreadA[k] = iClose(Symbol_1,0,k)*100/iOpen(Symbol_1,0,k+kol_vo_bar)-100;
            SpreadB[k] = iClose(Symbol_2,0,k)*100/iOpen(Symbol_2,0,k+kol_vo_bar)-100;                  
            Spread[k] = SpreadA[k]-SpreadB[k];
   }
   return(0);
}

而这里是mql5上的代码。

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   3
//--- plot Label1
#property  indicator_label1  "Label1"
#property  indicator_type1   DRAW_SECTION
#property  indicator_color1  clrRed
#property  indicator_style1  STYLE_SOLID
#property  indicator_width1  2
//--- plot Label2
#property  indicator_label2  "Label2"
#property  indicator_type2   DRAW_SECTION
#property  indicator_color2  clrBlue
#property  indicator_style2  STYLE_SOLID
#property  indicator_width2  2

#property  indicator_label3  "Label3"
#property  indicator_type3   DRAW_HISTOGRAM
#property  indicator_color3  clrGray
#property  indicator_style3  STYLE_SOLID
#property  indicator_width3  1

//--- input parameters
input int kol_vo_bar=96;
input string   Symbol_1="GBPJPY";
input string   Symbol_2="EURJPY";
//--- indicator buffers
double         Label1Buffer[];
double         Label2Buffer[];
double         Label3Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
   SetIndexBuffer(1,Label2Buffer,INDICATOR_DATA);
   SetIndexBuffer(2,Label3Buffer,INDICATOR_DATA);
   
//---
   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[])
  {
//---
   for(int k=0; k<Bars(_Symbol,_Period); k++)
   {
            Label1Buffer[k] = iClose(Symbol_1,PERIOD_CURRENT,k)*100/iOpen(Symbol_1,PERIOD_CURRENT,k)-100;
            Label2Buffer[k] = iClose(Symbol_2,PERIOD_CURRENT,k)*100/iOpen(Symbol_2,PERIOD_CURRENT,k)-100;                  
            Label3Buffer[k] = Label1Buffer[k]-Label2Buffer[k];
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
double iClose(string symbol,ENUM_TIMEFRAMES tf,int index)
{
   if(index < 0) return(-1);
   double Arr[];
   if(CopyClose(symbol,tf,index,1,Arr)>0)
        return(Arr[0]);
   else return(-1);
}
double iOpen(string symbol,ENUM_TIMEFRAMES tf,int index)
{
   if(index < 0) return(-1);
   double Arr[];
   if(CopyOpen(symbol,tf,index+kol_vo_bar,1,Arr)>0)
        return(Arr[0]);
   else return(-1);
}

指标线 在MT5中不能正确显示。

我做错了什么?

好心人,帮帮我,可怜可怜我吧,我都快崩溃了,真的。真可惜,你不能在这里骂人!

版主,不要封杀我,如果有什么不对,先给我一个警告。

 

你在每个刻度 上重新计算所有可用的条形图,这是非常次优的,而且速度非常慢。

 
zlodei:


指标线 在MT5中不能正确显示。

我写错了什么?

PlotIndexXXX的工作在哪里?

不允许你阅读文件和例子?



版主,不要封杀我,如果有什么不对,先给我一个警告。

去代码库看看吧,那里有数百个例子。
 
sergeev:

哪里有PlotIndexXXX的工作?

懒得阅读文档和例子?


去codebase看一下。有数百个例子。

我想知道为什么在代码的开头需要这样做。

#property  indicator_label1  "Label1"
#property  indicator_type1   DRAW_SECTION
#property  indicator_color1  clrRed
#property  indicator_style1  STYLE_SOLID
#property  indicator_width1  2

#property  indicator_label2  "Label2"
#property  indicator_type2   DRAW_SECTION
#property  indicator_color2  clrBlue
#property  indicator_style2  STYLE_SOLID
#property  indicator_width2  2

#property  indicator_label3  "Label3"
#property  indicator_type3   DRAW_HISTOGRAM
#property  indicator_color3  clrGray
#property  indicator_style3  STYLE_SOLID
#property  indicator_width3  1

每一行的所有属性都在这里指定?还是说对于mql5来说这还不够,现在我需要通过PlotIndex来写线的属性?

我读了很多例子和文档,我不明白其中的80%,例如,为什么要把简单的事情复杂化?

例如,在mql4:

   SetIndexStyle(0,DRAW_SECTION,EMPTY,2,Red);
   SetIndexStyle(1,DRAW_SECTION,EMPTY,2,Blue);
   SetIndexStyle(2,DRAW_HISTOGRAM,EMPTY,1,Gray);

在mql5中,我甚至无法想象指定行的样式会花费多少时间,可能有50行,而结果是1,而且是相同的。

MQL5是为程序员设计的,MQL4是为交易员设计的。如果你想检查系统,就用mql4编程,如果你想用mt5做同样的事情,就请程序员来做,或者停止交易,花时间研究mql5。

随着MT5的发布,我作为一个交易员,只注意到一个改进,它是一个64位的测试器,能够使用所有的CPU核心。

mql语言的复杂程度不会以任何方式影响人工或自动交易的结果。语言的复杂性对程序员来说很重要,是的--我们可以制作漂亮的按钮和面板,与各种奇怪的WinAPI集成,等等,但这并没有影响交易的结果。那么,为什么会有这些困难呢?你可以用mql4编程,并对其进行检查,但只有一个很大的缺点--没有x64终端和可以使用所有内核的测试器。如果他们能做到这两点,那么MT4就不会有价格了。但他们不会故意制造这些东西,这样就不会给MT5带来竞争,像我这样的人就会受到影响或付出金钱。

总之感谢你的关注,感谢你的 "帮助"。我不发表意见,反正我不会去支教,这只是我的看法,不多,我得去。

 
我是新来的。你能告诉我,如果我在mt5中交易rts指数期货?我怎样才能显示一个从2009年到今天的单一报价图表?
 
sbr080:
我是新来的。你能告诉我,如果我在mt5中交易rts指数期货?如何打印从2009年到今天的报价表?
你必须要求你的经纪人给你粘 的图表。
 
barabashkakvn:
要求你的经纪人给你一张胶水 图表。
我可以自己黏贴吗?
 
sbr080:
我可以自己把它粘起来吗?
不,只是一个经纪人。如果你自己做,你将不得不写你自己的指标。
 
barabashkakvn:
不,只是一个经纪人。如果你自己做,你就必须写你自己的指标。
谢谢你。
 
您能否告知,专家顾问是否有可能在图表上显示其使用的参数的技术指标?也就是说,与在策略测试器中使用可视化时的方式相同。我无法在任何地方找到这一信息。
Документация по MQL5: Технические индикаторы
Документация по MQL5: Технические индикаторы
  • www.mql5.com
Технические индикаторы - Документация по MQL5