You have to check that there is enough free margin to trade your selected volume before sending an order.
Read the documentation, please.
https://docs.mql4.com/account/accountfreemargincheck
Regards.
- docs.mql4.com
You have to check that there is enough free margin to trade your selected volume before sending an order.
Read the documentation, please.
https://docs.mql4.com/account/accountfreemargincheck
Regards.
ok thanks :) working code:
OrderSend(Symbol(),OP_SELL,0.01, Bid,10,0,0,"My order",16384,0,clrGreen);
}
Jose Francisco Casado Fernandez: You have to check that there is enough free margin to trade your selected volume before sending an order.
| Which is sufficient to open but not prevent stop out.
|
Hi,
I have some strange issue while using backtester.
Here is some code sample:
{
return(NormalizeDouble(val, Digits));
}
void OnTick()
{
double price=Ask;
double minstoplevel = MarketInfo(Symbol(),MODE_STOPLEVEL)+10;
double stoploss=ND(Ask+minstoplevel*Point);
double takeprofit=ND(Ask-minstoplevel*3*Point);
OrderSend(Symbol(),OP_SELL,0.01, Bid,10,0,0,"My order",16384,0,clrGreen);
}
when I add this strategy to market, on each tick new order is coming.
But while running backtests I have errors:
2017.01.20 11:02:16.863 2016.08.30 23:59 Tester: PrevBalance: 10000.00, PrevPL: 28.50, PrevEquity 10028.50, PrevMargin: 10057.91, NewMargin: 11142, FreeMargin: -1113.60
2017.01.20 11:02:16.863 2016.08.30 23:59 Tester: not enough money for sell 0.01 EURUSD at 1.11412 sl: 0.00000 tp: 0.00000 [2016.08.30 23:59]
can anyone tell me why is that ?
Thanks !
I would say you need to add more logic to your ordering.
Here is what I do to keep from getting killed by Margin Calls:
double EQTY = AccountInfoDouble(ACCOUNT_EQUITY);
double MarginCheck = (MarginFree/EQTY);
if(SomeOrderRule && MarginCheck > 0.30) { //Make sure you have more than 30% margin left before ordering (This can be adjusted depending on your comfort level)
if(OrderCount < 6)
OrderSend(Symbol(),OP_BUY,.10,Ask,3,0,Ask+.025,NULL,NULL,0,clrTeal); }
| Which is sufficient to open but not prevent stop out. |
You can't ever prevent a StopOut.
- 1. Your formula "DeltaPerLot" is variable (TickValue is variable, it changes with the prices movements). Therefore even if you calculate it at the moment of your entry, it doesn't assure that you are save from a StopOut later.
- 2. You also may open other positions later (manual or with other EA's) which would affect your Margin.
- 3. You also may change your Stop Loss later, or not to use a Stop Loss, and close your position with anyother rule (an opposite signal, for example).
- 4. There may be a price gap that causes your Stop Loss not to trigger where you placed it.
It is why I consider it is useless to calculate that at the moment of your entry if your aim is only prevent a StopOut. I think that's only useful if your aim is to get a ROUGH IDEA of what you can lose in that trade, but it will not prevent a Stop Out.
Regards
Here is what I do to keep from getting killed by Margin Calls:
double EQTY = AccountInfoDouble(ACCOUNT_EQUITY);
double MarginCheck = (MarginFree/EQTY);
if(SomeOrderRule && MarginCheck > 0.30) { //Make sure you have more than 30% margin left before ordering (This can be adjusted depending on your comfort level)
if(OrderCount < 6)
OrderSend(Symbol(),OP_BUY,.10,Ask,3,0,Ask+.025,NULL,NULL,0,clrTeal); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I have some strange issue while using backtester.
Here is some code sample:
{
return(NormalizeDouble(val, Digits));
}
void OnTick()
{
double price=Ask;
double minstoplevel = MarketInfo(Symbol(),MODE_STOPLEVEL)+10;
double stoploss=ND(Ask+minstoplevel*Point);
double takeprofit=ND(Ask-minstoplevel*3*Point);
OrderSend(Symbol(),OP_SELL,0.01, Bid,10,0,0,"My order",16384,0,clrGreen);
}
when I add this strategy to market, on each tick new order is coming.
But while running backtests I have errors:
2017.01.20 11:02:16.863 2016.08.30 23:59 Tester: PrevBalance: 10000.00, PrevPL: 28.50, PrevEquity 10028.50, PrevMargin: 10057.91, NewMargin: 11142, FreeMargin: -1113.60
2017.01.20 11:02:16.863 2016.08.30 23:59 Tester: not enough money for sell 0.01 EURUSD at 1.11412 sl: 0.00000 tp: 0.00000 [2016.08.30 23:59]
can anyone tell me why is that ?
Thanks !