Download MetaTrader 5
To add comments, please log in or register
Sign up to publish an article and receive 200 USD
Michael Sarikas
2992
Michael Sarikas 2014.08.28 03:59 

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
5533
Stuart Browne 2014.08.28 05:38  
You could always store the info in a multi dimension array and run a comparison by order ticket number?
Michael Sarikas
2992
Michael Sarikas 2014.08.28 06:13  
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
2385
Laszlo Tormasi 2014.08.28 07:54  
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
2992
Michael Sarikas 2014.08.28 09:11  
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
16461
Stanislav Korotky 2014.08.28 10:57  
Write a period into order comment, then parse the comments. This is the only way.
Michael Sarikas
2992
Michael Sarikas 2014.08.28 11:55  
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
28659
Alain Verleyen 2014.08.28 13:31  
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
28659
Alain Verleyen 2014.08.28 13:32  
marketeer:
Write a period into order comment, then parse the comments. This is the only way.
Of course, not.
Stanislav Korotky
16461
Stanislav Korotky 2014.08.28 15:17  
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
16461
Stanislav Korotky 2014.08.28 15:26  

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