Look for last closed trade

 

Hello,


I´m trying to add a routine to an EA to avoid open consecutive orders of the same type.

The idea here is, if price is above such a MA it BUY, but when that initial order is closed I need to avoid that the EA opens a new Buy order even if the price still above the MA, because the next order must be a SELL order when the price is below the MA.

I need something to identify the kind (Buy/sell) of the last closed order.

I tried with the follow piece of code, but it isn´t generating a signal .

Can I have some suggestions? Thanks.

-----------------------------------------------------


int Last_Buy, Last_Sell;


if (modo_scalper==1)
{
for(int z=OrdersHistoryTotal()-1;z>=0;z--)
{
if(OrderSelect(z,SELECT_BY_POS,MODE_HISTORY)==true && OrderSymbol()==Symbol() && OrderMagicNumber()==magico)
{
if(OrderType()==OP_BUY)
{
Last_Buy=1;
}


if (OrderType()==OP_SELL)
{
Last_Sell=1;
}

}

}

}
 

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. avoid that the EA opens a new Buy order even if the price still above the MA
    So test for it
    bool isWaiting;
    int init(){ isWaiting = false; }
    int start(){
       bool wasWaiting = isWaiting; 
       isWaiting = false; // Assume not OK to open
       :                  // Test 
       // Ok to open
       isWaiting = Bid < ma; // Time to open?
       if(!isWaiting && wasWaiting){ // Open Buy!
  3. Your loop keeps going after you've found the highest position order and will set both values (needs a break).
  4. Don't use int's when you mean bool's
 
cashmaker:

Hello,


I´m trying to add a routine to an EA to avoid open consecutive orders of the same type.

The idea here is, if price is above such a MA it BUY, but when that initial order is closed I need to avoid that the EA opens a new Buy order even if the price still above the MA, because the next order must be a SELL order when the price is below the MA.

I need something to identify the kind (Buy/sell) of the last closed order.

I tried with the follow piece of code, but it isn´t generating a signal .

Can I have some suggestions? Thanks.

...

Can you please edit your post and use the SRC button when you post code.