Download MetaTrader 5

preventing same bot to be attached to same pair with different period or having OrderPeriod() saved

To add comments, please log in or register
Michael Sarikas
3795
Michael Sarikas  

Hi, I found that with mt4 if you have a bot and its attached say to AUDUSD on M15 is there any way in code to see if the same bot/version is attached on the same pair but different period?

For example: If I have 5 open charts m5, m15, m30, m60, m240, I can run my bot over all of them but because there could be different buy/sell signals for the different periods the bot opens a buy at m5 but m60 it sees a sell and the orders get cancelled out.

I don't want to have 5 magic numbers, is there a way in mql to have OrderPeriod() saved away with the current order? Then it would simply be a check:

if(Period()==OrderPeriod()) then yes this order is from bot instance that got executed originally on this chart, and can distinguish from other period orders, we need this feature.

Stuart Browne
6032
Stuart Browne  
You could always store the info in a multi dimension array and run a comparison by order ticket number?
Michael Sarikas
3795
Michael Sarikas  
Filter:
You could always store the info in a multi dimension array and run a comparison by order ticket number?

im not sure if that would work, i need something more like a runtime command to say IsEAattached() then I loop over the periods and if more than one i just uninitialize and it will keep only one running EA.

I'm building a Period hedge EA to have my bot run over the same pair but different periods and I want each EA instance to manage the pair & period orders not just the pair.

Laszlo Tormasi
2941
Laszlo Tormasi  
skeezwiz:

im not sure if that would work, i need something more like a runtime command to say IsEAattached() then I loop over the periods and if more than one i just uninitialize and it will keep only one running EA.

I'm building a Period hedge EA to have my bot run over the same pair but different periods and I want each EA instance to manage the pair & period orders not just the pair.

What is the problem with magicnumbers? You can use a number like Period()*x. This way don't need to change it every time.
Michael Sarikas
3795
Michael Sarikas  
lost89:
What is the problem with magicnumbers? You can use a number like Period()*x. This way don't need to change it every time.

there is no problem apart from the wrong name of the var :(

I thought we would have to setup 5 different numbers, but what you proposed is short and sweet and works, i used + instead of *

But an OrderPeriod() would be good, that way we can check back in the history whether our bot had more profits on 15m vs 240m etc...

Stanislav Korotky
19825
Stanislav Korotky  
Write a period into order comment, then parse the comments. This is the only way.
Michael Sarikas
3795
Michael Sarikas  
marketeer:
Write a period into order comment, then parse the comments. This is the only way.

that field is small in size and plus using it for specific messages.

What we need in the product is OrderOpenPeriod() and OrderClosePeriod() as inbuilt functions. 

Alain Verleyen
Moderator
31976
Alain Verleyen  
skeezwiz:

that field is small in size and plus using it for specific messages.

What we need in the product is OrderOpenPeriod() and OrderClosePeriod() as inbuilt functions. 

Don't wait such things. You have to manage these data inside your code.
Alain Verleyen
Moderator
31976
Alain Verleyen  
marketeer:
Write a period into order comment, then parse the comments. This is the only way.
Of course, not.
Stanislav Korotky
19825
Stanislav Korotky  
angevoyageur:
Of course, not.
Ok. The only alternative I can think of is a server-side custom backend which store order IDs and corresponding timeframes in a DB. But this looks like an overkill for the task. Do you suggest something else?
Stanislav Korotky
19825
Stanislav Korotky  

skeezwiz: 

As for the task itself, it's much more proper to handle open positions and new signals without any dependency from originating timeframe. If multiple instances of EA is running on different timeframes they can analyse direction of the current position (if any) and handle new signals from any timeframe appropriately (close position, add lots, etc).

BTW, the comment field is large enough to handle an additional symbol. Even if the comment is already used for other purposes it's not a problem to combine more info there and parse it if needed.

12
To add comments, please log in or register