I need help setting the lot size of the next buy order if open buy orders are in profit

 

I have multiple open order (up to 4). Only buy or sell open at any time.

I want to set lot size of the next buy order depending if the current open buy orders are in profit.

if total openorder profit > 0, then next order lot size = 1.4

if total openorder profit < 0, then next order lot size = 0 (can I set 0 lot size?) if not then 0.2 lot size.

Does the following make sense?

// To set lots size if open buy orders are in profit

double BuyLots()
{
int total = OrdersTotal();
int ProfitLongOrders = 0;
int OpenLongOrders = 0
for(int i; i=0;i<total;i++)       
OrderSelect(i, SELECT_BY_POS,MODE_TRADES);
        {
        int typebuy = OrderType();
        if (typebuy == OP_BUY )       
                {
                OpenLongOrders=OpenLongOrders+1;
                ProfitLongOrders=ProfitLongOrders+OrderProfit();
                }
        }
        {
        if (OpenLongOrders == 0) return(1.4);
                {
                if(ProfitLongOrders>0) return(1.4);
                else
                return(0.2);
                }
        }
}
 
n4btb:

Open orders have their stop loss moved to break even in another part of the EA once the trade is in 15 pip profit.

I have multiple open orders and want the following logic on setting lot sizes....

If all open buy orders have stop losses == orderopenprice, then lot size for next open buy order = 1

If not all open buy order have stop losses == orderopenprice, then lot size for next open buy order = 0.2

Should the following work?

doesnt compile. Not sure what you are doing, but ive tidied up your code so it compiles.

double BuyLots()
{
int total = OrdersTotal();
bool StopLongOrders = false;
int OpenLongOrders = 0;

for(int i; i=0;i<total;i++)
{
OrderSelect(i, SELECT_BY_POS,MODE_TRADES);

int typebuy = OrderType();
if (typebuy == OP_BUY )
{
OpenLongOrders=OpenLongOrders+1;
if (OrderStopLoss() == OrderOpenPrice())
{
StopLongOrders = true ;
}
}

// to set first buy order to 1.4 lot size
if(OpenLongOrders==0)
{
return(1.4);
}

// if any open buy order does not have stop loss equal to open price then new order lot size will be small
if (!StopLongOrders)
{
return(0.2);
}
}
// if all open buy orders have stop loss equal to open price then new order lot size will be 1
return(1);
}

 
double BuyLots()
   {
      int total = OrdersTotal();
      bool StopLongOrders = false;
      int OpenLongOrders = 0;
      
      for(int i; i=0;i<total;i++)       
      {
         OrderSelect(i, SELECT_BY_POS,MODE_TRADES);
        
         int typebuy = OrderType();
         if (typebuy == OP_BUY )       
         {
            OpenLongOrders=OpenLongOrders+1;
            if (OrderStopLoss() == OrderOpenPrice()) 
            {
               StopLongOrders = true ;
            }
         }
        
         // to set first buy order to 1.4 lot size
        if(OpenLongOrders==0) 
        {
            return(1.4);
        }
           
         // if any open buy order does not have stop loss equal to open price then new order lot size will be small
         if (!StopLongOrders) 
         {
            return(0.2);
         }
      }      
      // if all open buy orders have stop loss equal to open price then new order lot size will be 1
      return(1);
   }
 
manic:

thanks. I'll give it a go.
Reason: