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

 
Fast235:

that's for me,

there will be an extra lag until all dots are set by the chart during compilation

If necessary (for example, recompile), create a terminal variable expetname.deinitreason.ChartId() in OnDeinit and give it a flag temporary, put the reason code there. The same with related data (you may need it).

in OnInit - see if the variable exists, act on its value.

and delete such variable in any case...

---

hint - abnormal terminations are caught in the same way but in reverse :-) In OnInit a variable is checked and created, and in OnDeinit it is deleted. If a critical error occurred and EA/terminal just crashed, the variable will remain.

 
Maxim Kuznetsov:

If necessary (e.g. recompile), create a terminal variable expetname.deinitreason.ChartId() in OnDeinit and give it the flag temporary, place the reason code there. The same with related data (you may need it).

in OnInit - see if the variable exists, act on its value.

and delete such variable in any case...

---

hint - abnormal terminations are caught in the same way but in reverse :-) In OnInit a variable is checked and created, and in OnDeinit it is deleted. If a critical error occurred and EA/terminal just crashed, the variable will remain.

I'm familiar with files and global variables, it's not worth to create this, maybe developers will remove from compilation - 0, or even add a state that the terminal started, for example, I may add a history loader for multisymbol instead of input

 

Hi all! The idea was to make the candles, volume, in different colours depending on the direction of the candles (up or down). However, the last candle gets different colours because of changes in the direction of the candle over time. And over time, all the candles get different colors. The question is how to change the colour of the last candle and not to change the others. Or maybe another idea.



//+------------------------------------------------------------------+
//|                                      VSA_Volume_Color            |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 3

//////////////
datetime PrevTime = 0;
double iVolume_UP[];
double iVolume_DWN[];
double iVolume_NULL[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorDigits(5);
//--- indicator buffers mapping
   SetIndexBuffer(0, iVolume_UP);
   SetIndexBuffer(1, iVolume_DWN);
   SetIndexBuffer(2, iVolume_NULL);
//---
   SetIndexStyle(0, DRAW_HISTOGRAM,EMPTY,2,clrGreen);
   SetIndexStyle(1, DRAW_HISTOGRAM,EMPTY,2,clrWhite);
   SetIndexStyle(2, DRAW_HISTOGRAM,EMPTY,2,clrRed);
//---
   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 i = 0, counted_bars = IndicatorCounted();
   i = Bars - counted_bars - 1;
   if(counted_bars < 0)
      return(-1);
//---
   if(counted_bars > 0)
      counted_bars--;
//--- return value of prev_calculated for next call
///////////
   while(i >= 0)
     {
      if(Close[i] > Open[i])
         iVolume_UP[i] =  iVolume(NULL, 0, i) * 1.0;
      if(Close[i] < Open[i])
         iVolume_DWN[i] =  iVolume(NULL, 0, i) * 1.0;
      if(Close[i] == Open[i])
         iVolume_NULL[i] =  iVolume(NULL, 0, i) * 1.0;
      i--;
     }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   return(rates_total);
  }
//+------------------------------------------------------------------+
Thank you!
 

Reset unnecessary buffers

iVolume_UP[i]=EMPTY_VALUE;
 

link to a separate topic -SERIES_LASTBAR_DATE

the printer showed that the missed signal because - the signal came from the indicator through the custom event, it checked for a new bar using SERIES_LASTBAR_DATE and

in the print the data of the previous bar, not new ..., about 50 trades in total of 7 characters, slips such, what can you look at, any ideas? ping 150.

Ryzen 3700x processor 16 threads

----

if i use a similar multi-symbol scheme, i have tried it on 2 or 3 terminals in realtime, on M1 for example, i wait from a couple hours to half a day for a skip like this, with 40-50 trades per day

Processor load a few % of the robot, almost sleeps.

В моих ТС пропуск сигнала
В моих ТС пропуск сигнала
  • 2021.03.16
  • www.mql5.com
Не люблю создавать новые темы, Небольшие исходные данные: Советник работает в OnChatEvent, 7 символов, циклов нет, прямая передача номера за минусо...
 

one trade at 30-50, okay, it can close both in the black and in the black, but

I have a system for calculating total profits, which is quite tricky, and it should involve this trade now, not at the next signal

you can dig deeper for 5 years.

if the event model is crooked, please let the developers know so it can be discarded, judging from the initial posts on spy, where different variants were tested, there was also scatter and omissions?
 
Aleksei Stepanenko:

Reset unnecessary buffers

Great. Everything works ). Thank you!
 
Guys, please advise, I'm confused with indexing in mql5 indicator buffers.
If theArraySetAsSeries(Buffer, true) function is applied
, only indexing is expanded? Or the buffer values are expanded as well?
 
Roman:
Guys, please advise, I'm confused with indexing in mql5 indicator buffers.
If theArraySetAsSeries(Buffer, true) function is applied
, only indexing is expanded? Or the buffer values are expanded as well?
When true, the zero bar of the indicator buffer is the rightmost one on the chart. If false, it is the leftmost bar.
Nothing else.
 
Artyom Trishkin:
When true the zero bar of indicator buffer is rightmost on the chart. At false it is leftmost.
That's all there is to it.

Thank you.
Artem please tell me one more thing.
The function

ChartSetInteger(ChartID(), CHART_SHOW, false)
Hides the main chart window, and subwindows of the installed indicator.
How can I hide only the main chart window? At the same time, the indicator subwindow should remain visible.