Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1245

 
Artyom Trishkin:

Not all arrays have the same orientation.

I understand, but I also set ArraySetAsSeries(barsBuffer1 ,true); !

Well, this is half the trouble. But I can't figure out how to add a new candle.

I tried it this way:

.........
   else
   {
      Print("tick_count = ",++tick_count);
      if(tick_count >= 5)
      {
         Print("Добавляем свечу.");
         
         double   O[1], H[1], L[1], C[1];
         O[0]  = newCandles_Open[3];
         H[0]  = newCandles_High[3];
         L[0]  = newCandles_Low[3];
         C[0]  = newCandles_Close[3];
         
         ArrayResize(barsBuffer1,ArraySize(barsBuffer1)+1);
         ArrayResize(barsBuffer2,ArraySize(barsBuffer2)+1);
         ArrayResize(barsBuffer3,ArraySize(barsBuffer3)+1);
         ArrayResize(barsBuffer4,ArraySize(barsBuffer4)+1);
         
         ArrayInsert(barsBuffer1,O,0);
         ArrayInsert(barsBuffer2,H,0);
         ArrayInsert(barsBuffer3,L,0);
         ArrayInsert(barsBuffer4,C,0);
         
         tick_count = 0;
      }
   }
//--- return value of prev_calculated for next call
   return(rates_total);
}

Doesn't work... (((

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

I understand, but I also set ArraySetAsSeries(barsBuffer1 ,true); !

Well, this is half the trouble. But how to add a new candle - I can't figure out.

I tried it this way:

Doesn't work... (((

I'm sorry, but arrays assigned to indicator buffers cannot be resized - the subsystem of the terminal does this.

   SetIndexBuffer(0, barsBuffer1, INDICATOR_DATA);
   SetIndexBuffer(1, barsBuffer2, INDICATOR_DATA);
   SetIndexBuffer(2, barsBuffer3, INDICATOR_DATA);
   SetIndexBuffer(3, barsBuffer4, INDICATOR_DATA);
         ArrayResize(barsBuffer1,ArraySize(barsBuffer1)+1);
         ArrayResize(barsBuffer2,ArraySize(barsBuffer2)+1);
         ArrayResize(barsBuffer3,ArraySize(barsBuffer3)+1);
         ArrayResize(barsBuffer4,ArraySize(barsBuffer4)+1);

Reconsider your logic. I don't know it at all, and can only show what's glaringly wrong.

 
Artyom Trishkin:

I apologise of course, but arrays assigned to indicator buffers cannot be resized - this is handled by the terminal subsystem.

Reconsider your logic. I don't know it at all, and can only show what is blatantly wrong.

That's how I understand it too, but...

Artem, if the indicator buffer is controlled by the subsystem, it means that this subsystem increases its size, too? In other words, a new indicator candlestick cannot be drawn in the chart until a new candlestick appears?

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

That's how I understand it too, but...

Artem, if the indicator buffer is managed by a subsystem, it means it increases its size as well? In other words, until a new candlestick appears on the chart, a new indicator candlestick cannot be drawn on the chart as well?

What is meant by "to draw a new candlestick"?

You can draw them, but the bars cannot be added - they are not present yet.

Yes, the terminal takes care of the size of indicator arrays. It also provides data on how many of them were on the previous call.

 
Artyom Trishkin:

What do you mean by "draw a new candle"?

You can draw all sorts, but you can't add bars - they don't exist yet.

Yes, the terminal itself takes care of the size of indicator arrays. It also provides data on how many of them were on the previous call.

Thank you, now I understand why it fails.

Then one last question. I know we can display candlesticks from another timeframe in the indicator. If the indicator shows candles from H2 and candles from H1, it means we should draw 2 candles during the one candle lifetime. How does it happen if the buffer is only increased by the system? Or give me a link to the example, if it is not too much trouble. Maybe I will figure it out ))))

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

Thank you, now I understand why it's not working for me.

Then one last question. I know that you can show candlesticks from another timeframe in the indicator. If the indicator shows candles from H1, it means we should draw 2 candles during one candle lifetime. How does it happen if the buffer is only increased by the system? Or give me a link to the example, if it is not too much trouble. Maybe I'll figure it out)))

I have given examples in my latest articles on indicators, but they are library based.

To understand how to draw two candlesticks instead of one, take a look at the chart. Look at the time the candle was opened on H2 and where the candle with the same time on H1 is located. Everything will become clear.

 
Artyom Trishkin:

I gave examples in my last articles on indicators, but they are all library-based.

And to understand how to draw two candles instead of one, look at the chart. Look at the time the candle was opened on H2 and where the candle with the same time on H1 is located. Everything will become clear.

Artem, the thing is that I do not get it!

For instance, the candlestick on H2 is open at 12:00. The next one will be at 14:00. But on H1 the next one will be at 13:00. According to the logic, until the candle opens on the higher TF, the indicator array will not be increased! It means I will not be able to draw the second candle in the indicator? Or what?

Explain it to me, unclear takomu..... Why and how can I draw two (or actually n) candlesticks on one chart? Why, if I fill the 0th index of indicator buffer with new value (simple assignment) the indicator will not change?

Maybe I should ask developers for such a possibility? I added a new element to this buffer - it is drawn with a shift of all previous ones to the left. It's my indicator, after all! I write it the way I want! I do not want to bind it to the opening of a new bar on the chart! How hard can it be?

 

Thanks to Artem and Vladimir! Your answers and explanations gave me the idea and the indicator came out. Thank you again.


 

Can you please tell me what's wrong?

There is a simple variable declaration:

input double   StopLoss=150.0;

When debugging on real data, the StopLoss variable has a set value of "150". But if I enable debugging on historical data, the same variable in the same code has a different value. What may be the reason for this? And how to deal with the problem?

 
Sayberix:

Can you please tell me what's wrong?

There is a simple variable declaration:

When debugging on real data, the StopLoss variable has a set value of "150". But if I enable debugging on historical data, the same variable in the same code has a different value. What may be the reason for this? And how to deal with the problem?

Check the values in the 'Parameters' tab of the strategy tester. When you enable debugging on real data, the Expert Advisor takes the values from the input variables, and if you enable it on history, the values are taken from the tester settings.

Reason: