first you cant use "exp" for an int it's reserved
second you express the "SL"
SL = MathFloor((iATR(NULL, PERIOD_D1, 7, 0)*MathPow(10,Digits-exp)+1)*0.1);
in the init section, bad idea
because if you get Error 4066 the "SL" = 0
then you get zero divide on "lots"
lots=MoneyRisk/SL/(MarketInfo(Symbol(), MODE_TICKVALUE)*multi);
and the indicator stops and you have to reload the indicator
obviously you can't avoid the update ;-) but you have to avoid a situation of "zero divide"
so you have to check if one of the variables equals to 0.... in case avoid zero divide
and because you can not stop an indicator you have to figure out something
example:
SL = MathFloor((iATR(NULL, PERIOD_D1, 7, 0)*MathPow(10,Digits-exp)+1)*0.1); if (SL == 0) // because error 4066 (for example) { SL = Someting; } lots=MoneyRisk/SL/(MarketInfo(Symbol(), MODE_TICKVALUE)*multi);
You are right.. I can't avoid it. :-)
What I meant is, can I wait until the update is completed before going on with the SL-calculation? The problem is that I can't give SL a random value because then the whole indicator is useless. So I would like to check for error 4066 and if it occurs, I would like to wait somehow and check again before going on.
By the way, I have the same problem with this indicator. But why wasn't it a problem in the "old" MetaTrader? Here I always receive a zero for the ATR(5). WHY?!?! That never happened before.. I hate this new MetaTrader...!
int start() //---- { double Spread = MarketInfo(Symbol(), MODE_SPREAD); double ATR = iATR(NULL, PERIOD_D1, 5, 0); int exp1 = 0; if (Digits==5 || Digits==3) { Spread=Spread*0.1; exp1 = 1; } Comment ( "ADR(5): ",DoubleToStr(ATR*MathPow(10,Digits-exp1),1), " || TODAY: ",(iHigh(NULL, PERIOD_D1, 0)-iLow(NULL, PERIOD_D1, 0))*MathPow(10,Digits-exp1), " || ", DoubleToStr(((iHigh(NULL, PERIOD_D1, 0)-iLow(NULL, PERIOD_D1, 0))*MathPow(10,Digits-exp1)/(ATR*MathPow(10,Digits-exp1))*100), 2), "%", "\n" + "SPREAD: ", Spread, " || RATIO: ",DoubleToStr((Spread/ATR)*MathPow(10,-(Digits-exp1-2)), 2),"%" ); //---- return(0); }
I think I found the problem! It is definitely an updating problem. When I now change currencies, the indicator works. But then I opened a currency-pair I had not open yet today. Then I got this message:
You have to put something like
if(number==0)dothis; else dothis;
in ShowSpread.mq4
Just search the line where this zero divide occurs.
I think I found the problem! It is definitely an updating problem. When I now change currencies, the indicator works. But then I opened a currency-pair I had not open yet today. Then I got this message:
angevoyageur, I think you did not see this posting from me:
You are right.. I can't avoid it. :-)
"What I meant is, can I wait until the update is completed before going on with the SL-calculation? The problem is that I can't give SL a random value because then the whole indicator is useless. So I would like to check for error 4066 and if it occurs, I would like to wait somehow and check again before going on."
There you can see that described that I can't follow the advice and because I came to that solution you can also see that I definitely checked what qjol advised me.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey coders,
I made a small Moneymanagement indicator which worked fine for me. But since the new MQL4 it causes problems I can't handle.
When you drag this indicator to your chart some numbers are printed on the very right side. The first number means the Stoploss in pips and the second is the lot-size. In the options you can choose the risk. The other number are the Stoploss Levels. But when I change the currency pair the numbers are gone. Instead I see several times the word "Label". And when I look to the indicator-list, my indicator is also gone. So, in summary, after changing the currency pair, the indicator is gone and left Labels instead of numbers.
I am totallly confused. This indicator used to work without any problem. Help is very appreciated.
Here is the code: