FXCM and the internal variable "Point".

NoTomatoes
40
NoTomatoes  

Had some weird risk excess today: A trade of an EA opened with a risk ten times as large as usual.

Turned out that FXCM gave 0.00001 for "Point" until March 06th and 0.0001 after that date.

Logging shows (right now):

2013.03.08 02:08:26    MyEA EURUSD,M1: Point      : 0.00010000

and before:

20:37:00 MyEA EURUSD,M1: Point      : 0.00001000

As the internal variable "Point" is a crucial part of the risk- and money management calculation, my positions were ten times as large as they would have normally been leading to a ten times as large loss - :-(

In the demo account of FXCM which runs in parallel to the real account I never observed such a behavior.

How does this happen?

How can I protect my EA from such misbehavior of internal variables of MT4?

NoTomatoes
40
NoTomatoes  

Things get pretty funny. Restarted the MT4 platform of FXCM to update the experts svn workspace.

And all of a sudden the variable Point is "0.00001" as it ever was.

Scratching my head... Did anyone else experience this once?

Simon Gniadkowski
17393
Simon Gniadkowski  
Brokers are not discussed on this Forum,  please discuss it with your Broker.
NoTomatoes
40
NoTomatoes  
RaptorUK:
Brokers are not discussed on this Forum,  please discuss it with your Broker.

Dear Raptor,

thank you very much for your reply by saying, that this is purely broker specific. This will help on my dispute. :-)

Personally I'm more to think of a rare bug in MT4 which shows up under some currently unknown circumstances. Much more I wanted to know why the content of the internal variable "Point" does change all of a sudden from 5 to 4 digits.

And what is even more important: Has anybody else seen such a behavior and what were the circumstances leading to that.

[Deleted]  
NoTomatoes: And what is even more important: Has anybody else seen such a behavior and what were the circumstances leading to that.

Yers, it doesn't look like a broker issue, probably another MT4 bug. For me this bug is reproducable with indicators only and only in init(), not in start(). Because I never watched it in EA's I didn't answer before, I can't offer help for this with EA's.

Of course it doesn't only happen with FXCM, it happens with every version/broker starting from build 225 where I experienced it the 1st time.

If the broker starts cheating you he will suddenly change the margin requirements for your open positions, only for a few seconds to stop you out for a loss. This indeed happens and you can only track the variables by yourself and log/alert any discrepancies. Manipulating the Point variable is to complicated because it requires you to run an EA that depends on Point.

[Deleted]  

I always have an indicator loaded to display different informations/states on the chart . If I overleverage and come close to stopout levels and suddenly the variables change, the signal lines on the chart start jumping.


NoTomatoes
40
NoTomatoes  
paulepanke:

Yers, it doesn't look like a broker issue, probably another MT4 bug. For me this bug is reproducable with indicators only and only in init(), not in start(). Because I never watched it in EA's I didn't answer before, I can't offer help for this with EA's.

And of course it doesn't only happen with FXCM, it happens with every version/broker starting from build 225 where I experienced it the 1st time.


Now that you mention it: I restarted MT4 on March 7th at 15:20 as my logs indicate - and on the initialization procedure of the riskmanagement I do some logging of the servers parameters which are crucial for lotsize calculation.

But then the EA uses the internal variable "Point" and not some saved value or some saved derived value of that when performing a lotsize calculation. The wrong value of "Point" even survived a removal and re-adding of the EA on the same chart.

In the logging mentioned above it's clearly to be seen that the content of "Point" is plain wrong - and stayed that way until I restarted the whole MT4 platform this morning.

15:21:32 MyEA EURUSD,M1: initRiskmanagement: Intializing Riskmanagement $Rev: 436 $
15:21:32 MyEA EURUSD,M1: Margin     : XXXXXXXXXXXXXXX
15:21:32 MyEA EURUSD,M1: Leverage   : 200.00000000
15:21:32 MyEA EURUSD,M1: LotSize    : 100000.00000000
15:21:32 MyEA EURUSD,M1: Minimum Lot: 0.01000000
15:21:32 MyEA EURUSD,M1: Lotstep    : 0.01000000
15:21:32 MyEA EURUSD,M1: Marginreq. : 500.00000000
15:21:32 MyEA EURUSD,M1: Point      : 0.00010000  <--- Here!

The code for initialization is a real no brainer:

/**
This function initialises the parameters neccessary for risk- and moneymanagement.
It has to be called once in the init procedure of the EA or when ever the leverage of the account changes.
It does not call the init procedure of the orderhist.mqh, though. This has to be done in 
the init() function of the EA as well.
*/
void risk.initRiskmanagement() {
	Print("initRiskmanagement: Intializing Riskmanagement $Rev: 436 $");
	// Initialize some globals which are not likely to change.
	risk.Leverage=AccountLeverage();
	risk.SymbolLotSize=MarketInfo(Symbol(), MODE_LOTSIZE);
	risk.SymbolMinLotSize=MarketInfo(Symbol(), MODE_MINLOT);
	risk.SymbolLotStep=MarketInfo(Symbol(), MODE_MINLOT);
	risk.SymbolMarginRequired=MarketInfo(Symbol(),MODE_MARGINREQUIRED);
	risk.SymbolMinStopLossPips=MarketInfo(Symbol(),MODE_STOPLEVEL);
	Print("Margin     : " + AccountFreeMargin());
	Print("Leverage   : " + risk.Leverage);
	Print("LotSize    : " + risk.SymbolLotSize);
	Print("Minimum Lot: " + risk.SymbolMinLotSize);
	Print("Lotstep    : " + risk.SymbolLotStep);
	Print("Marginreq. : " + risk.SymbolMarginRequired);
	Print("Point      : " + Point);
	//
}

And this is after restarting the MT4 platform this night:

03:07:26 MyEA EURUSD,M1: initRiskmanagement: Intializing Riskmanagement $Rev: 436 $
03:07:26 MyEA EURUSD,M1: Margin     : XXXXXXXXXXXXXXX
03:07:26 MyEA EURUSD,M1: Leverage   : 200.00000000
03:07:26 MyEA EURUSD,M1: LotSize    : 100000.00000000
03:07:26 MyEA EURUSD,M1: Minimum Lot: 0.01000000
03:07:26 MyEA EURUSD,M1: Lotstep    : 0.01000000
03:07:26 MyEA EURUSD,M1: Marginreq. : 500.00000000
03:07:26 MyEA EURUSD,M1: Point      : 0.00001000 <--- here!

Meanwhile I mitigated some of the pretty much unexpected technical operation risk by performing an "AccountFreeMarginCheck()" on the lotsize and the ordertype after calculating the risk.

[Deleted]  
Add Digits to your log. Whenever Point was set wrongly, Digits was so, too. It happens if a symbol is loaded in a new chart window, not in an old one. At MT4 restart all windows are new, too. For example, if no JPY chart is open (3 digits) but only a EURUSD chart (5 digits), the JPY variables Digits and Point in a new chart window (MarketWatch->New Chart) get populated in init() with the wrong EURUSD values. Later in start() they are correct.
[Deleted]  

I would recommend to move your risk.initRiskmanagement() function from init() to start().

init() might be called before the connection to the MT4 server is ready. start() definitely will "wait" for the first tick.

int start() {
   static bool risk.initDone = false;
   if (!risk.initDone) {
      risk.initRiskmanagement();
      risk.initDone = true;
   }
}
William Roeder
25075
William Roeder  
NoTomatoes:

Had some weird risk excess today: A trade of an EA opened with a risk ten times as large as usual.

Turned out that FXCM gave 0.00001 for "Point" until March 06th and 0.0001 after that date.

How does this happen?

How can I protect my EA from such misbehavior of internal variables of MT4?

Your code ASSSUMED a 5 digit broker. Have your EA auto adjust.

Either the broker changed, or you changed servers. Some brokers provide both.

[Deleted]  
WHRoeder:Your code ASSSUMED a 5 digit broker.
How do you see this?