# Sum of 2 Orders are not Correct Why

7760
2016.07.04 20:56

i dont know why SUM of 2 Orders are not correct , i am trying to close Last 2 orders with Minimum 1 usd profit. but in stratgy tester it,s closing no logic some time 0.50 cents and second trade at 0 , some time first order profit 1 usd and second order close at 17 usd loss. i cant understand what is the matter. any thing i am doing wrong

i also have function for LAST AND SECOND LAST OrderOpenTime.

trying hard but dont know what is the matter

for(i=0;i<=OrdersTotal();i++)
{

double orderprofit = 0.0;
double lastorderprofit = 0.0;

)
{

{
orderprofit = orderprofit + OrderProfit();
if(  orderprofit - lastorderprofit >= Min_Profit &&orderprofit <0 )
{

OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,clrYellow);

}
}

}

}
Moderator
4728
2016.07.04 21:12

you reset the value of orderprofit on every new cycle.

//+------------------------------------------------------------------+
double orderprofit=0.0;
double lastorderprofit=0.0;

for(i=0;i<=OrdersTotal();i++)
{
{
{
orderprofit=orderprofit+OrderProfit();
if(orderprofit-lastorderprofit>=Min_Profit && orderprofit<0)
{
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,clrYellow);
}
}
}
}
//+------------------------------------------------------------------+

it needs to be declared outside of the loop.

Also please use the styler (Ctrl+,)

And may want to check the return value of OrderClose() function.

7760
2016.07.04 21:33
Marco vd Heijden:

you reset the value of orderprofit on every new cycle.

it needs to be declared outside of the loop.

Also please use the styler (Ctrl+,)

And may want to check the return value of OrderClose() function.

i tried but no luck can you fix it

/////////////Order Close At Average////////////////
double orderprofit = 0.0;
double lastorderprofit = 0.0;

for(i=0;i<=OrdersTotal();i++)
{

)
{

{
orderprofit =OrderProfit();
if(  orderprofit + lastorderprofit >= Min_Profit )
{

OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,clrYellow);

}

}

}
else

orderprofit = 0.0;
lastorderprofit = 0.0;

}
Moderator
4728
2016.07.04 21:39
It's not complete.
7760
2016.07.04 21:44
Marco vd Heijden:

It's not complete.

)
{

{

orderprofit =OrderProfit();
if(  (orderprofit + lastorderprofit) >= Min_Profit )
{
orderprofit = 0.0;
lastorderprofit = 0.0;

OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,clrYellow);

}

}

}
else

orderprofit = 0.0;
lastorderprofit = 0.0;

}

even i tried with this but no luck. i will be very thankful to you if you do some help to fix this. i really stuck on this from 3 days

Moderator
4728
2016.07.04 21:48
It's not complete.
7760
2016.07.04 21:49
Marco vd Heijden:
It's not complete.

can you help me to complete it please

Moderator
4728
2016.07.04 21:50

can you help me to complete it please

7760
2016.07.04 21:59
Marco vd Heijden:

should i reset all them to 0 on every cycle

Moderator
4728
2016.07.04 22:08

should i reset all them to 0 on every cycle

No that is the problem you can not reset them if you want to add them together.

Your code is incomplete, functions are missing.

7760
2016.07.04 22:17
Marco vd Heijden:

No that is the problem you can not reset them if you want to add them together.

Your code is incomplete, functions are missing.

datetime LastSell0()
{

datetime orderopentime[];                 //--- declare array
int orderstotal=OrdersTotal();     //--- declare orderstotal
ArrayResize(orderopentime,orderstotal,0); //--- resize array
for(int i=0;i<orderstotal;i++)            //--- loop
{
//---- check selection result
{
break;
}
else if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true && OrderSymbol() == Symbol() && OrderType()==OP_SELL ) //--- check result
{
//Print("Symbol: ",OrderSymbol(),
//      " Ticket: ",OrderTicket(),
//      " Open Time: ",OrderOpenTime(),
//      " Open Price: ",OrderOpenPrice(),
//      " Close Time: ",OrderCloseTime(),
//      " Close Price: ",OrderClosePrice());

//--- fill array
orderopentime[i]=OrderOpenTime(); //--- fill array
}
}
int index;                                                        //--- declare index
index=ArrayMaximum(orderopentime,WHOLE_ARRAY,0);                  //--- find oldest order
Print(" Last order: ",TimeToString(orderopentime[index]));        //--- print result
orderopentime[index]=0;                                           //--- reset value so it will not be found again
index=ArrayMaximum(orderopentime,WHOLE_ARRAY,0);                  //--- find second oldest order
Print(" Second Last order: ",TimeToString(orderopentime[index])); //--- print result
orderopentime[index]=0;                                           //--- reset value so it will not be found again
index=ArrayMaximum(orderopentime,WHOLE_ARRAY,0);                  //--- find third oldest order
Print(TimeToString(orderopentime[index]));  //--- print result
return(OrderOpenTime());
}

{

datetime orderopentime[];                 //--- declare array
int orderstotal=OrdersTotal();     //--- declare orderstotal
ArrayResize(orderopentime,orderstotal,0); //--- resize array
for(int i=0;i<orderstotal;i++)            //--- loop
{
//---- check selection result
{
break;
}
else if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true && OrderSymbol() == Symbol() && OrderType()==OP_BUY ) //--- check result
{
//Print("Symbol: ",OrderSymbol(),
//      " Ticket: ",OrderTicket(),
//      " Open Time: ",OrderOpenTime(),
//      " Open Price: ",OrderOpenPrice(),
//      " Close Time: ",OrderCloseTime(),
//      " Close Price: ",OrderClosePrice());

//--- fill array
orderopentime[i]=OrderOpenTime(); //--- fill array
}
}
int index;                                                        //--- declare index
index=ArrayMaximum(orderopentime,WHOLE_ARRAY,0);                  //--- find oldest order
Print(" Last order: ",TimeToString(orderopentime[index]));        //--- print result
orderopentime[index]=0;                                           //--- reset value so it will not be found again
index=ArrayMaximum(orderopentime,WHOLE_ARRAY,0);                  //--- find second oldest order
Print(" Second Last order: ",TimeToString(orderopentime[index])); //--- print result
orderopentime[index]=0;                                           //--- reset value so it will not be found again
index=ArrayMaximum(orderopentime,WHOLE_ARRAY,0);                  //--- find third oldest order
Print(TimeToString(orderopentime[index]));  //--- print result
return(OrderOpenTime());
}
datetime LastSell1()
{

datetime orderopentime[];                 //--- declare array
int orderstotal=OrdersTotal();     //--- declare orderstotal
ArrayResize(orderopentime,orderstotal,0); //--- resize array
for(int i=0;i<orderstotal;i++)            //--- loop
{
//---- check selection result
{
break;
}
else if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true && OrderSymbol() == Symbol() && OrderType()==OP_SELL ) //--- check result
{
//Print("Symbol: ",OrderSymbol(),
//      " Ticket: ",OrderTicket(),
//      " Open Time: ",OrderOpenTime(),
//      " Open Price: ",OrderOpenPrice(),
//      " Close Time: ",OrderCloseTime(),
//      " Close Price: ",OrderClosePrice());

//--- fill array
orderopentime[i]=OrderOpenTime(); //--- fill array
}
}
int index;                                                        //--- declare index
index=ArrayMaximum(orderopentime,WHOLE_ARRAY,0);                  //--- find oldest order
Print(" Last order: ",TimeToString(orderopentime[index]));        //--- print result
orderopentime[index]=0;                                           //--- reset value so it will not be found again
index=ArrayMaximum(orderopentime,WHOLE_ARRAY,0);                  //--- find second oldest order
Print(" Second Last order: ",TimeToString(orderopentime[index]));
return(OrderOpenTime()); //--- print result
orderopentime[index]=0;                                           //--- reset value so it will not be found again
index=ArrayMaximum(orderopentime,WHOLE_ARRAY,0);                  //--- find third oldest order
Print(TimeToString(orderopentime[index]));  //--- print result

}
{

datetime orderopentime[];                 //--- declare array
int orderstotal=OrdersTotal();     //--- declare orderstotal
ArrayResize(orderopentime,orderstotal,0); //--- resize array
for(int i=0;i<orderstotal;i++)            //--- loop
{
//---- check selection result
{
break;
}
else if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true && OrderSymbol() == Symbol() && OrderType()==OP_SELL ) //--- check result
{
//Print("Symbol: ",OrderSymbol(),
//      " Ticket: ",OrderTicket(),
//      " Open Time: ",OrderOpenTime(),
//      " Open Price: ",OrderOpenPrice(),
//      " Close Time: ",OrderCloseTime(),
//      " Close Price: ",OrderClosePrice());

//--- fill array
orderopentime[i]=OrderOpenTime(); //--- fill array
}
}
int index;                                                        //--- declare index
index=ArrayMaximum(orderopentime,WHOLE_ARRAY,0);                  //--- find oldest order
Print(" Last order: ",TimeToString(orderopentime[index]));        //--- print result
orderopentime[index]=0;                                           //--- reset value so it will not be found again
index=ArrayMaximum(orderopentime,WHOLE_ARRAY,0);                  //--- find second oldest order
Print(" Second Last order: ",TimeToString(orderopentime[index]));
return(OrderOpenTime()); //--- print result
orderopentime[index]=0;                                           //--- reset value so it will not be found again
index=ArrayMaximum(orderopentime,WHOLE_ARRAY,0);                  //--- find third oldest order
Print(TimeToString(orderopentime[index]));  //--- print result

}

{
for(int i = 0 ; i <= OrdersTotal() ; i++)

{

{

}

}
}
int OrderTicketsSell ()
{
for(int i = 0 ; i <= OrdersTotal() ; i++)

{

if(Orderinfo == True && OrderType()==OP_SELL)
{

int OrderTicketSell=OrderTicket();

}

return(OrderTicketSell);
}
}

these are functions

123