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

 
STARIJ:
Try to write Date, Time, Bid and results of your calculations in file for each tick. Then upload it to Excel and check it. It hardly makes sense to reconcile every dozen lines of the program!

But look, you have return in every branch of the conditional operator, i.e. it is always executed. So we take it out of the conditional operator:

Bid[1] - is it so?


Thank you. I will try it now. I understood the gist of your code and it is already a great achievement for me :) I also saw my shortcomings.

What is SRC button?

 
STARIJ:
Try to write Date, Time, Bid and results of your calculations to the file for each tick. Then upload it to Excel and check it. It hardly makes sense to reconcile every dozen lines of the program!

But look, you have return in every branch of the conditional operator, i.e. it is always executed. So we take it out of the conditional operator's scope:

Bid[1] - is it like that?


I have inserted the code in the "constructor" of the custom indicator. I have compiled it. The compiler generated 1 warning: Two OnCalculate are defined. OHLC version will be used (I don't understand what it means).

Got compiled product. Attach it to the chart. The separate window for the chart is opened but it does not show any info about the histogram, despite the ticks.

What is wrong? Please, advise?

#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Label2
#property indicator_label2  "Label2"
#property indicator_type2   DRAW_HISTOGRAM
#property indicator_color2  clrDarkTurquoise
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

//- local variables
int Tick, Tick2;       // Для вставки программы используйте кнопку SRC
double Bid1;

//--- indicator buffers
double         Label1Buffer[];
double         Label2Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);
   SetIndexBuffer(1,Label2Buffer);
   Bid1=Bid;
//---
   return(INIT_SUCCEEDED);
  }
  
 
    void start()   // Вместо start более модно писать OnTick
{
    if(Bid > Bid1) Tick++;                             
    else Tick2++;
    Bid1=Bid;                      
}
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

 
YarTrade:

I inserted the code into the "constructor" of the custom indicator. Compiled it. The compiler gave me 1 warning: two OnCalculate are defined. OHLC version will be used (I don't know what it means).

Got compiled product. Attach it to the chart. The separate window for the chart is opened but it does not show any info about the histogram, despite the ticks.

What is wrong? Can you advise?

When you paste the code here, use button of message editor SRC - at the top of message field there are many useful things in the message formatting panel.

It's not hard to raise your eyes just above the text you're typing, is it? And it's much more pleasant for people to look at normal code instead of the swag, isn't it?

I have inserted your code for you in your post correctly (SRC)

 
Artyom Trishkin:

When you paste the code in here, use the SRC post editor button - there are lots of useful features in the post formatting panel at the top of the post box.

It's not hard to raise your eyes just above the text you're typing, is it? And it's much more pleasant for people to look at the normal code instead of the swag, isn't it?

I put your code in your message for you correctly (SRC)


Yeah. Thanks. I didn't know that.

 
YarTrade:

Issued 1 warning to compiler: two OnCalculate are defined. OHLC version will be used (not sure what this means).

Got compiled product. Attach it to the chart. The separate window for the chart is opened but it does not show any info about the histogram, despite the ticks.

What is wrong? Please, advise?

The function was called Start before, now it is called OnTick in Expert Advisor and OnCalculate in indicator. The compiler warns: you have the same function twice under different names. Move the contents of Start to OnCalculate and delete Start. You would also need to describe in your program, what and how it should be displayed. First decide for yourself - what image must be there? It is better to start studying the MQL language by writing scripts. An Expert Advisor is more complicated, an indicator is even more complicated

 
STARIJ:

The function used to be called Start, now it is called OnTick in the EA and OnCalculate in the indicator. The compiler warns: you have the same function twice under different names. Move the contents of Start to OnCalculate and delete Start. You would also need to describe in your program, what and how it should be displayed. First decide for yourself - what image must be there? It is better to start studying the MQL language by writing scripts. The Expert Advisor is more difficult, the indicator is even more difficult.


I cannot insert the content of Start in OnCalculate and get a lot of errors

 
YarTrade: I can't insert the content of Start into OnCalculate, it generates a lot of errors


The indicator only displays information from the start. The Data window (Ctrl-D) shows data of the candlestick, to which the cursor is pointing

//+------------------------------------------------------------------+
//|                                                     -Тики-07.mq4 |
//+------------------------------------------------------------------+
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 2
//  #property indicator_plots   2        в MQL-4 такое отсутствует
#property indicator_label1  "Вверх"
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_color1  Salmon
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2

#property indicator_label2  "Вниз"
#property indicator_type2   DRAW_HISTOGRAM
#property indicator_color2  clrDarkTurquoise
#property indicator_style2  STYLE_SOLID
#property indicator_width2  2

datetime Время=0;   // Время прошлого бара
double Bid1;

double   Buf_1[], Buf_2[]; // 2 буфера

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
{
   IndicatorDigits(0);
   SetIndexBuffer(0,Buf_1);
   SetIndexBuffer(1,Buf_2);
   Bid1=Bid;
}
 
 
//+------------------------------------------------------------------+
//| 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[])
{
   datetime Вр=Time[0];   // Время текущего бара
   if(Вр>Время)           // Если новый бар
   {
      Время=Вр;           // Запомнить
      Buf_1[0]=0;         // и обнулить последний элемент буфера
      Buf_2[0]=0;
   }

   if(Bid > Bid1) Buf_1[0]++;                             
   else Buf_2[0]--;
   Bid1=Bid;                      

  return(rates_total);
}
 
Alexey Kozitsyn:

:)

and how do you formulate the created situation with the names of the functions?
 
STARIJ:
And how do you formulate the created situation with function names?

start - obsolete name. OnTick() is the actual name of the tick handling function.

Anyway, it doesn't make any difference how you define it, just the word "trendy" made me smile.

 
Alexey Kozitsyn:

start - obsolete name. OnTick() is the actual name of the tick handling function.

Anyway, it doesn't matter how you define it, it's just the word "trendy" that makes you smile.

Obsolete is not used anymore. But start lives and will live on.
Reason: