How to find specific order in an EA?

 

Dear all,

Please help me on the following issue:

When my EA open an OP_BUY order, it will open an OP_SELL_LIMIT order at the same time. When the price reaches certain level, it will open an OP_SELL order to lock up the profit. When everything runs smoothly, it will close all three orders simultaneously at a time in future.

The problem is, there may be many groups like above one in the EA at the same time, therefore, I have no idea how to let EA close all three orders inside a specific group at the same time.

Does anyone have an idea how to do it? Please help!

Wing

 
You could append an additional digit or 2 or 3 to your Magic number to signify the group ID
 

Thanks RaptorUK.

On the other hand, how to write - if( "last digit of Magicnumber" == 0 )?

Wing

 

Simple . . .

if (MagicNumber - MagicNumberBase == 0)  do stuff . . 

MagicNumberBase is your current Magic Number without the addition of the extra digit(s) to signify the group ID

 
wing:

Dear all,

Please help me on the following issue:

When my EA open an OP_BUY order, it will open an OP_SELL_LIMIT order at the same time. When the price reaches certain level, it will open an OP_SELL order to lock up the profit. When everything runs smoothly, it will close all three orders simultaneously at a time in future.

The problem is, there may be many groups like above one in the EA at the same time, therefore, I have no idea how to let EA close all three orders inside a specific group at the same time.

Does anyone have an idea how to do it? Please help!

Wing

When it reaches that certain level, your OP_SELLLIMIT is triggered to an OP_SELL, only 2 opposite orders lock profit. so there are only 2 orders per group. Right? How come there's 3?
 

diostar,

order open price of OP_SELL_LIMIT is below OP_BUY and OP_SELL is over OP_BUY, so there is three orders.

Wing

RaptorUK,

I use 3rd digit as group number and last digit as order type number, e.g. 30100 is OP_BUY, 30101 is OP_SELL_LIMIT and 30102 is OP_SELL, another group is 30200, 30201 and 30202, etc.

So there is no MagicNumberBase and this method don't work for me.

Do you have any other idea?

Wing

 
wing:

diostar,

order open price of OP_SELL_LIMIT is below OP_BUY and OP_SELL is over OP_BUY, so there is three orders.

Wing


How could your sell_limit be below your OP_BUY?

"When my EA open an OP_BUY order, it will open an OP_SELL_LIMIT order at the same time."

Your sell_limit HAS to be above op_buy. No way, is this going to work in the first place....

 
wing:

RaptorUK,

I use 3rd digit as group number and last digit as order type number, e.g. 30100 is OP_BUY, 30101 is OP_SELL_LIMIT and 30102 is OP_SELL, another group is 30200, 30201 and 30202, etc.

Why ? OrderSelect() the use OrderType(), no need to keep the order type in the Magic Number.

It's possible to isolate any of the digits mathematically though . . if you really need to.

 

diostar,

Oh, sorry, I mixed them, it should be OP_SELL_STOP, not OP_SELL_LIMIT.

Wing

ReptorUK,

Oh yes, you are right, I get it!

So, just for interest, how to isolate the digits mathematically in MQL4?

Wing

 
wing:

So, just for interest, how to isolate the digits mathematically in MQL4?

Wing

OK, good. Imagine you want the 3rd digit from the left, take your Magic Number divide by 100, then do a %10 to get the remainder after dividing by 10, this remainder will be your 3rd digit . .

ThirdDigit = (MagicNumber/100)%10;
 
RaptorUK:

OK, good. Imagine you want the 3rd digit from the left, take your Magic Number divide by 100, then do a %10 to get the remainder after dividing by 10, this remainder will be your 3rd digit . .


Thank you so much! I get it!

Wing