I have an EA trading on the Daily time frame, however, somedays - like today - it doesn't trade and I don't know why.
I tried to solve it by taking out the following part of the code:
//--- go trading only for first tiks of new bar
But it started to open new Stop Orders on each tick. How do I make sure it opens a stop order each day. I mean, that's the objective of the EA, to open Stop Orders each day according the the trend direction.
Thanks in advanced!
If you only want to open a new order when a new bar appears then it's best not to do it by volume. The volume is too unpredictable. And the way that code is written, if the first tick has a volume > 1 (which is possible) then it won't trade at all. If you remove that line completely then it will trade on every single tick (as you have discovered).It would be better to have either a static or a global variable that holds the time of the last bar, compares the time of bar 0 and if it's greater, then you're on a new bar. So something like:
You can to try this
OpenTicketNo=OrderSend( ......................... )
One option is to use the CIsNewBar class here and only trade when it returns true.
Hope it helps, good luck!
Thank you guys. I appreciate your feedback. I tried to code by the different methods you mentioned but I couldn't make it work properly, perhaps I didn't do something correctly.
However, I kept looking on the forums and I found the following code which worked fine on backtestings:
//-------------- define variable
//--------------- Check for open order conditions
if( now != Time )
now = Time;
//--- sell conditions
Now I'm about to test it in live demo trading, too bad it's Friday night already so I'll have to wait 'till the market opens on Monday. I'll try to share wether it works or not.
Hi everyone... just for the records, it is Friday again and my EA traded the whole week without a problem, this piece of code actually solved the problem:
now = Time;