Need help with adding MaxSpread condition

Post Reply
User avatar
ThaiGuy
Trader
Posts: 17
Joined: Mon Apr 29, 2013 6:33 am

Need help with adding MaxSpread condition

Post by ThaiGuy »

I'm testing this EA I found somewhere, and would love to use (test) it for metals and indices, however... for example Gold (xauusd) sometimes have spreads of 25 pips and sometimes even above 60 pips.

So I was wondering how I can have a filter added to this EA for only open any trade when the current spread is for example $MaxSpread=30.

A modified code will be nice, however.. I also would like to learn from it, so if someone can also provide me with an explanation I would be really happy :)

[code]
/
[/code]

Cheers,
[i][size=100]TG[/size][/i]

[b]PS. Code is free to use, it did not contain any copyrights or anything, and was available for free, just forgot where I got it from lol :)[/b]
Last edited by ThaiGuy on Sat Sep 20, 2014 3:32 am, edited 1 time in total.
Radar
Trader
Posts: 437
Joined: Fri Mar 23, 2012 5:39 pm
Location: Round the bend ;)

Re: Need help with adding MaxSpread condition

Post by Radar »

Hey ThaiGuy,

Just add "extern double MaxSpread = 0.003" (without the quotes) for 30 pips, and change this...

Code: Select all

if (cA > 0) if (OrderSend(symb, OP_BUY, Lot(), ND(Ask), Slippage, 0, 0, Comm, Magic, 0, Blue) != -1) cA = 0;
if (cA < 0) if (OrderSend(symb, OP_SELL, Lot(), ND(Bid), Slippage, 0, 0, Comm, Magic, 0, Red) != -1) cA = 0;
to this...

Code: Select all

if (Ask - Bid <= MaxSpread)
{
if (cA > 0) if (OrderSend(symb, OP_BUY, Lot(), ND(Ask), Slippage, 0, 0, Comm, Magic, 0, Blue) != -1) cA = 0;
if (cA < 0) if (OrderSend(symb, OP_SELL, Lot(), ND(Bid), Slippage, 0, 0, Comm, Magic, 0, Red) != -1) cA = 0;
}
Have fun!

Radar =8^)
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
User avatar
ThaiGuy
Trader
Posts: 17
Joined: Mon Apr 29, 2013 6:33 am

Re: Need help with adding MaxSpread condition

Post by ThaiGuy »

thanks for your quick reply and sorry for my late response lol :)
Post Reply

Return to “Coders Hangout”