Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1236

 
Vladimir Karputov:

In debugging, go through and check in which cases will your condition hold?


Rates_total - prev_calculates is very effective.

  • If it is equal to zero - it means that calculation will be performed on the current bar by a tick.
  • If it is equal to 1 - it means that there is a new bar and two bars will be calculated - the previous and the current one.
  • If it is greater than 1, it means either the first run or change in the history data
We calculate the limit. And in the loop from limit to greater than or equal to zero, we calculate the indicator data. And you yourself calculate what limit is equal to when calculating limit = rates_total - prev_calculates.
 
Artyom Trishkin:

rates_total - prev_calculates is a very effective construction.

  • If it is equal to zero, it means that calculation is performed on the current bar by the tick
  • If it is equal to 1 - it means that there is a new bar and two bars will be calculated - the previous and the current one
  • If it is greater than 1, it means either the first run or change in the history data
We calculate the limit. And in the loop from limit to greater than or equal to zero, we calculate the indicator data. And you yourself calculate what the limit is when calculating limit = rates_total - prev_calculates.

Look at the code.

Then you can comment on it.

 
Vladimir Karputov:

Look at the code.

Then comment on it.

Why the rudeness? I wasn't being rude.

I answered when the line you quoted and its condition will hold:

Forum on Trading, Automated Trading Systems and Strategy Tests

FAQ from Beginners MQL5 MT5 MetaTrader 5

Vladimir Karputov, 2020.08.06 13:03

In debugging, go through and check, in which cases your condition will be fulfilled?


I even added an answer to three possible conditions and what is done in such a case:

Forum on trading, automated trading systems and strategy testing

FAQ from Beginners MQL5 MT5 MetaTrader 5

Artyom Trishkin, 2020.08.06 15:17

rates_total - prev_calculates is a very efficient algorithm.

  • If it is equal to zero, it means calculation on the current bar by the tick.
  • If it is equal to 1, it means that there is a new bar and two bars will be calculated - the previous and the current one
  • If it is greater than 1, it means either the first run or change in the history data
We calculate the limit. And in the loop from limit to greater than or equal to zero, we calculate the indicator data. And calculate what the limit is when calculating the limit = rates_total - prev_calculates.

You don't need to do anything for processing - this very calculation will start the cycle from the needed value in each of the three states.

 
Artyom Trishkin:

Why be rude? I wasn't being rude.

I answered in which cases the line you quoted and its condition will be fulfilled:

And I even completed the answer with three possible states, and what is done in such a case:

You don't need to do anything to process it yourself - this exact calculation will start a loop from the desired value in each of the three states.

Take the code and go through debugging. Next, you can do it yourself - but now go to the end and explain at least three errors.

 
Vladimir Karputov:

Take the code and go through debugging. Do the rest on your own - but now follow through and explain at least three errors.

No. I don't have time. I only replied to the line you quoted - there's no error there. And from here (I glanced at the code from the corner of my eye) let him try to figure it out for himself (there are errors, and they are on the surface).

There are plenty of examples of such constructs here on the forum and its services.

