Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1065

 
yiduwi:

Thank you. Can you tell me why the arrow is placed on the second bar and not on the first.

So you put the arrow on the second bar and not on the first - it doesn't draw itself, does it? )))

You must have added an extra one here BufferDN[i+1]=high[i+1];

 
Igor Makanu:

so you put the arrow on the second bar and not on the first - it doesn't draw itself, does it? )))

I guess you must have added an extra one here BufferDN[i+1]=high[i+1];

Uh, without the one, in general the arrow is placed on the third bar, Code small, where did I screw up?

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot UP
#property indicator_label1  "UP"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrLawnGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot DN
#property indicator_label2  "DN"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrDeepPink
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

//--- indicator buffers
double         BufferUP[];
double         BufferDN[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,BufferUP);
   SetIndexBuffer(1,BufferDN);
   PlotIndexSetInteger(0,PLOT_ARROW,233);
   PlotIndexSetInteger(1,PLOT_ARROW,234);

//---

   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[])
  {
//---
   if(rates_total<3) return(0);
   int limit=rates_total-prev_calculated;
   if(limit>1)
     {
      limit=rates_total-3;
      ArrayInitialize(BufferUP,EMPTY_VALUE);
      ArrayInitialize(BufferDN,EMPTY_VALUE);
     }
   for(int i=limit; i>=0; i--)
     {
      if (fabs(high[i+1]-high[i+2]) <= 0.0*_Point)
        {
         BufferDN[i]=high[i];
        }
     }
//--- return value of prev_calculated for next call

   return(rates_total);
  }
It goes to the first bar, if so.
BufferDN[i+2]=high[i+2];
I don't get it.
 
Igor Makanu:

Here's the solution, but I don't think there's anything I've considered.

Logic says it's right.

 
yiduwi:

Ugh, no unit, in general the arrow is put on the third bar, Code small, where did I mess up?

It's put on the first bar, if so I don't get it.

Probably so, but I don't write it under MT5, I could be wrong.

//+------------------------------------------------------------------+
//|                                                          tst.mq5 |
//|                                                            IgorM |
//|                              https://www.mql5.com/ru/users/igorm |
//+------------------------------------------------------------------+
#property copyright "IgorM"
#property link      "https://www.mql5.com/ru/users/igorm"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot UP
#property indicator_label1  "UP"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrLawnGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot DN
#property indicator_label2  "DN"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrDeepPink
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

input int Pips=5;
//--- indicator buffers
double         BufferUP[];
double         BufferDN[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,BufferUP);
   SetIndexBuffer(1,BufferDN);
   PlotIndexSetInteger(0,PLOT_ARROW,233);
   PlotIndexSetInteger(1,PLOT_ARROW,234);
//---
   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;
   if(limit>1 || prev_calculated==0)
     {
      limit=rates_total-2;
      ArrayInitialize(BufferUP,EMPTY_VALUE);
      ArrayInitialize(BufferDN,EMPTY_VALUE);
     }
   for(int i=limit; i>=0; i--)
     {
      if(fabs(high[i+1]-high[i])<=_Point*(double)Pips) BufferDN[i]=high[i];
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Igor Makanu:

Probably so, but I don't write under MT5, I could be wrong

Also, on the second bar puts me)

 
Igor Makanu:

Thanks, that's one of the bugs, but still can't figure out how to get from 159,002 seconds to 44 hours 10 minutes 2 seconds (online calculator )) )


here's the solution but i think i'm missing something

2019.06.18 11:46:22.691 tstss EURUSD,H1: h = 44 , m = 10 , s = 2

Seems simpler to me

 int timeinsec = 159002;
 int sec = timeinsec%60;
 int min = ((timeinsec-sec)%3600)/60;
 int hou = (timeinsec-sec-min)/3600;
 
yiduwi:

Also, on the second bar puts me)

The arrow should put only where the condition is fulfilled, yes by the way I remembered for MT5 it is better to have a full slack condition:

if(fabs(high[i+1]-high[i])<=_Point*(double)Pips) BufferDN[i]=high[i]; else BufferDN[i]=EMPTY_VALUE;
Alexey Viktorov:

I think it is easier.

Got it! Thank you! That is exactly what I wanted!

 
There is code with a lot of Print calls. Is there any way to quickly turn them all off without removing Print from the code \To turn them back on ? This is the only option I see so far:
bool L=true;
if(L)Print("123");

I.e. replace all "Print(" with "if(L)Print(" , maybe some other options?

 
pivomoe:
There is code where a lot of Print calls are made. Is there any way to quickly disable them all without removing Print from the code \ Include it back? So far I see only this option:

I.e. replace all "Print(" by "if(L)Print(" , maybe some other options?

In the input parameters output the "Print" flag. It will work like your code, but the flag itself (bool variable) will be in the input parameters.

 

Hello !

Optimisation by all symbols in MT5 tester refuses to work...

Can you please enlighten me on how to make it work ?

THANK YOU.

Reason: