You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
[E]ven tho[ugh] i would add an int variable=PositionsTotal() and reused this int for all those lines in OnTick; i do not see anymore optimising opportunities there. i woul also do same for ask and bid prices, however, this would only be out of habit, i do not think it would make the code run faster since these lines are not used at every tick -- correct?
The idea is that PositionsTotal() gets updated in the trading conditions in my code snippet's current form. A global int's value would remain unchanged until its PositionsTotal() definition is updated─causing erroneous orders to be sent. Again, you'll need to return the trade results or hackishly use Sleep(100) or so following each sent order. Just be aware that Sleep() is not compatible with the Tester─it can be enabled/disabled with a bool input.
Yes, the trading conditions blocks only run when they're true.
even tho i would add an int variable=PositionsTotal() and reused this int for all those lines in OnTick; i do not see anymore optimising opportunities there. i woul also do same for ask and bid prices, however, this would only be out of habit, i do not think it would make the code run faster since these lines are not used at every tick -- correct?
Even if you add else statements, that's still far from all you can do. Because the conditions for the if statements are, roughly speaking, the same. Why check the same thing multiple times?
The idea is that PositionsTotal() gets updated in the trading conditions in my code snippet's current form. A global int's value would remain unchanged until its PositionsTotal() definition is updated─causing erroneous orders to be sent. Again, you'll need to return the trade results or hackishly use Sleep(100) or so following each sent order. Just be aware that Sleep() is not compatible with the Tester─it can be controlled with a bool input.
Yes, the trading conditions blocks only run when they're true.
if it is used in Ontick, then, wont PositionsTotal be allowed to update the 1 time per each tick?
EDIT: But then again if this was so, then a loop that closes trades, if the loop is in ontick, then, couldnt work.
Even if you add else statements, that's still far from all you can do. Because the conditions for the if statements are, roughly speaking, the same. Why check the same thing multiple times?
yes, agreed, i just assumed that checking a single variable several times would be faster than requesting update of PositionsTotal several times.
But as you said, we have digressed from original topic, not that this is too far from it.
back to bed for me! 4am here! Thanks for every1s time and efforts.if it is used in Ontick, then, wont PositionsTotal be allowed to update the 1 time per each tick?
Why check the same thing multiple times?
What does PositionsTotal() affect? I haven't delved into the code, but I'm sure it can be checked once, not 10 times.
positionType can be checked once, not 10 times. Furthermore, it's best to avoid string comparisons when you can avoid it.
Why check the following a million times? Calculate 'initialOpenPrice - X * _Point' in advance and check it once.
EDIT: But then again if this was so, then a loop that closes trades, if the loop is in ontick, then, couldnt work.
You can write a loop to do whatever you like in OnTick() as long as you have the position ticket.
yeah i see that. been many years since coding for mt4, but still revert to mental think of using positions rather than ticket numbers for even simply closing all trades at once!
and that is why i created an int at start of Ontick for PositionsTotal, which i meant to use that int variable instead of updating PositionsTotal million times, but have not fully replaced all those PositionsTotal(s) with the int variable. will get around to replacing them on 1 day!
yeah i see that. been many years since coding for mt4, but still revert to mental think of using positions rather than ticket numbers for even simply closing all trades at once!
isnt the if line made redundant by the first loop? ie i>= 0
EDIT code below extracted from my file.