自定义指标不是画线,而是在专家选项卡中打印出数据

omega13lives
14
omega13lives  

我知道这对于其他人来说确实很简单或显而易见,但是我对MQL5还是很陌生,并且在转换MT4指标方面仅取得部分成功(我敢肯定,我的EA将是一场噩梦)。 数据显示我何时使用 打印功能 但没有显示任何行。 在数据窗口中也没有任何显示,这可能是一个提示。 当我看到缺少PLOT_DRAW_TYPE,DRAW_LINE时我以为自己拥有了,但是没有。 我已经阅读了许多帮助文章,但似乎找不到答案。 如果有人可以帮助,谢谢! 这是试图使分形显示线条而不是箭头的代码(带有一些额外的垃圾):

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 2
#property indicator_color1 clrPaleGreen
#property indicator_color2 clrTomato

input int numberOfBars=1000;
//---- buffers
double v1[];
double v2[];
double val1;
double val2;
int i;
bool firstTime;
//--- Auxiliary arrays 
   double Ups[],Downs[]; 
   datetime Time[]; 
//+------------------------------------------------------------------+
void OnInit()
  {
   firstTime=true;
  //IndicatorBuffers(2);
 
//---- drawing settings
//--- Set the arrays as timeseries 
   ArrayResize(Ups,numberOfBars,0);
   ArraySetAsSeries(Ups,true); 
   ArrayResize(Downs,numberOfBars,0);
   ArraySetAsSeries(Downs,true); 
   ArrayResize(Time,numberOfBars,0);
   ArraySetAsSeries(Time,true); 
   
   IndicatorSetString(INDICATOR_SHORTNAME,"iFractalLines");
  
   SetIndexBuffer(0,v1,INDICATOR_DATA);
   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);
   PlotIndexSetInteger(0,PLOT_LINE_STYLE,STYLE_DASH);
   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,1);
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,indicator_color1);
   //PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,998);//i-1);
   PlotIndexSetString(0,PLOT_LABEL,"Resistance");
    

   SetIndexBuffer(1,v2,INDICATOR_DATA);
   PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_LINE);
   PlotIndexSetInteger(1,PLOT_LINE_STYLE,STYLE_DASH);
   PlotIndexSetInteger(1,PLOT_LINE_WIDTH,1);
   PlotIndexSetInteger(1,PLOT_LINE_COLOR,indicator_color2);
   //PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,998);//i-1);
   PlotIndexSetString(1,PLOT_LABEL,"Support");
 
   return;
  }

//+------------------------------------------------------------------+
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[])
  {

//--- Create handle of the Indicator Fractals 
   int FractalsHandle=iFractals(NULL,0); 
   //Print("FractalsHandle = ",FractalsHandle); 
//--- Set Last error value to Zero 
   ResetLastError(); 
//--- Try to copy the values of the indicator 
   //Sleep(1000);
   //if(!firstTime)
   {
   int copied=CopyBuffer(FractalsHandle,0,0,1000,Ups); 
   if(copied<=0) 
     { 
      Print("Unable to copy the upper fractals. Error = ",GetLastError()); 
      return(0); 
     } 
  
   ResetLastError(); 
//--- Try to copy the values of the indicator 
   copied=CopyBuffer(FractalsHandle,1,0,1000,Downs); 
   if(copied<=0) 
     { 
      Print("Unable to copy the bottom fractals. Error = ",GetLastError()); 
      return(0); 
     } 
  
   ResetLastError(); 
//--- Copy timeseries containing the opening bars of the last 1000 ones 
   copied=CopyTime(NULL,0,0,1000,Time); 
   if(copied<=0) 
     { 
      Print("Unable to copy the Opening Time of the last 1000 bars"); 
      return(0); 
     } 
  
   //int upcounter=0,downcounter=0; // count there the number of arrows 
   //bool created;// receive the result of attempts to create an object 
   //i=1000;
   ArrayResize(v1,numberOfBars,0);
   ArrayResize(v2,numberOfBars,0);
   //Print("ArraySize(v1)=",ArraySize(v1));
   v1[numberOfBars-1]=0;
   v2[numberOfBars-1]=0;
   for(i=numberOfBars-2 ;i>=0;i--)// Run through the values of the indicator iFractals 
     { 
      if(Ups[i]!=EMPTY_VALUE)// Found the upper fractal 
        { 
         v1[i]=iHigh(NULL,PERIOD_CURRENT,i);
         //Print("v1[",i,"]=",v1[i]);
        } 
      else
        {
        v1[i] = v1[i+1];
         //Print("v1[",i,"]=",v1[i]);
         }

      if(Downs[i]!=EMPTY_VALUE)// Found a lower fractal 
        { 
         v2[i]=iLow(NULL,PERIOD_CURRENT,i);
        } 
      else
         v2[i] = v2[i+1];
     } 
   }
   return(0);
  }
