Questions from Beginners MQL5 MT5 MetaTrader 5 - page 93

 
ryzhak.vladimir:

Hello! There is an array of closing prices of 30 min bars of the EURUSD pair, from 01.01.2012 to 31.12.2012. I get it with function CopyClose. But CopyClose[0] doesn't equal to close price of last bar on 31.12.2012 in terminal, if I open chart. Please tell me what I'm doing wrong. Why the prices from CopyClose and the actual price on the chart do not coincide

Before you call Close_buf[0] you must use ArraySetAsSeries. Once, during entire operation of EA/Script/indicator code.

ArraySetAsSeries(Close_buf,true);
 
fyords:

ArraySetAsSeries must be used before calling Close_buf[0]. Once, for the entire duration of the EA/script/indicator code.

It still does not match, it shows 1.32308 instead of 1.31964 (last bar close price in 2012)

//+------------------------------------------------------------------+
//|                                                    simpleBet.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
double Close_buf[];//динамический массив для хранения значений закрытия баров
string my_symbol = "EURUSD";//валютная пара
ENUM_TIMEFRAMES my_timeframe = PERIOD_M30;//таймфрейм
datetime testTimeStart = D'2012.01.01';
datetime testTimeEnd = D'2012.12.31';
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---    
     CopyClose(my_symbol,my_timeframe,testTimeStart,testTimeEnd,Close_buf); 
     ArraySetAsSeries(Close_buf,true);
     Print(Close_buf[0]);
  }
//+------------------------------------------------------------------+
 
ryzhak.vladimir:

Still doesn't match, displays 1.32308 instead of 1.31964 (closing price of last bar in 2012)

You set
datetime testTimeEnd = D'2012.12.31';
And if you set
datetime testTimeEnd = D'2012.12.31 23:59:59';
 
Yes it worked, thank you! Although it's still not clear why the prices only matched when the exact date was given, down to the seconds
 
ryzhak.vladimir:
Yes it worked, thank you! Although it's still not clear why the prices only matched when the exact date was specified down to the seconds

Probably because 2012.12.31 defaults to 2012.12.31 00:00:00, not 2012.12.31 24:00:00

 
The quote from the documentation about the CopyBuffer function:"The data elements to be copied (indicator buffer with index buffer_num) are counted from the start position from the present to the past, i.e. the start position equal to 0 means the current bar (indicator value for the current bar). "But in practice, in order to have the current bar in the 0th element, we have to apply ArraySetAsSeries(Close_buf,true). But it is written in documentation that by default it copies the last bar in the 0th element. Why is there such a difference?
Усреднение ценовых рядов без дополнительных буферов для промежуточных расчетов
Усреднение ценовых рядов без дополнительных буферов для промежуточных расчетов
  • 2010.10.25
  • Nikolay Kositsin
  • www.mql5.com
Статья о традиционных и не совсем традиционных алгоритмах усреднения, упакованных в максимально простые и достаточно однотипные классы. Они задумывались для универсального использования в практических разработках индикаторов. Надеюсь, что предложенные классы в определенных ситуациях могут оказаться достаточно актуальной альтернативой громоздким, в некотором смысле, вызовам пользовательских и технических индикаторов.
 
ryzhak.vladimir: The quote from the documentation about the CopyBuffer function:"The data elements to be copied (indicator buffer with index buffer_num) are counted from the start position from the present to the past, i.e. the start position equal to 0 means the current bar (indicator value for the current bar). "But in practice, in order to have the current bar in the 0th element, we have to apply ArraySetAsSeries(Close_buf,true). But it is written in documentation that by default it copies the last bar in the 0th element. Why is there such a difference?
Look at the figure more closely. Where is the 'start_pos' item being copied?
 
Faced the problem of psychological direction.
I wrote a trend EA and it seems to be successful. Now I am writing a flat EA and... This is the 5th time this EA is reduced to the previous one, as if I am stuck with only one algorithm. Everything starts out as "new", but after the algorithm is structured, I start writing an EA that starts to adjust to the first (successful) one in every possible way.

If anyone has faced such a thing - tell me how to "get rid" of the imposing algorithm, which only brings down the deposit in the flat.
 
Lester: If you have faced with such a bullshit - tell me how to "get rid" of the imposing algorithm, which in the flat only drains the deposit.
I haven't come across such a thing, but for a general shift of attention try to study other people's algorithms.
 
Lester:

Faced the problem of psychological direction.
I wrote a trend EA and it seems to be successful. Now I am writing a flat EA and... This is the 5th time this EA is reduced to the previous one, as if I am stuck with only one algorithm. Everything starts out as "new", but after the algorithm is structured, I start writing an EA that starts to adjust to the first (successful) one in every possible way.

If anyone has faced such a thing - tell me how to "get rid" of the algorithm, which only brings down the deposit in the flat.
Your trader has not a psychological problem, but a system problem - the lack of precise signs of difference between the trend and the flat. Once you understand this point, everything will work out for you.
Reason: