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

 
Carcass77:

我的指标有效,我只是 扩大。

好吧,我自己去拿。

如果这是你的指标,这个问题看起来,说句不好听的,令人震惊......

 
Сергей Таболин:

如果这是你的指标,这个问题看起来,说句不好听的,令人震惊......

它正在发挥作用。该问题是关于字符串变量声明的 "形式"。我还在学习,如果有的话,各位程序员。

 
Carcass77:

它起作用了。该问题是关于字符串变量声明的 "形式"。我还在学习,如果有的话,各位程序员。

每个人都在学习,这很正常。

我的问题是因为你的例子不是初学者的水平,而关于变量类型和范围的问题是你第一次尝试写代码时必须了解的第一件事--不了解这一点,你将来就不会有任何收获。

 
Carcass77:

它起作用了。该问题是关于字符串变量声明的 "形式"。我还在学习,如果有的话,各位程序员。

我也还在学习))))而且希望我还能学到很多东西;)

 

大家好!如何向按钮传递,名称+值(例如按钮Lots = 0.1)?

预先感谢 !

 
你好!我想用下分形画一条趋势线,但不成功。以时间的起点为第一点,画一条线,就这样。它没有进入下一个分形。 我做错了什么,如何才能解决?
datetime firsttime1;
datetime firsttime2;
datetime secondtime1;
datetime secondtime2;
double  firstprice1;
double  firstprice2;
double  secondprice1;
double  secondprice2;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  if(Hour()>=9 && Hour()<22)
   {
    Fun_New_Bar();
    if(New_Bar)      
     {

double vallo=iFractals(NULL,0,MODE_LOWER,2);Alert("vallo = ",vallo);
      {if(vallo>0)
       {
       //забиваем координаты второй точки для линии Low
       secondtime1=(TimeCurrent()-7200);
       secondprice1=iLow(NULL,0,2);
       
       //рисуем трендовую линию Low
       ObjectCreate("LowLine",OBJ_TREND,0,firsttime1,firstprice1,secondtime1,secondprice1);

      firsttime1=secondtime1;
      firstprice1=secondprice1;
   
       }
      }
     }
   }
  } 
 

为从kodobase下载的SuperTrend 指标添加箭头。它在启动时正常地绘制箭头。


但如果我在图表上向后/向左滚动,就会出现胡言乱语,一切都崩溃了。


以下是代码。

//+------------------------------------------------------------------+
//|                                                   SuperTrend.mq4 |
//|                   Copyright © 2008, Jason Robinson (jnrtrading). |
//|                                   http://www.spreadtrade2win.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Jason Robinson."
#property link      "http://www.spreadtrade2win.com"
#property strict
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 clrLime
#property indicator_color2 clrRed
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 3
#property indicator_width4 3

enum en_trend {
   Modern,   // Modern
   Classic,  // Classic
};

//+------------------------------------------------------------------+
//| Universal Constants                                              |
//+------------------------------------------------------------------+
#define  PHASE_NONE 0
#define  PHASE_BUY  1
#define  PHASE_SELL -1

//+------------------------------------------------------------------+
//| User input variables                                             |
//+------------------------------------------------------------------+
input en_trend TrendMode      = Modern;   // Trend Line Mode
input int      ATR_Period     = 10;       // ATR Period
input double   ATR_Multiplier = 3.0;      // ATR Multiplier
input int      BarsToCount    = 0;        // Bars to count (0 - all bars)
input color    clr_Up         = clrLime;  // Arrow Up Color
input color    clr_Dn         = clrRed;   // Arrow Down Color

//+------------------------------------------------------------------+
//| Universal variables                                              |
//+------------------------------------------------------------------+
double buffer_line_up[];
double buffer_line_down[];
double ArrowUpBuffer[];
double ArrowDnBuffer[];

double atr,
       band_upper,
       band_lower,
       shift;
int    phase=PHASE_NONE;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  
   IndicatorShortName("Super Trend");
   IndicatorDigits((int)MarketInfo(Symbol(),MODE_DIGITS));
   SetIndexBuffer(0,buffer_line_up);
   SetIndexLabel(0,"Up Trend");
   SetIndexBuffer(1,buffer_line_down);
   SetIndexLabel(1,"Down Trend");

//--- 2 additional arrows buffers
//---- drawing settings
   SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID,EMPTY,clr_Up);
   SetIndexArrow(2,233);
   SetIndexStyle(3,DRAW_ARROW,STYLE_SOLID,EMPTY,clr_Dn);
   SetIndexArrow(3,234);
//---- indicator buffers
   SetIndexBuffer(2,ArrowUpBuffer);
   SetIndexBuffer(3,ArrowDnBuffer);
   SetIndexEmptyValue(2,0.0);
   SetIndexEmptyValue(3,0.0);  
  
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit-=1+2;

   for(int i=limit; i>=0; i--) 
     {
      atr   = iATR(Symbol(),0,ATR_Period,i);
      shift = 0.5*iATR(Symbol(),0,100,i);;
      band_upper = (High[i]+Low[i])/2 + ATR_Multiplier * atr;
      band_lower = (High[i]+Low[i])/2 - ATR_Multiplier * atr;

      if(phase==PHASE_NONE) 
        {
         buffer_line_up[i]=(High[i+1]+Low[i+1])/2;
         buffer_line_down[i]=(High[i+1]+Low[i+1])/2;
        }

      if(phase!=PHASE_BUY && Close[i]>buffer_line_down[i+1] && buffer_line_down[i+1]!=EMPTY_VALUE) 
        {
         phase = PHASE_BUY;
         buffer_line_up[i]=band_lower;
         buffer_line_up[i+1]=buffer_line_down[i+1];
        }

      if(phase!=PHASE_SELL && Close[i]<buffer_line_up[i+1] && buffer_line_up[i+1]!=EMPTY_VALUE) 
        {
         phase = PHASE_SELL;
         buffer_line_down[i]=band_upper;
         buffer_line_down[i+1]=buffer_line_up[i+1];
        }

      if(phase==PHASE_BUY
         && ((TrendMode==0 && buffer_line_up[i+2]!=EMPTY_VALUE) || TrendMode==1)) 
        {
         if(band_lower>buffer_line_up[i+1]) 
           {
            buffer_line_up[i]=band_lower;
           }
         else 
           {
            buffer_line_up[i]=buffer_line_up[i+1];
           }
        }
      if(phase==PHASE_SELL
         && ((TrendMode==0 && buffer_line_down[i+2]!=EMPTY_VALUE) || TrendMode==1)) 
        {
         if(band_upper<buffer_line_down[i+1]) 
           {
            buffer_line_down[i]=band_upper;
           }
         else 
           {
            buffer_line_down[i]=buffer_line_down[i+1];
           }
        }
        
        // Make Arrows
        if (buffer_line_up[i+1]  !=EMPTY_VALUE && 
            buffer_line_up[i+2]  !=EMPTY_VALUE && 
            buffer_line_down[i+2]!=EMPTY_VALUE) {
           ArrowUpBuffer[i+1]=Low[i+1]-shift;
           ArrowDnBuffer[i+1]=0.0;

        }
        if (buffer_line_down[i+1] !=EMPTY_VALUE && 
            buffer_line_down[i+2] !=EMPTY_VALUE && 
            buffer_line_up[i+2]   !=EMPTY_VALUE) {
           ArrowDnBuffer[i+1]=High[i+1]+shift;
           ArrowUpBuffer[i+1]=0.0;

        }
     }

   return(0);
  }
//+------------------------------------------------------------------+

请告诉我它有什么问题。

Supertrend
Supertrend
  • www.mql5.com
AudioPrice Revision 1 Have audio output of latest price in stereo! Revised to cater for fractional pips as now offered by some brokers to MT4. Stochastic Net Stochastic net for the the classification problems with the instruction provided.
附加的文件:
 
Grigori.S.B:

请告诉我我做错了什么。

我犯了一个错误,单独插入了这个附加组件。箭头应该只放在缓冲区变化的时刻。同时,不要忘记在所有其他情况下,在缓冲区中放入一个空值。

甚至更好:一次放一个空值,当趋势发生变化时,用一个箭头填充其中一个缓冲区。

 
Grigori.S.B:

但如果我向后/向左滚动,就会出现胡言乱语,一切都会中断。

历史记录被扫除了吗?在这种情况下,你没有重新计算,出现的新指标缓冲区 项目都是垃圾。

 
怎么,既然没有人愿意回答,我是不是又错过了什么基本的东西?