Need help with trigger sell positions - page 2

 
GrumpyDuckMan:

Hello friends,

This code hasn't been tested.

Maybe change your SL/TP

If you know the ticket number or magic number, why use select by pos?

I do something like this to close positions down.

this may be of some help also.

this way I can debug if OrderSend(); has successfully placed the order.

Thanks for the input.  However, my closing out is not a problem, the only problem I have is getting sell positions to open. 

I'm usng "res" in place of "ticket" does that matter.  It's working for buys just find, just not sells.  Why change so much?

 
kamalagroup:

Hi, any help is appreciated, I can't figure out why my EA only does buy positions.  I need it to do sell positions also, on multiple time frames simultaneously.

I'm sorry I haven't found any errors in your code (there are some nonsense in your code but that have no effect on EA's logic). I tried to backtest your EA and it opened both buy and sell orders. You should look for possible errors outside your code.
 
GrumpyDuckMan:

Hello again,

The first if statement buy++ is always going to greater than the second if statement sell++.

True, or not?

   if(buys>0) return(buys);
   else       return(-sells);
buys and -sells are only variables to a function.

I was responding to your comment about 

         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;

Then you respond referencing the code

   if(buys>0) return(buys);
   else       return(-sells);

Why??


Regarding 

   if(buys>0) return(buys);
   else       return(-sells);

The way of coding is odd, but the coder is only interested in whether there is an open order or not so it will do what he wants.

The first if statement buy++ is always going to greater than the second if statement sell++.

I have no idea what you mean, they are if conditions that do not test whether buys>sells

 
Keith Watford:

I was responding to your comment about 

Then you respond referencing the code

Why??


Regarding 

The way of coding is odd, but the coder is only interested in whether there is an open order or not so it will do what he wants.

The first if statement buy++ is always going to greater than the second if statement sell++.

I have no idea what you mean, they are if conditions that do not test whether buys>sells

That would not increase buy, if a sell is executed first. 
 
Petr Nosek:
I'm sorry I haven't found any errors in your code (there are some nonsense in your code but that have no effect on EA's logic). I tried to backtest your EA and it opened both buy and sell orders. You should look for possible errors outside your code.
You are right. It must be something in another part of the sell logic code that I recently removed.  Thanks
 

Hello again,

int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
//---
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
//--- return orders volume
   if(buys>0) return(buys);
   else       return(-sells);
  }

if you break; the if statement may default to buys++. So if buy is greater than = 0. Some code is executed.

Reason: