Download MetaTrader 5
To add comments, please log in or register
Find out how social trading can improve your profits
jasinali
19
jasinali 2014.07.27 12:09 

Hello! I'm having struggles with my EA. 

Right now, it runs the code each tick, not every bar. With doing so, I get ALOT of orders in the same place, effectivly draining my account balance in the backtesting.

Here is a picture for demonstration.

 

 As you can see in the picture above, it opens up multiple sell and buy positions, where i really just want one.

 The problem was solved previously by just running the code each bar, but in doing so, I got in the positions one bar late and out of the positions one bar late.

Which is a big problem when I use the daily graphs, which my program is made for.

 

How would you solve this matter?

Sorry if this post was badly made, it's my first one.

Ask me for more info if needed!

 

Thank you for reading! 

Keith Watford
Moderator
8027
Keith Watford 2014.07.27 13:11  

Make sure that you use an individual magic number for the EA orders.

Loop through the open orders and check if there is already a trade open with the magic number.

Only open a new trade if one does not exist already. 

whroeder1
13656
whroeder1 2014.07.27 13:19  
Jalex: How would you solve this matter?
  1. Once per bar
  2. Test if an order is already open
  3. Test last open datetime
jasinali
19
jasinali 2014.07.27 14:02  

I don't know if I am missunderstanding what you two are saying, but I am already looking to see if an order is open. 
But the problem is that it opens an order, then closes it and then opens another one. 

I'm guessing it's because the signal crosses the macd line multiple times in the same bar sometimes.

Do you think I might be right in this? And is it a feesable solution to just put the program on hold for one bar after each order? 

Amir Yacoby
1128
Amir Yacoby 2014.07.27 19:22  
Jalex:

I don't know if I am missunderstanding what you two are saying, but I am already looking to see if an order is open. 
But the problem is that it opens an order, then closes it and then opens another one. 

I'm guessing it's because the signal crosses the macd line multiple times in the same bar sometimes.

Do you think I might be right in this? And is it a feesable solution to just put the program on hold for one bar after each order? 


If your close condition is working per-tick, it can be. One thing you can do is change your close order condition to work per bar as well.
jasinali
19
jasinali 2014.07.27 20:26  
amir_avatar:

If your close condition is working per-tick, it can be. One thing you can do is change your close order condition to work per bar as well.
But then I am back to exiting my positions up to one bar too late. Which plays a huge role when using the daily period graphs. Am I even right in this? Thank you for all the replies by the way.
Amir Yacoby
1128
Amir Yacoby 2014.07.27 21:41  

it depends on your signals. 

If your strategy demands closing as soon as the signal comes even without bar close, then the midway is to open deal only on the bar after the closed deal.
This demands that you check the closing time.
Right now you have open and close many times inside a bar, so obviously something with the strategy is not working right.
You should revise if and when you can count on the signal, obviously if you get many opposite signals within a short time, then something is wrong, even if you filter them at the end with new bar. 

jasinali
19
jasinali 2014.07.28 06:22  

The code concerning the signals is right, I'm sure. And I also do realize why they give me mixed signals, it should. 

The question, though, is how to deal with it? 

Is there some way to set a time limit the program must hold the order for? For example, the order must be held atleast one bar? 

Amir Yacoby
1128
Amir Yacoby 2014.07.28 11:14  

I believe your question has already been answered by me and others. You can set the close condition on the next bar only and not on the bar where the deal was opened.

I also suggested that but you said:
"But then I am back to exiting my positions up to one bar too late. Which plays a huge role when using the daily period graphs. Am I even right in this? Thank you for all the replies by the way." 

So, you need to set your mind as to what you want, you cant hold the rope on both sides. 

jasinali
19
jasinali 2014.07.28 13:17  
amir_avatar:

I believe your question has already been answered by me and others. You can set the close condition on the next bar only and not on the bar where the deal was opened.

I also suggested that but you said:
"But then I am back to exiting my positions up to one bar too late. Which plays a huge role when using the daily period graphs. Am I even right in this? Thank you for all the replies by the way." 

So, you need to set your mind as to what you want, you cant hold the rope on both sides. 

OK, I nos understand what you're saying. Thank you.
/
To add comments, please log in or register