Can broker deny access to server's historic time-series/spread info?

 

this is what i was trying , out of curiosity.

CopyRates returns 100/ok , but the buffer is all 0's. 

Is the broker not exposing their historic rates info?

or i'm doing it wrong?

MqlRates rates[100];

int OnCalculate(){

   int copied=CopyRates(_Symbol,NULL,0,100,rates);
   if(copied==-1)Alert("failed copying");

  ArraySetAsSeries(rates,true);
 

  for(int i=0;i<100;i++)
    {
      Print((string)rates[i].spread);////its printing all 0's
    }

}
 
Tusher Ahmed:

this is what i was trying , out of curiosity.

CopyRates returns 100/ok , but the buffer is all 0's. 

Is the broker not exposing their historic rates info?

or i'm doing it wrong?

I have never actually seen that implemented by a broker. If you want bar spreads you can modify the rates struct as follows. Also, don't pass static arrays.  


struct MyRates : public MqlRates
{
   double Spread() { return this.high - this.low; }
};

void OnStart()
{
   MyRates r[];
   int copied = CopyRates(_Symbol, _Period, 0, 1, r);
   printf("%.5f -> %.5f",
      r[0].spread,
      r[0].Spread()
   );
}
 
nicholi shen: I have never actually seen that implemented by a broker. If you want bar spreads you can modify the rates struct as follows. Also, don't pass static arrays.
Perhaps you should read the manual.
  1. struct MqlRates
      {
       datetime time;         // Period start time
       double   open;         // Open price
       double   high;         // The highest price of the period
       double   low;          // The lowest price of the period
       double   close;        // Close price
       long     tick_volume;  // Tick volume
       int      spread;       // Spread
       long     real_volume;  // Trade volume
      };

              Constants, Enumerations and Structures / Data Structures / History Data Structure - Reference on algorithmic/automated trading language for MetaTrader 5
    Spread is not candle range, it's Ask - Bid. Supported on some symbols on some brokers. Never on MT4.

  2. When copying the yet unknown amount of data, it is recommended to use dynamic array as a target array, because if the requested data count is less (or more) than the length of the target array, function tries to reallocate the memory so that the requested data fit entirely.

    If you know the amount of data you need to copy, it should better be done to a statically allocated buffer, in order to prevent the allocation of excessive memory.


              Timeseries and Indicators Access / CopyRates - Reference on algorithmic/automated trading language for MetaTrader 5

 
whroeder1:
Perhaps you should read the manual.
  1. Spread is not candle range, it's Ask - Bid. Supported on some symbols on some brokers. Never on MT4.

"Spread" means different things depending on the context. In the context of a tick it's Ask - Bid, however, in the context of a candle it's high - low. If you had read the post you'd see that both OP and I are referring to "bar-spreads". It should have also been a dead-give-away since we are using rate structs and not tick structs. 

 
nicholi shen:

"Spread" means different things depending on the context. In the context of a tick it's Ask - Bid, however, in the context of a candle it's high - low. If you had read the post you'd see that both OP and I are referring to "bar-spreads". It should have also been a dead-give-away since we are using rate structs and not tick structs. 

sorry i too am not sure if there's anything as "bar spread". But you are right, there's no such thing as tick-struct either.

whroeder1:
  1. Spread is not candle range, it's Ask - Bid. Supported on some symbols on some brokers. Never on MT4.

yes admin, that's what i too assumed so far I've also chosen to use static buffer as per the doc. Any other clues as to why its not coming in?

 
Tusher Ahmed:

sorry i too am not sure if there's anything as "bar spread". But you are right, there's no such thing as tick-struct either.

yes admin, that's what i too assumed so far I've also chosen to use static buffer as per the doc. Any other clues as to why its not coming in?

There is such a thing as bar/candle-spreads. Haven't you ever heard anyone ask, "what's the daily spread on AAPL"?   

There are tick-structs.

MqlTick

Use MqlTick and CopyTicks to work with ticks and tick-spreads. 

Use MqlRates and CopyRates to work specifically with candles. 

"Spread" is just another way of saying "range", and given the context, why would it make sense to have a tick-spread for a candle that happened days ago? How would that even apply?
 
nicholi shen: "Spread" means different things depending on the context.

So here's context

Forum on trading, automated trading systems and testing trading strategies

MqlRates spread gives spread on pips ?

Azkron, 2018.02.14 10:54

I am an experienced programmer but I am new to FX trading.

When I check the .spread property in a MqlRates instance I always get whole numbers like 2 or 7, but then if for instance it is 7, does that mean that the spread is 7 pips ?


          MqlRates spread gives spread on pips ? - Pips - General - MQL5 programming forum
 
nicholi shen:

There is such a thing as bar/candle-spreads. Haven't you ever heard anyone ask, "what's the daily spread on AAPL"?   

There are tick-structs.

Use MqlTick and CopyTicks to work with ticks and tick-spreads. 

Use MqlRates and CopyRates to work specifically with candles. 

"Spread" is just another way of saying "range", and given the context, why would it make sense to have a tick-spread for a candle that happened days ago? How would that even apply?

Now that i've tried both MQlRates & MqlTicks, none worked.

Can you post code examples (pulling spreads from server) that you found to be working ?


Edit : Also my compiler doesn't seem to have mql4 function named CopyTicks (its for MT5 only)

 
Tusher Ahmed:

Now that i've tried both MQlRates & MqlTicks, none worked.

Can you post code examples (pulling spreads from server) that you found to be working ?


Edit : Also my compiler doesn't seem to have mql4 function named CopyTicks 

If you're using mql4 then you need to create a way to tracking the ticks yourself. One easy way is to wrap the TickStruct with a CObject subclass and then use a CList subclass as the collection interface. 


#include <Arrays\List.mqh>

class Tick : public CObject{
   double m_spread;
public: 
   MqlTick tick; 
   double spread(){ return m_spread; }
   void spread(double spread){ m_spread = spread; }
};
#define foreach_tick(LIST) for(Tick*tick=LIST.GetLastNode();CheckPointer(tick);tick=tick.Prev())

class TickList : public CList
{
public:
   void onTick(){ 
      Tick *tick = new Tick();
      SymbolInfoTick(_Symbol, tick.tick);
      tick.spread(tick.tick.ask - tick.tick.bid);
      this.Add(tick);
   }  
   double avg_spread(int num_ticks)
   {
      int cnt = 0;
      double cum_spreads = 0.;
      foreach_tick(this)
      {
         if(!CheckPointer(tick) || cnt >= num_ticks)
            break;
         cnt++;
         cum_spreads+= tick.spread();
      }
      return cum_spreads / cnt / _Point;
   }
};

TickList ticks;
void OnTick()
{
   ticks.onTick();
   
   printf("The avg spread for the last %d ticks is %.1f",
      ticks.Total() > 50 ? 50 : ticks.Total(),
      ticks.avg_spread(50)
   );
}
 
nicholi shen:

If you're using mql4 then you need to create a way to tracking the ticks yourself. One easy way is to wrap the TickStruct with a CObject subclass and then use a CList subclass as the collection interface. 


Are you sure its pulling historic-spreads from broker server?

SymbolInfoTick // it's for working with current prices of a specified symbol
 
Tusher Ahmed:

Are you sure its pulling historic-spreads from broker server?

No. That is not possible with mt4. 

Reason: