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

 
I found a new indicator, I wanted to put it on my EA, but the problem is that it opens trades on every candle. Can you tell me how to make it open only on arrow signal?
//------------------------------------------------------------------
#property copyright "Hill"
#property link      "Romio.com"
//------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Orange
#property indicator_color2 DarkGray
#property indicator_color3 Orange
#property indicator_color4 LimeGreen
#property indicator_style2 STYLE_DOT
#property indicator_style3 STYLE_DOT
#property indicator_style4 STYLE_DOT
//

//
//
//
//
//

extern int    RsiLength  = 4;
extern int    RsiPrice   = PRICE_CLOSE;
extern int    HalfLength = 5;
extern int    DevPeriod  = 100;
extern int    Sise       = 10;
extern double Deviations = 1.0;
extern bool   UseAlert   = true;
extern bool   DrawArrows = true;

color ColorDn = Crimson;
color ColorUp = DodgerBlue;
int     CodDn = 222;
int     CodUp = 221;

string   Font = "Verdana";

// ti init() if(ObjectFind("100s")<0)GetText(3,"100s","BuySell Pro",LawnGreen,5,5,7);


string PrefixArrow = "ArrowsHill";

double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];

double up[];
double dn[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   HalfLength=MathMax(HalfLength,1);
   SetIndexBuffer(0,buffer1);
   SetIndexBuffer(1,buffer2);
   SetIndexBuffer(2,buffer3);
   SetIndexBuffer(3,buffer4);

   SetIndexStyle(4,DRAW_ARROW,0,2,Blue);
   SetIndexArrow(4,233);
   SetIndexBuffer(4,up);

   SetIndexStyle(5,DRAW_ARROW,0,2,Red);
   SetIndexArrow(5,234);
   SetIndexBuffer(5,dn);


   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   DellObj(PrefixArrow);

   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int i,j,k,counted_bars=IndicatorCounted();
   if(counted_bars<0)
      return(-1);
   if(counted_bars>0)
      counted_bars--;
   int limit=MathMin(Bars-1,Bars-counted_bars+HalfLength);

   static datetime timeLastAlert = NULL;

   for(i=limit; i>=0; i--)
      buffer1[i] = iRSI(NULL,0,RsiLength,RsiPrice,i);
   for(i=limit; i>=0; i--)
     {
      double dev  = iStdDevOnArray(buffer1,0,DevPeriod,0,MODE_SMA,i);
      double sum  = (HalfLength+1)*buffer1[i];
      double sumw = (HalfLength+1);
      for(j=1, k=HalfLength; j<=HalfLength; j++, k--)
        {
         sum  += k*buffer1[i+j];
         sumw += k;
         if(j<=i)
           {
            sum  += k*buffer1[i-j];
            sumw += k;
           }
        }
      buffer2[i] = sum/sumw;
      buffer3[i] = buffer2[i]+dev*Deviations;
      buffer4[i] = buffer2[i]-dev*Deviations;

      if(buffer1[i] >= buffer3[i] /*&& buffer1[i+1] < buffer3[i+1]*/)
        {
         dn[i] = buffer3[i];
         if(DrawArrows)
            ArrowDn(Time[i], High[i]);

         if(UseAlert && i == 0 && Time[0] != timeLastAlert)
           {
            Alert("Signal DOWN!");
            timeLastAlert = Time[0];
           }
        }

      if(buffer1[i] <= buffer4[i] /*&& buffer1[i+1] > buffer4[i+1] */)
        {
         up[i] = buffer4[i];
         if(DrawArrows)
            ArrowUp(Time[i], Low[i]);

         if(UseAlert && i == 0 && Time[0] != timeLastAlert)
           {
            Alert("Signal UP!");
            timeLastAlert = Time[0];
           }
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ArrowUp(datetime tim,double pr)
  {
   if(ObjectFind(PrefixArrow+"TextUp"+tim)==-1)
     {
      if(ObjectCreate(PrefixArrow+"TextUp"+tim,OBJ_TEXT,0,tim,pr-GetDistSdvig()))
         ObjectSetText(PrefixArrow+"TextUp"+tim,CharToStr(CodUp),Sise,"WingDings",ColorUp);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ArrowDn(datetime tim,double pr)
  {
   if(ObjectFind(PrefixArrow+"TextDn"+tim)==-1)
     {
      if(ObjectCreate(PrefixArrow+"TextDn"+tim,OBJ_TEXT,0,tim,pr+GetDistSdvig()))
         ObjectSetText(PrefixArrow+"TextDn"+tim,CharToStr(CodDn),Sise,"WingDings",ColorDn);
     }
  }
extern double TextSdvigMnoj = 2;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetDistSdvig()
  {
   return(iATR(NULL, 0, 100, 1) * TextSdvigMnoj);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DellObj(string dell)
  {
   string name;
   for(int i = ObjectsTotal()-1 ; i >=0 ; i--)
     {
      name = ObjectName(i);
      if(StringFind(name, dell) != EMPTY)
         ObjectDelete(name);
     }
  }
//+------------------------------------------------------------------+
 
jarikn:
I found a new indicator, I wanted to put it on the EA, but the problem is that it opens trades on every candle. Please advise how to make it open only on arrow signal

First of all, the indicator is not new at all, but very old. So old that its interfaces are outdated even for 4

Secondly, it redraws. Exactly at HalfLength (5 bars by default, set in parameters)

and finally - how to open trades for Expert Advisor depends on 90% of the EA, that is, without the EA code, everything is useless

 
Maxim Kuznetsov:

First of all, the indicator is not new at all, but very old. So old that its interfaces are obsolete even for 4

Secondly, it redraws. Exactly at HalfLength (5 bars by default, set in parameters)

And finally - how to open trades for Expert Advisor depends 90% on the EA, i.e. without the EA code, everything is useless

Ok. Got it. For example, if we take 2 indicators with different periods and write the condition *if 1 indicator shows the up arrow and 2 indicators shows the up arrow on one candle, give us an alert and an arrow on the chart*. Do you know how this can be implemented? Do I need to add a buffer or can I create an indicator that follows the signals of both? And if you are not hard, give an example how to do it

 
jarikn:

ok. got it. For example, if we take 2 indicators with different periods and write the following condition *if 1 indicator shows the up arrow and 2 indicators shows the up arrow on one candle, it will generate for example an alert and an arrow on the chart*. Do you know how this can be implemented? Do I need to add a buffer or can I create an indicator that follows the signals of both? And if you are not hard, give an example how to do it

If you add two iCustom indicators with different periods to your Expert Advisor, you will (probably) be in luck.
 
MakarFX:
Add two iCustom with different periods to your EA and (maybe) you'll be happy.

OK, I'll give it a try. Thank you.

 

Hello again )))) Who can tell me what is the indicator?

<*.ex* file deleted

 

I'm trying to write an indicator like ZigZag by the number of passed points.

I'm afraid I don't have enough knowledge to write it myself, so I decided to rewrite someone else's indicator.

This is what has come out

#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_SECTION
#property indicator_color1  clrCrimson
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      Points=50;
//--- indicator buffers
int Trend=1,InTrend;
datetime ttime;
double Last_High,Last_Low;
double Buffer01[],Buffer02[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorBuffers(2);
   IndicatorDigits(Digits);
//--- indicator buffers mapping
   SetIndexBuffer(0,Buffer01);
   SetIndexBuffer(1,Buffer02);
   SetIndexEmptyValue(0,0);
//---
   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 limit=rates_total-prev_calculated-2;
   if(limit<2) return(0);
   for(int i=limit; i>=0;i--)
     {
      if(time[i]!=ttime) {InTrend=InTrend+1; ttime=time[i];}
      Buffer01[i]=0;
      Buffer02[i]= open[i]; 
      if(Buffer02[i+1]>Last_High && Trend==1)   InTrend=1;
      if(Buffer02[i+1]<Last_Low  && Trend==0)   InTrend=1;
      if(Buffer02[i+1]>Last_High) Last_High=Buffer02[i+1];
      if(Buffer02[i+1]<Last_Low ) Last_Low =Buffer02[i+1];
      //----
      if(Trend==1 && Buffer02[i+1]<Last_High-Points*Point && InTrend>1)
        {
         Trend=0;
         if(i+InTrend<ArraySize(Buffer01))
         Buffer01[i+InTrend]=Buffer02[i+InTrend];
         Last_High=Buffer02[i+1];
         Last_Low=Buffer02[i+1];
         InTrend=1;
        }
      if(Trend==0 && Buffer02[i+1]>Last_Low+Points*Point && InTrend>1)
        {
         Trend=1;
         if(i+InTrend<ArraySize(Buffer01))
         Buffer01[i+InTrend]=Buffer02[i+InTrend];
         Last_Low=Buffer02[i+1];
         Last_High=Buffer02[i+1];
         InTrend=1;
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

It seems to be drawing correctly, but it lags.

The price has passed 50 points but indicator does not draw.

Please help me to fix this problem.

 
MakarFX:

Help solve the problem, please.

Here is the point by point ZZ posted for MT5

https://www.mql5.com/ru/forum/318267#comment_12508440


should work in MT4 if you change the numbering in the main calculation cycle

 
Igor Makanu:

here is the point-by-point ZZ posted for mt5

https://www.mql5.com/ru/forum/318267#comment_12508440


It should work in MT4 if you renumber the main calculation cycle

Igor, thank you, but MT4 does not work correctly.


Please tell me what has to be correct.

 
I have encountered such a problem. I put the mt2 indicator on mt4. it is supposed to read the indicator buffers and when the arrow appears it should automatically open trades on binary options. but the problem is that I have it opening trades every new candle and only upwards. Who knows what's wrong?
Files:
Screenshot_8.png  121 kb
123.mq4  5 kb
Reason: