is there average spread function, for mq4 ?

 

about spread :


in metatrader5 : its work , as below:

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     &TickVolume[],
                const long     &Volume[],
                const int      &Spread[])
{
.
 if (!ArrayGetAsSeries(High))  ArraySetAsSeries(High,true);
.
.
Comment(""
           ,"\n High[0]=",High[0]
           ,"\n Spread[0]=",Spread[rates_total-1]
           ,"\n Spread[1]=",Spread[rates_total-2]
           ,"\n Spread[2]=",Spread[rates_total-3]
.
.
.
          

and i have this :

///////////////////////////

but for metatrader4 : it does not work . see below;

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[])
  {
.

.
.
Comment("\n"
           ,"\n high[0]=",high[0]
           
           ,"\n Spread[0]=",spread[0]
           ,"\n Spread[1]=",spread[1]
           ,"\n Spread[2]=",spread[2]
           .
.
.
          );

the code doesn't have error/warning but in Experts  tab i have : " array out of range in 'PipValueCalculatorV1_02 2.mq4' (90,35) ".

////////////////

where is the problem ?

 
It seems that when OnCalculated was brought to 4 from 5, volume and spread were not included. Maybe because mql4 never had a Spread[] and not real Volume before. Volume[] returns tick volume.
 
Keith Watford:
It seems that when OnCalculated was brought to 4 from 5, volume and spread were not included. Maybe because mql4 never had a Spread[] and not real Volume before. Volume[] returns tick volume.

thank you to reply.

this is bad.

I need to know about this. my ea (mt4,mq4) run on 28 main forex currency pair. i must check spread as also as the other's . maybe i can a " guess " or see if the broker have some information about average of symbol spread.

for the first trade on each symbol , i checking if the spread is : spread<= spread_allow. ( for example 5 pip.)

but this is not enough if i want to have another enter levels. ( some of them maybe have 15 pip spread )

it must to have a sorted list according to spread.

.//

IS there a solution for it ?

 
Mehrdad Shiri:

thank you to reply.

this is bad.

I need to know about this. my ea (mt4,mq4) run on 28 main forex currency pair. i must check spread as also as the other's . maybe i can a " guess " or see if the broker have some information about average of symbol spread.

for the first trade on each symbol , i checking if the spread is : spread<= spread_allow. ( for example 5 pip.)

but this is not enough if i want to have another enter levels. ( some of them maybe have 15 pip spread )

it must to have a sorted list according to spread.

.//

IS there a solution for it ?

Sorry, I don't see any easy solution.

The only way that I can think of would be to build a file to gets details of spreads (Ask - Bid) in real time.

 
Keith Watford:

Sorry, I don't see any easy solution.

The only way that I can think of would be to build a file to gets details of spreads (Ask - Bid) in real time.

thank you.