Detecting a Spreadbetting account programatically

 

Hi guys,

Is there a way to detect if an account that an EA is running on is a spreadbetting account as opposed to an ordinary account? The difference lies in the designation of P/L calculations - Spreadbetting gives a different result to ordinary FX accounts since P/L is measured in terms of Stake per pip rather than Term Currency. I have EAs that get used on both types of accounts and so it is important they can calculate trade size differently depending on what type of account is being traded. Since Metaquotes enabled MT4 to be used on SB accounts you would think they would provide some function or contant to detect this such as accountType() or MODE_SPREADBET, but it appears not. Frankly I'm surprised the mql4 community isn't falling over themselves to find a solution. Has anyone had to face this issue or come up with a mathematical check that achieves the same goal?

Kind regards,

Sam

 
#define FOREX   0
bool Spreadbetting = (MarketInfo("EURUSD", MODE_PROFITCALCMODE) != FOREX);

Test on EURUSD as it is a FOREX symbol. If the MarketInfo for the Profit calculation mode does not yield 0 for FOREX then we assume Spreadbetting. You may have to add a suffix to the symbol name. I tested with www.gkfx.co.uk

 

Hi sxTED,

Thanks for this - not a bad idea! Presumably doing this doesn't positively identify the account as spreadbetting (it could still be CFD or Futures, neither of which I'm sure calculate P/L the same way as spreadbetting - probably not), but still good enough for what I have in mind I think. I'll be testing it on gkfx and Alpari UK Spreadbetting accounts.

Cheers,

Sam

 
Samlivingstone:

Hi sxTED,

Thanks for this - not a bad idea! Presumably doing this doesn't positively identify the account as spreadbetting (it could still be CFD or Futures, neither of which I'm sure calculate P/L the same way as spreadbetting - probably not), but still good enough for what I have in mind I think. I'll be testing it on gkfx and Alpari UK Spreadbetting accounts.

Cheers,

Sam

I'm doing essentially the same test on my Alpari UK accounts successfully. ( I don't use CFD or futures).

   if( MarketInfo(Symbol(),MODE_PROFITCALCMODE)==0 ){
      FOREX= true;
   }
   else{
      FOREX= false;
   }

Swapping between accounts is risky and has caught me out a coupling of times, costing me money :-(

The spread bet lot size is about 7 x smaller (for me) so I have set the lot size 7x too big on the non-SB account. Oopss!

And my indicator even says "SPREAD BET" on the screen, and I still screwed it up :-(

 

Just tried it on SB and regular forex accounts with Alpari and GKFX - works perfectly on both!

Sam

Reason: