- Add print statements dumping your variables before and in IF statements and find out why?
- Name your variables carefully. Order_time is not a datetime, the name is misleading.
- IF the last order was opened at 2300 what happens next?
if(order_time ==0 || TimeHour(TimeCurrent()) >= order_time + x 0..23 >= 23 + x Will this ever be true again?
How aboutdatetime order_time; // Common variables (global) are always static. int start(){ if(timeCurrent() > order_Time + x * 3600) .. : order_time = TimeCurrent(); // or Time[0]
Thanks for the response.
I don't think adding print statements will help because I am back testing the EA using the strategy tester.
I've changed order_time to datetime type and the time check conditions but it still won't execute a trade. It should execute at least once because order_time == 0 is true for the time around.
Also if I comment out the reassignment of order_time in the second if statement, it works properly.
Oh I just realized that print statements will print onto the journal tab. Didn't know that before. This should make debugging this much easier.
Thanks!
EDIT: Figured out that the order_time variable was reassigned even when the ordersend() function returned an error and did not actually send a trade. Quick fix and now it works

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
I am working on an EA that only trades once per bar.
I am using time to check if the current bar is at least x hours ahead of the previous bar. However it does not execute a trade on backtests, but it does when I remove the time check conditions.
Here's the pseudocode:
Any hints would be appreciated, thanks!