- Use the debugger or print out your variables, including _LastError
and
find out why. We have no idea what One_Lot is.
- Don't use MarketInfo in OnInit. The terminal may not yet be connected to the broker.
-
Risk depends on your initial stop loss and lot size.
- 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.
- Account Balance * 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
- You must normalize lots properly and check against min and max.
- You must also check FreeMargin to avoid stop out
Check that in the division the result is 0, because if it is 0 you will have the zero divide error. Try to see if this Tipic can be useful to you.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Symb = Symbol(); RefreshRates(); // Refresh rates Min_Lot=MarketInfo(Symb,MODE_MINLOT); // Minimal number of lots Free =AccountFreeMargin(); // Free margin One_Lot=MarketInfo(Symb,MODE_MARGINREQUIRED);// Price of 1 lot Step =MarketInfo(Symb,MODE_LOTSTEP); // Step is changed Step = 1; Print(Step); if (Lots < 0) // If lots are set, Lts =Lots; // work with them else // % of free margin Lts=MathFloor(Free*Prots/One_Lot/Step)*Step;// For opening
Why am I getting zero divide in the above code please? I believe is the Step.
This is the example code that I download from https://book.mql4.com/samples/expert , as I am self learning MQL4 language.
I have attached my mq4 file, this is modified on tradingexpert.mq4 from the tutorial page above.
Many thanks