324

Hi guys... I would like to ask if the formula that i used to compute the average of spread per tick is:

where:

Bid=Bid

Tick=value per tick or Tick Count

if you have another formula it would be a big help for me...

thank you very much

45

in my opinion, you can try to write this:

then you can caculate the average of spread per tick since the first tick count.

```// Global variable//--------------------------------------------------------------------

int Tick;
int sum;

//start//----------------

int start()
{
sum = (Ask + Bid) + sum;
Tick++;
double Average = 0;
Average = sum/Tick;
Print(Average);
return;
}```
Moderator
18058

raven_chrono:

Hi guys... I would like to ask if the formula that i used to compute the average of spread per tick is:

where:

Bid=Bid

Tick=value per tick or Tick Count

You can code a Spread MA
324

RaptorUK:
You can code a Spread MA

Can you show me some sample algorithm or pseudo code?

tnx...

Moderator
18058

raven_chrono:

Can you show me some sample algorithm or pseudo code?

I can do better than that . . . .

```// globally declared variables for function Spread()

extern int SpreadSampleSize = 100;  // number of ticks to average spread over  set to 0 to disable

//+-----------------------------------------------------+
//+-----------------------------------------------------+
{
double LastValue;
static double ArrayTotal=0;

{
ArrayTotal = ArrayTotal - LastValue;
}
//+--------------------------------------------------------+```

To use it simply call it at the start of the start() function and pass it the spread . . .

`Spread(Ask-Bid);`

Then when you want the averaged spread simply call the function with no parameter . . .

`Print("The averaged spread is ", Spread() );`
324

RaptorUK:

I can do better than that . . . .

To use it simply call it at the start of the start() function and pass it the spread . . .

Then when you want the averaged spread simply call the function with no parameter . . .

Thank you so much but one other thing... which is more reliable to use, the Ask-Bid or the MarketInfo(Symbol(),MODE_SPREAD)
Moderator
18058

raven_chrono:

Thank you so much but one other thing... which is more reliable to use, the Ask-Bid or the MarketInfo(Symbol(),MODE_SPREAD)
At the start of the start() function they are as reliable as each other.  Ask and Bid can become out of date if your start() function takes so long to run that it misses ticks,  this is not an issue at the start of the start function.
324

```double spread,average,sum;
int ticks;
int start()
{
while(IsStopped()==false)
{
while(RefreshRates()==false)
{

}
ticks++;
average=sum/ticks;

}

return(0);
}```
does this mean that the code that i created above is not reliable?
Moderator
18058

raven_chrono:
does this mean that the code that i created above is not reliable?
You aren't using any of the Predefined Variables so there is no need for RefreshRatws()  your code will work and will give an avreage not a moving average.
324

RaptorUK:
You aren't using any of the Predefined Variables so there is no need for RefreshRatws()  your code will work and will give an avreage not a moving average.

```double spread,average,sum;
int ticks;
int start()
{
while(IsStopped()==false)
{
while(RefreshRates()==false)
{

}
ticks++;
average=sum/ticks;

}

return(0);
}

Now i use the predefined variables Bid and Ask...
```
Moderator
18058

raven_chrono:
Now i use the predefined variables Bid and Ask...

But you still don't need to use RefreshRates(),  Bid and Ask are never going to be out of date in that code.