Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1170

 
Carcass77:

My indicator works, I ' m just expanding.

OK, I'll get it myself.

If this is your indicator, the question looks, to put it mildly, alarming...

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

If this is your indicator, the question looks, to put it mildly, alarming...

It's working. The question was about the "form" of the string variable declaration. I'm still learning, if anything, gentlemen programmers.

 
Carcass77:

It worked. The question was about the "form" of the string variable declaration. I'm still learning, if anything, gentlemen programmers.

Everyone's learning, that's normal.

My question arose because your example was not of beginner's level, and the question about variable types and scope is the first thing you have to understand when you first try to write your code - without understanding this, you will not get anything at all in the future

 
Carcass77:

It worked. The question was about the "form" of the string variable declaration. I'm still learning, if anything, gentlemen programmers.

I'm still learning too )))) And hopefully I can still learn a lot ;)

 

Greetings All ! How to pass to the button , name + value ( example button Lots = 0.1 ) ?

Thanks in advance !

 
Hello! I'm trying to draw a trend line using lower fractals and it's not working. Takes the beginning of times as the first point, draws one line and that's it. It does not go to the next fractal. What am I doing wrong, how can I fix it?
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;
   
       }
      }
     }
   }
  } 
 

Added arrows to the SuperTrend indicator downloaded from kodobase. It draws the arrows normally on startup,


but if I scroll back/left on the chart, the gibberish appears and everything crashes.


Here is the code:

//+------------------------------------------------------------------+
//|                                                   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);
  }
//+------------------------------------------------------------------+

Please tell me what's wrong with it.

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.
Files:
 
Grigori.S.B:

Please tell me what I did wrong.

I made a mistake by inserting this add-on separately. The arrows should be put only at the moment of buffer change. At the same time, do not forget to put an empty value in the buffer in all other cases.

Even better: put an empty value at once, and fill one of the buffers with an arrow when the trend changes.

 
Grigori.S.B:

but if I scroll backwards/leftwards, the gibberish appears and everything breaks.

is the history being swept up? you don't have a recalculation for this case and the new indicator buffer items that appear are filled with rubbish.

 
What, am I missing something elementary again since no one wants to answer?
Reason: