question about getting the ask price on previous candles

To add comments, please log in or register
Farzin Sadeghi
6903
Farzin Sadeghi  

Hi , Is there any way to get the value of Ask or Bid price of previous candles ? for example I want to see what was the max ask value on candle 10th from the last candles.

I saw that Ask value in mt4 , or SymbolInfoDouble(_Symbol,SYMBOL_ASK);  is only referring to the value of latest ticks on last candle. 

how should I get this value in past candles ? 

Jose Francisco Casado Fernandez
5160
Jose Francisco Casado Fernandez  

MT4 doesn't save ask or bid prices (only OHLC prices for each bar). It would be possible only if you use an EA saving ticks 24 hours a day, but it's not an ideal solution because no EA will save all the ticks (when there is a high volatility in the market you will not be able to save all the ticks and if you lose connection to the broker server you will lose a lot of ticks until you reconnect).

In MT5 it's possible natively. You can use CopyTicksRange().

Regards.

Documentation on MQL5: Timeseries and Indicators Access / CopyTicksRange
Documentation on MQL5: Timeseries and Indicators Access / CopyTicksRange
  • www.mql5.com
Timeseries and Indicators Access / CopyTicksRange - Reference on algorithmic/automated trading language for MetaTrader 5
honest_knave
Moderator
2302
honest_knave  
Jose Francisco Casado Fernandez:

It would be possible only if you use an EA saving ticks 24 hours a day, but it's not an ideal solution because no EA will save all the ticks (when there is a high volatility in the market you will not be able to save all the ticks and if you lose connection to the broker server you will lose a lot of ticks until you reconnect).

Just for reference: I harvest ticks and generally get around 70% (depending on the broker and the instrument).

The code is lightweight and the results are very similar on old and new hardware alike, which leads me to believe the code doesn't miss many ticks.

My conclusions are that brokers do not send every tick, even in quiet times. I've also seen volume drop between ticks on the same bar!!

If you go for this option, you will need to interpolate for the missed ticks.

Farzin Sadeghi
6903
Farzin Sadeghi  

I tried to use this copyTicksRange for the first time and I get : 'copyAskArray' - parameter conversion not allowed Far-Test-MQLtick.mq5 39 27

here is how I wrote it :

MqlTick copyAskArray;

int milliTimeEnd=GetTickCount();

CopyTicksRange(_Symbol,copyAskArray,COPY_TICKS_INFO,(milliTimeEnd-100000/*last 100 seconds*/),milliTimeEnd); 

 

I think the problem is that I use it in OnCalculate in an indicator.

I'll try to put it in OnTick of an expert. maybe it works. 


Farzin Sadeghi
6903
Farzin Sadeghi  
Farzin Sadeghi:

I tried to use this copyTicksRange for the first time and I get : 'copyAskArray' - parameter conversion not allowed Far-Test-MQLtick.mq5 39 27

here is how I wrote it :

MqlTick copyAskArray;

int milliTimeEnd=GetTickCount();

CopyTicksRange(_Symbol,copyAskArray,COPY_TICKS_INFO,(milliTimeEnd-100000/*last 100 seconds*/),milliTimeEnd); 

 

I think the problem is that I use it in OnCalculate in an indicator.

I'll try to put it in OnTick of an expert. maybe it works. 


I could fix this step ...

 MqlTick copyAskArray[];

uint milliTimeEnd=GetTickCount();

Jose Francisco Casado Fernandez
5160
Jose Francisco Casado Fernandez  

Yes, you have to use a MqlTick array (MqlTick MyTicks[]; for example).

To get the open bar time for passing to CopyTicksRange function you would have to use CopyTime(....) (or predefined time[] array inside OnCalculate() if you are coding an indicator) instead of GetTickCount().  Regards-

Farzin Sadeghi
6903
Farzin Sadeghi  
Jose Francisco Casado Fernandez:

Yes, you have to use a MqlTick array (MqlTick MyTicks[]; for example).

To get the open bar time for passing to CopyTicksRange function you would have to use CopyTime(....) (or predefined time[] array inside OnCalculate() if you are coding an indicator) instead of GetTickCount().  Regards-

I couldn't get it to work :

if(doneBefore==false){

      uint milliTimeEnd=GetTickCount();

      ResetLastError();

      numberofCopied=CopyTicksRange(_Symbol,copyAskArray,COPY_TICKS_INFO,(milliTimeEnd-100000),milliTimeEnd);

      //datetime current

      doneBefore=true;

      Print(__LINE__,"-ArraySize=",ArraySize(copyAskArray)," | numberofCopied=",numberofCopied," | error=",GetLastError());

   } 

on expert on tick function :

2016.12.16 01:01:16.476 Far-Test-MQLtick (EURUSD,M1) 43-milliTimeEnd=470298640 | ArraySize=0 | numberofCopied=0 | error=0

-----------------------

on Indicator On calculate I get error 4403 : ERR_HISTORY_TIMEOUT

I think I am pointing to the millisecond time in a wrong way. 

To add comments, please log in or register