Close Old Orders

 

Hi All - I need help with the following scenario:


Example I am creating an EA based on the EMA cross over/order.

So when an EMA cross under I would do a sell and when it cross over I would do a buy.

I am trying to close any previous position (buy/sell) when the EMA goes opposite to the order.

If (previousSignal == sell && currentSignal == buy) then

{close all previous sell order;]

else if (previousSignal == buy & currentSignal == sell) then

{close all buy order;}


Thanks in advance

 
EternalBlue 2044 :

Hi All - I need help with the following scenario:


Example I am creating an EA based on the EMA cross over/order.

So when an EMA cross under I would do a sell and when it cross over I would do a buy.

I am trying to close any previous position (buy/sell) when the EMA goes opposite to the order.

If (previousSignal == sell && currentSignal == buy) then

{close all previous sell order ;]

else if (previousSignal == buy & currentSignal == sell) then

{close all buy order;}


Thanks in advance

Show your code.

 
Vladimir Karputov #:

Show your code.

I go up to here so far, but not sure how I can make sure I close the order type SELL or BUY accordingly - thoughts?


            prevSig = sigType;
            sigType = myTrend();
          
           if (prevSig=-1 && sigType=1) then //previous trend was sell (-1) and now it's buy trend sigType=1
           {OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID), 10,NULL);} // here I want to close the sell position that's already open if any
           if (prevSig=1 && sigType=-1) then //previous trend is buy and now trend is sell
            {OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID), 10,NULL);} //here I want to close the buy position that's already open if any
 

There is no need to check the previous signal, only opposite direction orders to the current signal.

 When there is a new signal say a Buy and there is an opposite order open ie. a Sell then close the Sell order

If (sigType==1 && sells>0)   OrderClose(sell);

Reason: