# Order mangement

Good morning everyone. I’m making an ea in mql4, I’m currently working with 4 market operations. The first order enters buy or sell depending on the operational filters. The others are open pending orders at a certain distance. I have to enter another code after the last order opens and how can I do different activities based on whether the order is buy or sell? Thank you all

This is psuedo code, so not meant to compile but rather to give an idea:

if (TriggerLong == true)
{
LotSize = put your calculation here.
TP = CurrentPrice + TP_Points * Point;
SL = CurrentPrice - SL_Points * Point;
OrderSend( place buy trade at current price with TP, SL, LotSize etc)

// Second order away from price
LotSize = put your calculation here.
TP = CurrentPrice + ((SecondTrade + TP_Points) * Point);
SL = CurrentPrice - ((SecondTrade + SL_Points) * Point);

TriggerLong == false; // stop TriggerLong from going endlessly
}

it (TriggerShort == true)
{
LotSize = put your calculation here.
TP = CurrentPrice + TP_Points * Point;
SL = CurrentPrice - SL_Points * Point;
OrderSend( place buy trade at current price with TP, SL, LotSize etc)

// Second order away from price
LotSize = put your calculation here.
TP = CurrentPrice + ((SecondTrade + TP_Points) * Point);
SL = CurrentPrice - ((SecondTrade + SL_Points) * Point);

TriggerLong == false; // stop TriggerLong from going endlessly
}

Note: I just copied and pasted the TriggerLong into the TriggerShort. I didn’t take the time to fix the math to account for the opposite direction. Generally, I will do the Long side and get it to work and then copy it like above and do the math adjustments.
LotSize will likely be the same.
TP will change the plus to a minus
SL similar change
TriggerLong will be edited to be TriggerShort.

If you want to keep track of the mode you will be in until changed, you can add a Flag.

if (TriggerLong == true)
{

TriggerLongFlag = true;
TriggerShortFlag = false;
// here you are turning off the ShortFlag and engaging the LongFlag to let other code know that you are either in Long or short mode.
// if you are going to use this across different functions near the very top of your code put:
bool TriggerLongFlag = false;
bool TriggerShortFlag = false;
// set these to false so that it takes a trigger event to set the code into motion

// for variables you will just use here, like LotSize, you can do that inside this function.
// choose the very top of the code IF you are going to use the code all over different functions
// choose in a function if that is all you need

LotSize = put your calculation here.
TP = CurrentPrice + TP_Points * Point;
SL = CurrentPrice - SL_Points * Point;

I may not fully understand what you are doing, so adjust this to what you are actually doing.
If you get stuck, go to MQL5.com and look at the code for similar EAs and see if you can find something close to what you are doing and actual code that will compile.

I hope this helps.
Best wishes.

Thanks a lot. Today i Will try tour code.
Best wishes