Think I've found my answer in the Experts log........
Problem must be in one of these calcs, just got to work out why it calcs fine when adding to a live chart but not on restart of MT4......
lotValue = Close[0]/tickSize * tickValue; Lev = 100/(lotValue/marginRequired);
- Check your variables before deviding.
Close[0]/tickSize * tickValue
is meaningless. There is no value per lot. A change in price * (tickValue / TickSize) is the change in equity per lot.- 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 = RISK = (OrderOpenPrice - OrderStopLoss)*DIR * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)
- 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
Ok, so testing shows marginRequired variable is the problem, therefore this is returning a zero value on start:
marginRequired = MarketInfo(Symbol(), MODE_MARGINREQUIRED);
It seems that for a few seconds on start up it is zero so indicator fails and then won't update itself to correct. Is there a way to fix this - could the initialising of indicator be delayed for a few seconds, or until an event such as first tick refresh of chart?
Simple if statement to test variables are > 0 did the trick - all working as it should now. Thanks

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
I have this simple indicator which just adds two objects to the chart to show the spread and margin for currency pair.
It is all fine when first added in (i.e. objects display correctly and are removed when indicator is removed), but when MT4 is restarted two things happen:
1) only one of the objects remains displayed correctly (spread) whilst the other (margin) now appears as grey text just saying "label".
2) also after restart, the two objects seem to have become orphaned, so removing the indicator does not remove the objects.
Any pointers for a novice to help me spot what I'm doing wrong would be greatly appreciated.
Thanks
Tim.