need help identify last order

 

hello,

i'm writing a code for ea,

ea will open multiple orders buy n sell several times until close all profit.

'n i need to know how to code :

if last order op buy, then ea will not open buy until it op sell first

and vice versa

Could someone give me a help here ?

Thanks in advance...

 
zidan:

hello,

i'm writing a code for ea,

ea will open multiple orders buy n sell several times until close all profit.

'n i need to know how to code :

if last order op buy, then ea will not open buy until it op sell first

and vice versa

Could someone give me a help here ?

Thanks in advance...

can you show....
how you know what trades are open ??
 

You can use global variables to do that like below.

string Trend;

int init()
{
 if(...&&Trend!="Buy"){
  // buy opening system
  Trend="Buy";
 }

 if(...&&Trend!="Sell"){
  // sell opening system
  Trend="Sell";
 }

}

In the example we are using the global variable to save the last trend. Once buy opens the trend is saved as buy and same to sell. In the trade opening criteria we check and only open a buy when trend reads sell and after the ordersend() we now make trend a buy so next time only sell will open when the rest of the criteria in the if() is met.

~Tonny~

 
tonny:

You can use global variables to do that like below.

In the example we are using the global variable to save the last trend. Once buy opens the trend is saved as buy and same to sell. In the trade opening criteria we check and only open a buy when trend reads sell and after the ordersend() we now make trend a buy so next time only sell will open when the rest of the criteria in the if() is met.

~Tonny~


this way you don't find last trade
 
deVries:
can you show....
how you know what trades are open ??

1. at price 1.500, signal buy, ea order send buy 1 lot, take profit US$ 500

2. at price 1.900, signal buy, ea does’nt send order buy (Take profit has not reached yet)

3. at price 1.850 signal sell, ea order send sell 2 lot

4. at price 1.700 signal sell, ea does’nt send order sell (Take profit has not reached yet)

5. at price 1.600, signal buy, ea order send buy 3 lot

‘n then price goes up until take profit US$ 500 and close all orders at 1.750

Order no. 1 == TP US$ 250, Order no. 3 == SL US$ -200, Order no. 5 == TP US$ 450

EA does’nt send order no. 2 and no. 4, coz last order has the same direction.

Could you help me to show me the code ?

 
deVries:

this way you don't find last trade
But it will still achieve the goal of must not open same trade till after the opposite opened like alternating style.
 
zidan:

1. at price 1.500, signal buy, ea order send buy 1 lot, take profit US$ 500

2. at price 1.900, signal buy, ea does’nt send order buy (Take profit has not reached yet)

3. at price 1.850 signal sell, ea order send sell 2 lot

4. at price 1.700 signal sell, ea does’nt send order sell (Take profit has not reached yet)

5. at price 1.600, signal buy, ea order send buy 3 lot

‘n then price goes up until take profit US$ 500 and close all orders at 1.750

Order no. 1 == TP US$ 250, Order no. 3 == SL US$ -200, Order no. 5 == TP US$ 450

EA does’nt send order no. 2 and no. 4, coz last order has the same direction.

Could you help me to show me the code ?


Moving Average.mq4

You have it on your account

can you show....

how you know what trades are open ??

Use SRC button to display that part where you find what trades are open

 
tonny:
But it will still achieve the goal of must not open same trade till after the opposite opened like alternating style.

if your ea has to restart you have lost your global variable
 
deVries:

if your ea has to restart you have lost your global variable
That simple style but ocourse there are other more complex ways he can use like cycle history.
 
Or he can use GV that way will be still as simple an it wont be easily lost. Cycling orders last resort due to memory.
Reason: