- Use a mutex to compute lot size through open.
Prevent EA from opening trades at the same time across two or more pairs? (Steve) - MQL4 and MetaTrader 4 - MQL4 programming forum - If you are worried about margin and leverage, you are not controlling your risk.
Never risk more than a small percentage of your account, certainly less than 2%
per trade, 6%
total.
In code (MT4):
Risk depends on your initial stop loss, lot size, and the value of the pair.
- You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
- AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
-
Do NOT use TickValue by itself - DeltaPerLot and verify that
MODE_TICKVALUE is returning a value in your deposit currency, as promised
by the documentation, or whether it is returning a value in the instrument's
base currency.
MODE_TICKVALUE is not reliable on non-fx instruments with many brokers. - You must normalize lots properly and check against min and max.
- You must also check FreeMargin to avoid stop out
Hi,
I want to check my free margin before I open a position. However my EA opens positions at the same time (when markets open).
Now I am afraid, that if my EA on different charts checks free margin at the same time, they will all get returned the same free margin for each chart (because all positions will probably open at the same time).
Has anyone dealt with something like this before?