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...
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~
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
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 ?
this way you don't find last trade
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
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
if your ea has to restart you have lost your global variable

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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...