Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
I have an issue with some IF statements which are shown in my code below (I have taken out a lot of code that does not relate to the topic).
All code highlighted in purple works perfectly, both lastSignal & thisSignal strings are updated when required. My problem is after my // Set SAR swap. Neither statements will execute but not because the statements are incorrect - they are. they do not execute, as I have found through trail and error, because the lastSignal & thisSignal have not been "hard coded". If I alter these strings to "BUY" or "SELL" then they work without issue. I have also tried nesting the statements but that did not work either.
Thanks, Steve
You're setting your variables to " " on every tick.
Declare lastSignal and thisSignal up top on the global scope, set them to " " in OnInit(), and then update their values in OnTick() as and where needed.
You're setting your variables to " " on every tick.
Declare lastSignal and thisSignal up top on the global scope, set them to " " in OnInit(), and then update their values in OnTick() as and where needed.
Thanks for the input Ryan, but I want the variables to change on every tick.
You're welcome. As a best practice, I put as many variables as possible on the global scope. I don't go local unless I have a specific reason for doing so. You can still declare your variables up top, and then continue setting them to " " locally. This might give all of your conditions access to them.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have an issue with some IF statements which are shown in my code below (I have taken out a lot of code that does not relate to the topic).
All code highlighted in purple works perfectly, both lastSignal & thisSignal strings are updated when required. My problem is after my // Set SAR swap. Neither statements will execute but not because the statements are incorrect - they are. they do not execute, as I have found through trail and error, because the lastSignal & thisSignal have not been "hard coded". If I alter these strings to "BUY" or "SELL" then they work without issue. I have also tried nesting the statements but that did not work either.
Thanks, Steve