弗拉基米尔·卡普托夫(Vladimir Karputov)
主持人
238792
弗拉基米尔·卡普托夫(Vladimir Karputov)  
omega13lives :

我知道这对于其他人来说确实很简单或显而易见,但是我对MQL5还是很陌生,并且在转换MT4指标方面仅取得部分成功(我敢肯定,我的EA将是一场噩梦)。 数据显示我何时使用 打印功能 但没有显示任何行。 在数据窗口中也没有任何显示,这可能是一个提示。 当我看到缺少PLOT_DRAW_TYPE,DRAW_LINE时我以为自己拥有了,但是没有。 我已经阅读了许多帮助文章,但似乎找不到答案。 如果有人可以帮助,谢谢! 这是试图使分形显示线条而不是箭头的代码(带有一些额外的垃圾):

纠正主要错误:您在每笔交易中创建一个指标句柄!

记住,请阅读帮助,请参见示例:在MQL5中,必须一次创建指示器句柄,而这必须在OnInit中完成!!!

omega13lives
14
omega13lives  
弗拉基米尔·卡普托夫(Vladimir Karputov):

纠正主要错误:您在每笔交易中创建一个指标句柄!

记住,请阅读帮助,请参见示例:在MQL5中,必须一次创建指示器句柄,而这必须在OnInit中完成!!!

谢谢,我会尝试的。 我不太擅长MQL5,所以我从文档中完全复制了代码,如果您不是MQL5的专家,通常会很困惑并且很难理解。 我不明白为什么,但是我将其移至OnInit。 我重新编译了代码,但仍然看不到 指标缓冲区.
弗拉基米尔·卡普托夫(Vladimir Karputov)
主持人
238792
弗拉基米尔·卡普托夫(Vladimir Karputov)  
omega13lives :
谢谢,我会尝试的。 我不太擅长MQL5,所以我从文档中完全复制了代码,如果您不是MQL5的专家,通常会很困惑并且很难理解。 我不明白为什么,但是我将其移至OnInit。 我重新编译了代码,但仍然看不到 指标缓冲区 .

MQL5代码在哪里?没有代码,没有帮助。

omega13lives
14
omega13lives  
弗拉基米尔·卡普托夫(Vladimir Karputov):

MQL5代码在哪里?没有代码,没有帮助。

我所做的就是移动代码,但是在这里是:

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 2
#property indicator_color1 clrPaleGreen
#property indicator_color2 clrTomato

input int numberOfBars=1000;
//---- buffers
double v1[];
double v2[];
double val1;
double val2;
int i;
bool firstTime;
//--- Auxiliary arrays 
   double Ups[],Downs[]; 
   datetime Time[]; 
int FractalsHandle;
//+------------------------------------------------------------------+
void OnInit()
  {
   firstTime=true;
//--- Create handle of the Indicator Fractals 
   FractalsHandle=iFractals(NULL,0); 
   //Print("FractalsHandle = ",FractalsHandle); 

  //IndicatorBuffers(2);
 
//---- drawing settings
//--- Set the arrays as timeseries 
   ArrayResize(Ups,numberOfBars,0);
   ArraySetAsSeries(Ups,true); 
   ArrayResize(Downs,numberOfBars,0);
   ArraySetAsSeries(Downs,true); 
   ArrayResize(Time,numberOfBars,0);
   ArraySetAsSeries(Time,true); 
   
   IndicatorSetString(INDICATOR_SHORTNAME,"iFractalLines");
  
   SetIndexBuffer(0,v1,INDICATOR_DATA);
   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);
   PlotIndexSetInteger(0,PLOT_LINE_STYLE,STYLE_DASH);
   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,1);
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,indicator_color1);
   //PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,998);//i-1);
   PlotIndexSetString(0,PLOT_LABEL,"Resistance");
    

   SetIndexBuffer(1,v2,INDICATOR_DATA);
   PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_LINE);
   PlotIndexSetInteger(1,PLOT_LINE_STYLE,STYLE_DASH);
   PlotIndexSetInteger(1,PLOT_LINE_WIDTH,1);
   PlotIndexSetInteger(1,PLOT_LINE_COLOR,indicator_color2);
   //PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,998);//i-1);
   PlotIndexSetString(1,PLOT_LABEL,"Support");
 
   return;
  }

//+------------------------------------------------------------------+
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[])
  {

//--- Set Last error value to Zero 
   ResetLastError(); 
//--- Try to copy the values of the indicator 
   //Sleep(1000);
   //if(!firstTime)
   {
   int copied=CopyBuffer(FractalsHandle,0,0,1000,Ups); 
   if(copied<=0) 
     { 
      Print("Unable to copy the upper fractals. Error = ",GetLastError()); 
      return(0); 
     } 
  
   ResetLastError(); 
//--- Try to copy the values of the indicator 
   copied=CopyBuffer(FractalsHandle,1,0,1000,Downs); 
   if(copied<=0) 
     { 
      Print("Unable to copy the bottom fractals. Error = ",GetLastError()); 
      return(0); 
     } 
  
   ResetLastError(); 
//--- Copy timeseries containing the opening bars of the last 1000 ones 
   copied=CopyTime(NULL,0,0,1000,Time); 
   if(copied<=0) 
     { 
      Print("Unable to copy the Opening Time of the last 1000 bars"); 
      return(0); 
     } 
  
   //int upcounter=0,downcounter=0; // count there the number of arrows 
   //bool created;// receive the result of attempts to create an object 
   //i=1000;
   ArrayResize(v1,numberOfBars,0);
   ArrayResize(v2,numberOfBars,0);
   //Print("ArraySize(v1)=",ArraySize(v1));
   v1[numberOfBars-1]=0;
   v2[numberOfBars-1]=0;
   for(i=numberOfBars-2 ;i>=0;i--)// Run through the values of the indicator iFractals 
     { 
      if(Ups[i]!=EMPTY_VALUE)// Found the upper fractal 
        { 
         v1[i]=iHigh(NULL,PERIOD_CURRENT,i);
         //Print("v1[",i,"]=",v1[i]);
        } 
      else
        {
        v1[i] = v1[i+1];
         //Print("v1[",i,"]=",v1[i]);
         }

      if(Downs[i]!=EMPTY_VALUE)// Found a lower fractal 
        { 
         v2[i]=iLow(NULL,PERIOD_CURRENT,i);
        } 
      else
         v2[i] = v2[i+1];
     } 
   }
   return(0);
  }
弗拉基米尔·卡普托夫(Vladimir Karputov)
主持人
238792
弗拉基米尔·卡普托夫(Vladimir Karputov)  
omega13lives :

我所做的就是移动代码,但是在这里是:

为什么使用“ CopyTime”,“ iHigh”和“ iLow” ???该指标已提供所有阵列:

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[])
  {

纠正你的错误。

弗拉基米尔·卡普托夫(Vladimir Karputov)
主持人
238792
弗拉基米尔·卡普托夫(Vladimir Karputov)  

指标名称所在的行在哪里? (这些行放在最开始的位置)。

参见示例:

//+------------------------------------------------------------------+
//|                                                  Accelerator.mq5 |
//|                   Copyright 2009-2020, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright   "2009-2020, MetaQuotes Software Corp."
#property link        "http://www.tbxfkj.com"
#property description "Accelerator/Decelerator"

//--- indicator settings

纠正你的错误。