Max spread in points

 

There are a number of topics on this forum about checking for the current spread before placing an order. However each of them says something different, and as my brain is over loaded today I can't set my mind on a good solution. Can somebody confirm that the following is a correct way? That will probably be helpful for others as well. I put parts of the EA code to stay short and clear.

Obviously, I'd want to attach this EA on any chart, 3 or 5 digits fx markets including USDJPY etc, plus UK100GBP etc.


// global variables

extern int maxSpread = 5; // in number of pips

double vPoint;

...

// beginning of start function

Print ("Digits=",Digits);

if (Digits % 2 == 1){       // DE30=1/JPY=3/EURUSD=5

       vPoint=Point*10; vSlippage=Slippage*10;

} else {

       vPoint=Point; vSlippage=Slippage;
}

// EA decisions

... If there is a decision to enter the market, then sets either OpenBuy or OpenSell to true

// Order placement

double spread = Ask-Bid ;

if (OpenBuy) {

if (spread <= maxSpread * vPoint) {

// create Buy order

} else {

Print ("Buy Order not placed as spread too high (", spread, " > ", maxSpread * vPoint, ")")

}

}

if (OpenSell) {

if (spread <= maxSpread * vPoint) {

// create Sell order

} else {

Print ("Sell Order not placed as spread too high (", spread, " > ", maxSpread * vPoint, ")")

}

}

Would it correct and therefore reusable?

Thanks in advance!

 

Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

 
Thanks Ange, I hadn't notice this function. It's true that the forum participants have a better look at the question now...
 
It does not look very reliable. What i do is to rely on "EURUSD" symbol and check its Digits. If Digits are 4 then you dont need to *10 for all other pairs. I assume if EURUSD is 5 digits then all other pairs are also micro biased. This was working til now without any problems.