Victor Nikolaev always used it (or still does if he's not lazy), and taught me a long time ago.

Victor Nikolaev
Victor Nikolaev
  • www.mql5.com
Профиль трейдера
 
Artyom Trishkin:

No. I don't have the time. I only replied to the line you quoted - there is no error in it. And further (I glanced at the code out of the corner of my eye) let him try to figure it out himself (there are errors, and they are on the surface).

There are plenty of examples of such constructs here on the forum and its services.

Victor Nikolaev has always used it (or still uses it if he's not lazy), and taught me a long time ago.

You'd better read the forum not from a mobile phone, but from a computer. And read ALL posts, not favorites. If you don't want to help, don't join the conversation at all.

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


Here is an example: based on DRAW_COLOR_CANDLES, if the size of the candle is smaller than set - the candle is not drawn.

Note: this is a redesigned indicator - it originally drew candlesticks by High and Low. And no ticks yet - just an example of working with DRAW_COLOR_CANDLES, if the candle size is less than set - the candle is not drawn.

//+------------------------------------------------------------------+
//|                                             High Low Candles.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots   1
//--- plot HLC_
#property indicator_label1  "High Low Candles"
#property indicator_type1   DRAW_COLOR_CANDLES
#property indicator_color1  clrLimeGreen,clrLavender
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input uint     InpMinSize     = 150;            // Candles: min size
//--- indicator buffers
double   OpenBuffer[];  // open
double   HighBuffer[];  // high
double   LowBuffer[];   // low
double   CloseBuffer[]; // close
double   Colors[];
//---
double   m_min_size           = 0.0;            // Candles: min size          -> double
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,OpenBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,HighBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,LowBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,CloseBuffer,INDICATOR_DATA);
   SetIndexBuffer(4,Colors,INDICATOR_COLOR_INDEX);
//--- an empty value
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
//--- set the display of the symbol
   string symbol=Symbol();
   PlotIndexSetString(0,PLOT_LABEL,symbol+" Open;"+symbol+" High;"+symbol+" Low;"+symbol+" Close");
   IndicatorSetString(INDICATOR_SHORTNAME,"HLC ("+symbol+")");
//---
   m_min_size=InpMinSize*Point();
//---
   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=prev_calculated-1;
   if(prev_calculated==0)
      limit=0;
   for(int i=limit; i<rates_total; i++)
     {
      HighBuffer[i]=high[i];
      LowBuffer[i]=low[i];
      if(open[i]<close[i])
        {
         if(close[i]-open[i]>m_min_size)
           {
            OpenBuffer[i]=low[i];
            CloseBuffer[i]=high[i];
            Colors[i]=1.0;
           }
         else
           {
            OpenBuffer[i]=0.0;
            HighBuffer[i]=0.0;
            LowBuffer[i]=0.0;
            CloseBuffer[i]=0.0;
            Colors[i]=0.0;
           }
        }
      else
        {
         if(open[i]-close[i]>m_min_size)
           {
            OpenBuffer[i]=high[i];
            CloseBuffer[i]=low[i];
            Colors[i]=0.0;
           }
         else
           {
            OpenBuffer[i]=0.0;
            HighBuffer[i]=0.0;
            LowBuffer[i]=0.0;
            CloseBuffer[i]=0.0;
            Colors[i]=0.0;
           }
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


Result:


Files:
 
Vladimir Karputov:

You should read the forum from your computer instead of your mobile phone. And read ALL the posts, not the favorites. If you don't want to help, don't join the conversation at all.

You sick? :)


 

Guys, Artyom and Vladimir, don't quarrel, there's really nothing to quarrel about... )))

Now for the errors. I began writing this indicator simply to visualize what I read about in this article. And I began to write it after I was sent to the baths a month ago. I mean that I had time to find my own mistakes. I couldn't find them, that's why I came here for help.

I asked you to show me where I'm wrong (in the code). And why?

I can't use the debugger. I don't know how. No variables are added to "watchable" (I wrote about it on the forum quite a long time ago...).

Just tell me where the hitch is?

Дискретизация ценового ряда, случайная составляющая и "шумы"
Дискретизация ценового ряда, случайная составляющая и "шумы"
  • www.mql5.com
Классический способ представления ценовых движений в виде временных отрезков возник на заре становления финансовых рынков, когда еще не было компьютеров и вся торговля шла на реальных рынках, реальными товарами. Хранить каждое изменение цены в течении дня было трудно, да и не имело смысла, цены менялись не так быстро. Поэтому представлялось...
 
Сергей Таболин:

Just tell me where the hitch is?

The hitch is in the organisation of the code. I tried to look at it, but it is written in such a way that my brain can't comprehend it. I don't know how to explain what's wrong.

I can only advise you to start from the beginning and in order.

  1. Start by singling out every N candle.
  2. Then set a condition to choose which candle to highlight.
And finally learn how to use the debugger.
Reason: