"expression is always false" is only a warning letting you know something could be wrong here. The compiler is making an assumption based on its own written rules. Doesn't mean it's bad code. What value is val? If it is 0, then at time of compile, yes the expression will always be false since Bid is always greater than 0.
There are several ways to make a sound play only once. Easiest would be to make the posFlag static. Another method would be to create a text Object and hide it. You could add description for the text Object, say for example "on" and "off". When sound is played, have code set Object to "on" and have code only allow sound play when description is "off". When sound is allowed to play again based on your rules, you have code reset Object to read "off".
These above are only couple ideas. You could also look into Global Variables or writing to a file. However reading from a text Object is easiest to code.
if(Bid<= val) posFlag=-1; //if(Bid<= val) you set posFlag=-1 if(Bid>= val) posFlag=1; if (Bid<= val && posFlag==1) //Then you check the same condition for Bid and val , posFlag CANNOT ==1 if (Bid>= val && posFlag==-1) //ditto

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
But I get error message /warning/ during compilation: "expression is always false" at this row of code:
And if position the trend line below the price and wait for cross, when the cross occurred the alerts are continuous, but if position the trendline above - just from the second I get continuous alerts. I only need one alert per cross.
This is the code:
I want to set the position of the trend line manually. And have a code to get the position of the price (above or below) based on the trend line.