Spread Check - using a switch

 

Hi

 

I would like to add a Max Spread check function, and have the various ccypairs already set with the tolerance, so that I can just drop the EA on whatever pair and not worry about remembering to set it.

 

I tried to create a switch that would return either true or false that i can then just use in my order placement criteria, but I am not sure that I have done this correctly as MaxSpread keeps coming back as false.

In the example below AUDUSD is currently 16, which is less than 30 so I expected it to return true.

What did I do wrong? Or is there a better way to do this?

 

thanks

Simon 

 

bool MaxSpread;  



//Spread Check - to make sure the spread has not widened to far.
int CcyPair = 0;
if (Symbol() =="AUDUSD") CcyPair = 1;
if (Symbol() =="GBPUSD") CcyPair = 2;
if (Symbol() =="EURUSD") CcyPair = 3;
if (Symbol() =="USDCAD") CcyPair = 4;

switch (MaxSpread)
{
case 1: MaxSpread = MarketInfo(Symbol(),MODE_SPREAD) < 30; break;
case 2: MaxSpread = MarketInfo(Symbol(),MODE_SPREAD)< 50; break;

}
 
simoncs:

Hi

 

I would like to add a Max Spread check function, and have the various ccypairs already set with the tolerance, so that I can just drop the EA on whatever pair and not worry about remembering to set it.

 

I tried to create a switch that would return either true or false that i can then just use in my order placement criteria, but I am not sure that I have done this correctly as MaxSpread keeps coming back as false.

In the example below AUDUSD is currently 16, which is less than 30 so I expected it to return true.

What did I do wrong? Or is there a better way to do this?

switch(bool)  ??

switch (CcyPair)
 
bool converts to an int
bool MaxSpread;                                                    <-- defaults to zero/false

// irrevalent //Spread Check - to make sure the spread has not widened to far.
// irrevalent int CcyPair = 0;
// irrevalent if (Symbol() =="AUDUSD") CcyPair = 1;
// irrevalent if (Symbol() =="GBPUSD") CcyPair = 2;
// irrevalent if (Symbol() =="EURUSD") CcyPair = 3;
// irrevalent if (Symbol() =="USDCAD") CcyPair = 4;

switch (MaxSpread)                                                 <-- switch(0) no case matches switch exits
{
// irrevalent case 1: MaxSpread = MarketInfo(Symbol(),MODE_SPREAD) < 30; break;
// irrevalent case 2: MaxSpread = MarketInfo(Symbol(),MODE_SPREAD)< 50; break;
}
 
simoncs:

Hi

 

I would like to add a Max Spread check function, and have the various ccypairs already set with the tolerance, so that I can just drop the EA on whatever pair and not worry about remembering to set it.

 

I tried to create a switch that would return either true or false that i can then just use in my order placement criteria, but I am not sure that I have done this correctly as MaxSpread keeps coming back as false.

In the example below AUDUSD is currently 16, which is less than 30 so I expected it to return true.

What did I do wrong? Or is there a better way to do this?

 

thanks

Simon 

 

 


extern   double MaxSpreadPips           = 4.5; 

double SymSpread;

//----------------------------------------------------------------------------------------------------------
int start()
//----------------------------------------------------------------------------------------------------------
   {
   if(Digits==3){SymSpread=(Ask-Bid)*100;}
   if(Digits==5){SymSpread=(Ask-Bid)*10000;}
   }
//----------------------------------------------------------------------------------------------------------
int OpenOrders(int Direction) //
//----------------------------------------------------------------------------------------------------------
   {
   if(SymSpread>MaxSpreadPips){Print("MaxSpreadPips Triggered"); return(0);}
   }

This is just one currency, do you mean to monitor multiple currencies from one chart? like EURUSD?

 
Subgenius:


This is just one currency, do you mean to monitor multiple currencies from one chart? like EURUSD?



Thanks - that's pretty much what I was going to do originally. But then I thought I could have a list of currencies and the max spreads for each, that would be checked. that way I wouldn't need to amend the etern variable each time. I am now thinking the external check is probably the most sensible, but I still want to work out how to do the  switch method, just to increase my coding skills.
 
simoncs:

Thanks - that's pretty much what I was going to do originally. But then I thought I could have a list of currencies and the max spreads for each, that would be checked. that way I wouldn't need to amend the etern variable each time. I am now thinking the external check is probably the most sensible, but I still want to work out how to do the  switch method, just to increase my coding skills.
Read all the posts not just the last one . . .
 
simoncs:

Thanks - that's pretty much what I was going to do originally. But then I thought I could have a list of currencies and the max spreads for each, that would be checked. that way I wouldn't need to amend the etern variable each time. I am now thinking the external check is probably the most sensible, but I still want to work out how to do the  switch method, just to increase my coding skills.


Your currency switch may be useful to use the right MaxSpread depending on the Symbol?

 
RaptorUK:
Read all the posts not just the last one . . .


thanks - I will come back to this - just need to fix another issue first so that I can start running some tests.
Reason: