Sum of 2 Orders are not Correct Why - page 2

 
Muhammad Mudasir:

   these are functions

return(OrderOpenTime());
this does not work outside of the OrderSelect loop.
 
Marco vd Heijden:
this does not work outside of the OrderSelect loop.



so how to make it work. please help marco

 
Marco vd Heijden:
this does not work outside of the OrderSelect loop.


i change some codes and try to reset now ea close in profit but it,s when first trade in profit at 1 usd minimum

do you think any more changes i need to do?

/////////////Order Close At Average////////////////
 double orderprofit = 0.0;
  double lastorderprofit = 0.0;
  datetime ordertime =0;
  int orderticket =0;
 for(i=0;i<=OrdersTotal();i++)
 {
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
   {
      ordertime = OrderOpenTime();
    if(ordertime == LastBuy1()) { orderprofit = OrderProfit() ; orderticket =OrderTicket(); } else { orderprofit = 0.0; orderticket=0;}
    if(OrderSelect(OrderTicketNumberBuy(),SELECT_BY_TICKET,MODE_TRADES) && 
         OP_BUY && OrderSymbol()== Symbol() && OrderMagicNumber()==MagicNumber)
         { lastorderprofit = OrderProfit(); } else {lastorderprofit = 0.0;}
         
  }
 
  if(orderprofit+lastorderprofit==Min_Profit && orderticket > 0 && OrderTicketNumberBuy() >0)
  {
  
  
   
      OrderClose(orderticket,OrderLots(),OrderClosePrice(),Slippage,clrYellow);
      
      OrderClose(OrderTicketNumberBuy(),OrderLots(),OrderClosePrice(),Slippage,clrYellow);
  
  
  
  }
  
 
}  
 
//+------------------------------------------------------------------+
double profit=0;

for(int i=0;i<OrdersTotal(),i++)
  {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
     {
      if(OrderSymbol()==Symbol())
        {
         profit=profit+OrderProfit();
        }
     }
  }
Print(" Average Profit for ",Symbol()," is: ",profit);
//+------------------------------------------------------------------+


This calculates the average profit for the symbol.

 
Muhammad Mudasir:


i change some codes and try to reset now ea close in profit but it,s when first trade in profit at 1 usd minimum

do you think any more changes i need to do?


yes i know but it,s calculate all orders profit i want last 2 orders profit

 
Muhammad Mudasir:


yes i know but it,s calculate all orders profit i want last 2 orders profit

I did give you the example.

//+------------------------------------------------------------------+
//| Get Profit for last two orders                                   |
//+------------------------------------------------------------------+
double GetProfit()
  {
   datetime opentime[];double profit[];int index;double avgprofit;int cnt=0;
   ArrayResize(opentime,1,0);ArrayResize(profit,1,0);
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
        {
         if(OrderMagicNumber()==MagicNumber)
           {
            if(OrderSymbol()==Symbol())
              {
               ArrayResize(opentime,ArraySize(opentime)+1,0);
               opentime[i]=OrderOpenTime();
               ArrayResize(profit,ArraySize(profit)+1,0);
               profit[i]=OrderProfit();
               cnt++;
              }
           }
        }
     }
   index=ArrayMaximum(opentime,WHOLE_ARRAY,0);
   avgprofit=profit[index];
   opentime[index]=0;
   index=ArrayMaximum(opentime,WHOLE_ARRAY,0);
   avgprofit=avgprofit+profit[index];
   //Print(IntegerToString(cnt),"Orders Processed, Average Profit for the last two orders: ",DoubleToString(avgprofit,2));
   return(avgprofit);
  }
//+------------------------------------------------------------------+
 
Muhammad Mudasir:


yes i know but it,s calculate all orders profit i want last 2 orders profit

Marco vd Heijden   YOU ARE VERY HELPFUL. THAK YOU ONCE AGAIN
 
Marco vd Heijden:

I did give you the example.


i added some filter in code but this filter only do Buy Sum Good but not Sell Some if last one not Sell. i am attaching Sell code please check why it,s return 0

i want again your help

double profit()
  {
   datetime opentime[];double profit[];int index;double avgprofit;double cnt=0;
   ArrayResize(opentime,1,0);ArrayResize(profit,1,0);
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) )
        {
        
           
            if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)
              {
               ArrayResize(opentime,ArraySize(opentime)+1,0);
               opentime[i]=OrderOpenTime();
               ArrayResize(profit,ArraySize(profit)+1,0);
               profit[i]=OrderProfit()+OrderCommission()+OrderSwap();
               
               cnt++;
              }
           
        }
     }
   index=ArrayMaximum(opentime,WHOLE_ARRAY,0);
   avgprofit=profit[index];
   opentime[index]=0;
   index=ArrayMaximum(opentime,WHOLE_ARRAY,0);
   avgprofit=avgprofit+profit[index];
   //Print(IntegerToString(cnt),"Orders Processed, Average Profit for the last two orders: ",DoubleToString(avgprofit,2));
   return(avgprofit);
  }



Regards



Muhammad Mudasir

 

I don't get it you want the profit of last two orders then add filter OP_SELL and complain it doesn't work when it's not OP_SELL ?

This will take a long time to dev like this.

Please draw up a flow chart.

http://Draw.io

draw.io - free flowchart maker and diagrams online
draw.io - free flowchart maker and diagrams online
  • draw.io
draw.io (formerly Diagramly) is free online diagram software. You can use it as a flowchart maker, network diagram software, to create UML online, as an ER diagram tool, to...
 
Marco vd Heijden:

I don't get it you want the profit of last two orders then add filter OP_SELL and complain it doesn't work when it's not OP_SELL ?

This will take a long time to dev like this.

Please draw up a flow chart.

http://Draw.io



see these orders



when i do Add OP_BUY in filter then i get result -1.46 usd which is Correct

 double profit()
  {
   datetime opentime[];double profit[];int index;double avgprofit;int cnt=0;
   ArrayResize(opentime,0,1);ArrayResize(profit,0,1);
   for(int i=0;i<=OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) )
        {
        
           
            if(OrderSymbol()==Symbol() &&  OrderType()==OP_BUY)
              {
               ArrayResize(opentime,ArraySize(opentime)+1,0);
               opentime[i]=OrderOpenTime();
               ArrayResize(profit,ArraySize(profit)+1,0);
               profit[i]=OrderProfit()+OrderCommission()+OrderSwap();
               
               cnt++;
              }
           
        }
     }
   index=ArrayMaximum(opentime,WHOLE_ARRAY,0);
   avgprofit=profit[index];
   opentime[index]=0;
   index=ArrayMaximum(opentime,WHOLE_ARRAY,0);
   avgprofit=avgprofit+profit[index];
   Alert(IntegerToString(cnt),"Orders Processed, Average Profit for the last two orders: ",DoubleToString(avgprofit,2));
   return(avgprofit);
  }





when i add O_SELL IN filter then i get 0.0 result which is not correct. please help me in this

void OnStart()
  {


    int Spread = MarketInfo(Symbol(),MODE_SPREAD);


   Alert(profit());






       
 }
   double profit()
  {
   datetime opentime[];double profit[];int index;double avgprofit;int cnt=0;
   ArrayResize(opentime,0,1);ArrayResize(profit,0,1);
   for(int i=0;i<=OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) )
        {
        
           
            if(OrderSymbol()==Symbol() &&  OrderType()==OP_SELL)
              {
               ArrayResize(opentime,ArraySize(opentime)+1,0);
               opentime[i]=OrderOpenTime();
               ArrayResize(profit,ArraySize(profit)+1,0);
               profit[i]=OrderProfit()+OrderCommission()+OrderSwap();
               
               cnt++;
              }
           
        }
     }
   index=ArrayMaximum(opentime,WHOLE_ARRAY,0);
   avgprofit=profit[index];
   opentime[index]=0;
   index=ArrayMaximum(opentime,WHOLE_ARRAY,0);
   avgprofit=avgprofit+profit[index];
   Alert(IntegerToString(cnt),"Orders Processed, Average Profit for the last two orders: ",DoubleToString(avgprofit,2));
   return(avgprofit);


i get 0.0 , i dont know why because of i have nothing knowledge about array


Reason: