One trade per order....

 

Hi Guys,

How can i amend an EA so that it trades only 1 times and once that trade is close i.e take profit is hit then dont trade again until the next opposite trade...let me explain it in detail....If the long trade has hit its TP then wait for the short trade and do not place any further trades...but at the moment my EA opens another buy trade...

Thanks

Babar

 

you will notice near the top, one of the phrases is if(OrdersTotal() < 1), and the function thereafter. that is how you regulate only one trade at a time.

//Buy

if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

IsTrade = False;//---allows multiple orders to open

if(!IsTrade) {

if (StopLossMode) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;

if (TakeProfitMode) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

if(OrdersTotal() < 1)

Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);

if(Ticket > 0) {

if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {

Print("BUY order opened : ", OrderOpenPrice());

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");

} else {

Print("Error opening BUY order : ", GetLastError());

}

}

if (EachTickMode) TickCheck = True;

if (!EachTickMode) BarCount = Bars;

return(0);

}

}

 
Eaglehawk:
you will notice near the top, one of the phrases is if(OrdersTotal() < 1), and the function thereafter. that is how you regulate only one trade at a time.
//Buy

if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

IsTrade = False;//---allows multiple orders to open

if(!IsTrade) {

if (StopLossMode) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;

if (TakeProfitMode) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

if(OrdersTotal() < 1)

Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);

if(Ticket > 0) {

if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {

Print("BUY order opened : ", OrderOpenPrice());

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");

} else {

Print("Error opening BUY order : ", GetLastError());

}

}

if (EachTickMode) TickCheck = True;

if (!EachTickMode) BarCount = Bars;

return(0);

}

}

Many Thanks Eaglehawk....Will try this ...

 

Hi,

By using if(OrdersTotal() < 1), only 1 trade will opened at a time. As soon as 1 trade is closed another will be opened if the conditions meet.

if we use if(OrdersTotal() < 2), then 2 trades will be opened at a time.

we need a code to open 1 long trade and hit tp, and wait for next trend to start to open a short trade.

 

there are several ways you could approach this problem. to determine the trend is a simple method that could be accieved by almost anything.

a moving average is one that i find the most crucial and effective. there are ways to determine the slope which i don't have the time to come up with right now, but maybe in a week.

one other way is subtacting the highs and lows or opens and closes to determine trends.

 

Thank you for your reply Eaglehawk,

I am looking for a code that would do this: Send one order per trend, if order hits takeprofit or stoploss, the order is closed.If the trend continues, it should wait for the trend to change to send another order. Thank you for your time and help.

 

Is it all right if you send over the ea you want the code attatched to. firstly, some ea's are setup differently than others. secondly, it helps to have the benifit of something to add on to and show than tell what to put in the code.

 

Hi,

For eg if you look at the expert i attached.... you'll notice that this ea has potential but will open trades even while the trend is fading and all those trades would result in a loss. so if we can restrict this ea to send one buy order after the price moves above the pivot and close it in profit or loss and wait until price moves below the pivot to send a sell order.

Thanks

 
triumph:
Thank you for your reply Eaglehawk, I am looking for a code that would do this: Send one order per trend, if order hits takeprofit or stoploss, the order is closed.If the trend continues, it should wait for the trend to change to send another order. Thank you for your time and help.

Is there anyone who can help in this matter ...please

Thanks

 
triumph:
Hi,

By using if(OrdersTotal() < 1), only 1 trade will opened at a time. As soon as 1 trade is closed another will be opened if the conditions meet.

if we use if(OrdersTotal() < 2), then 2 trades will be opened at a time.

we need a code to open 1 long trade and hit tp, and wait for next trend to start to open a short trade.

can anyone (programmers) please help us !!!!!!!!.......we are stuck

Thanks in advance

 
babarmughal:
can anyone (programmers) please help us !!!!!!!!.......we are stuck Thanks in advance

please help someone..

Reason: