Obviously, just setting it will be more efficient.
Just to be clear. When I say more efficient programing, I don't mean less code. I 'm talking fastest running code. I kind of think they will be the same. It just seems wrong to set rrPrinted over and over again. Thanks for your reply! ---Tom
Yes, my answer was based on resource efficiency (less CPU usage).
Even if writing to RAM is somewhat slower that reading from RAM, it is done in the background, while the CPU continues to do its thing. So a Read Cycle or a Write cycle takes practically the same amount of time.
However, for your first option you are reading, then comparing. That will take more cycles then just writing it always and nothing else.
That being said, even a "write" can sometimes be one cycle to many, so see if you can rethink your overall logic to eliminate the need to set the variable in the first place.
Which is the most efficient programing? Reading and "if" statement every tick or just setting the bool variable every tick? Kind Regards ---Tom
Yes, my answer was based on resource efficiency (less CPU usage).
Even if writing to RAM is somewhat slower that reading from RAM, it is done in the background, while the CPU continues to do its thing. So a Read Cycle or a Write cycle takes practically the same amount of time.
However, for your first option you are reading, then comparing. That will take more cycles then just writing it always and nothing else.
That being said, even a "write" can sometimes be one cycle to many, so see if you can rethink your overall logic to eliminate the need to set the variable in the first place.
That makes sense. Thank you.
As far as rethinking the overall logic, I can't think of a better way to Print only the last RR a once trade has closed. Maybe you have some ideas?
Once in a trade (EAOpenTrades() > 0), CalculateRR() tracks (variable RR) the % gain/loss compared to the pips risked i.e. stoploss. A -0.5 means I am halfway to my SL. A +1.5 means I am in profit 1.5 times my risk. When trade is closed, I want to print the last RR.
Thanks again,
Tom
I'd go for initializing the variable inside the "if". There's nothing wrong in that, and you can see that very often whether it is initializing an int, string or whatever. Maybe the difference is insignificant, but it kind of feels very redundant and unnecessary asking every single time instead of just initializing the bool to false. Maybe it's just my coding style.
Regards.
We don't have access to your overall code logic or know and understand your objectives, so it would be difficult to offer other viable options.
Just keep the idea in your mind and as you progress with your development, you might come up with an alternative. For now, I don't think it will be that critical to just leave it as is.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Which is the most efficient programing? Reading and "if" statement every tick or just setting the bool variable every tick? Kind Regards ---Tom