Point == 0 not working

To add comments, please log in or register
J Webster
932
J Webster  

I have some indexes like the DAX and FTSE on my platform.

I am trying the following code, which works for other pairs where Point == 0.01, 0.00001 etc but not for the indexes:


if (Point==0.0){
ObjectSet("signal"+x+3,OBJPROP_XDISTANCE,x*scaleX+offsetX+30);
ObjectSetText("signal"+x+"3", DoubleToStr(MathRound(MathAbs(iHigh(Symbol(),PERIOD_D1,0)-iLow(Symbol(),PERIOD_D1,0))*0.1),0)+" out of "+
DoubleToStr(MathRound(iATR(Symbol(),PERIOD_D1,14,0)*0.1),0)+" pts",
8,"Tahoma",Black);
            if (Point==0.01){
               ObjectSet("signal"+x+3,OBJPROP_XDISTANCE,x*scaleX+offsetX+30);
               ObjectSetText("signal"+x+"3", DoubleToStr(MathRound(MathAbs(iHigh(Symbol(),PERIOD_D1,0)-iLow(Symbol(),PERIOD_D1,0))*10),0)+" out of "+
                                             DoubleToStr(MathRound(iATR(Symbol(),PERIOD_D1,14,0)*10),0)+" pts",
                                             8,"Tahoma",Black);
            }
            if (Point==0.1){
               ObjectSet("signal"+x+3,OBJPROP_XDISTANCE,x*scaleX+offsetX+30);
               ObjectSetText("signal"+x+"3", DoubleToStr(MathRound(MathAbs(iHigh(Symbol(),PERIOD_D1,0)-iLow(Symbol(),PERIOD_D1,0))*1),0)+" out of "+
                                             DoubleToStr(MathRound(iATR(Symbol(),PERIOD_D1,14,0)*1),0)+" pts",
                                             8,"Tahoma",Black);
            }
            if (Point==0.0){
               ObjectSet("signal"+x+3,OBJPROP_XDISTANCE,x*scaleX+offsetX+30);
               ObjectSetText("signal"+x+"3", DoubleToStr(MathRound(MathAbs(iHigh(Symbol(),PERIOD_D1,0)-iLow(Symbol(),PERIOD_D1,0))*0.1),0)+" out of "+
                                             DoubleToStr(MathRound(iATR(Symbol(),PERIOD_D1,14,0)*0.1),0)+" pts",
                                             8,"Tahoma",Black);
            }
Any ideas why?
bernd
989
bernd  
I doubt that Point would ever be 0, this could only happen if the broker has configured something completely wrong. A lot of people would complain because a lot of scripts and EAs would produce a lot of zero division errors, Point is simply not allowed to be 0.
J Webster
932
J Webster  
7bit:
I doubt that Point would ever be 0, this could only happen if the broker has configured something completely wrong. A lot of people would complain because a lot of scripts and EAs would produce a lot of zero division errors, Point is simply not allowed to be 0.

Well it is on the indexes. UK100 and GER30 the chart even just says 6079 and 7414


Is there another way around it? I guess I have t check for the symbol instead of Point?

bernd
989
bernd  
SanMiguel:

Well it is on the indexes. UK100 and GER30 the chart even just says 6079 and 7414

What about just printing Point to see how much it is? If there is no decimal then maybe Point == 1


Print(Point);


and will you know it exactly. Point is the smallest increment between two prices, so it cannot be 0.

bernd
989
bernd  
BTW, your code is extremely ugly:
            if (Point==0.01){
               ObjectSet("signal"+x+3,OBJPROP_XDISTANCE,x*scaleX+offsetX+30);
               ObjectSetText("signal"+x+"3", DoubleToStr(MathRound(MathAbs(iHigh(Symbol(),PERIOD_D1,0)-iLow(Symbol(),PERIOD_D1,0))*10),0)+" out of "+
                                             DoubleToStr(MathRound(iATR(Symbol(),PERIOD_D1,14,0)*10),0)+" pts",
                                             8,"Tahoma",Black);
            }
            if (Point==0.1){
               ObjectSet("signal"+x+3,OBJPROP_XDISTANCE,x*scaleX+offsetX+30);
               ObjectSetText("signal"+x+"3", DoubleToStr(MathRound(MathAbs(iHigh(Symbol(),PERIOD_D1,0)-iLow(Symbol(),PERIOD_D1,0))*1),0)+" out of "+
                                             DoubleToStr(MathRound(iATR(Symbol(),PERIOD_D1,14,0)*1),0)+" pts",
                                             8,"Tahoma",Black);
            }
            if (Point==1){ // 0.0 was wrong
               ObjectSet("signal"+x+3,OBJPROP_XDISTANCE,x*scaleX+offsetX+30);
               ObjectSetText("signal"+x+"3", DoubleToStr(MathRound(MathAbs(iHigh(Symbol(),PERIOD_D1,0)-iLow(Symbol(),PERIOD_D1,0))*0.1),0)+" out of "+
                                             DoubleToStr(MathRound(iATR(Symbol(),PERIOD_D1,14,0)*0.1),0)+" pts",
                                             8,"Tahoma",Black);

there is a lot of code duplication. Its three times the EXACT same code, only one variable changes.

There is no need for the if at all, you can just calculate the factor. There is a rule of thumb that goes like "the more 'if' in the code the worse it is". Avoid any 'if' whenever you can. For every 'if' in your code (especially such repeated if or if/else and also switch/case), ask yourself the question: "Can I get rid of it somehow or reduce it to less?". Of course there are many instances where this would not be reasonable or even possible but something like the above is definitely screaming for improvement.

How about something like this:

               ObjectSet("signal"+x+3,OBJPROP_XDISTANCE,x*scaleX+offsetX+30);
               ObjectSetText("signal"+x+"3", DoubleToStr(MathRound(MathAbs(iHigh(Symbol(),PERIOD_D1,0)-iLow(Symbol(),PERIOD_D1,0))*0.1/Point),0)+" out of "+
                                             DoubleToStr(MathRound(iATR(Symbol(),PERIOD_D1,14,0)*0.1/Point),0)+" pts",
                                             8,"Tahoma",Black);
[Deleted]  
SanMiguel:

Well it is on the indexes. UK100 and GER30 the chart even just says 6079 and 7414


Is there another way around it? I guess I have t check for the symbol instead of Point?


That's not point == 0, that's point == 1

What you are looking for is Digit == 0

To add comments, please log in or register