Du fragst OrderHistory total falsch ab.
So etwa gehts nämlich, und du machst die Abfrage in der History nur 1 x pro Order:
Code:
int LastBuy = 0;
int LastSel = 0;
int History_index = 0;
int LastHistory_index = 0;
.
.
.
//========================================================
// P R U E F E N O B O R D E R S G E O E F F N E T S I N D
//=============================================================================================================
bool BuyInv=false;
bool SelInv=false;
for(i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS))
{
if(OrderType()==OP_BUY &&OrderMagicNumber()==Buy_MN &&OrderSymbol()==Symbol()) BuyInv=true;
if(OrderType()==OP_SELL&&OrderMagicNumber()==Sell_MN&&OrderSymbol()==Symbol()) SelInv=true;
}
}
//------------------------------
// OrderLots für Buy erhöhen
//----------------------------
History_index = OrdersHistoryTotal();
if (LastHistory_index != History_index)
{
if (LastBuy > 0)
{
//Print ("Gewinn LastBuy fragen: ",LastBuy);
for(i=History_index;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderTicket() == LastBuy)
{
Print ("OrderProfit LastBy: ",LastBuy," ",DoubleToString(OrderProfit(),2));
if (OrderProfit()>0.0)
{
if(OLPO_LP==false)LotsBuy = LotsBuy + LotsPlus;
if(OLPO_LP==true)LotsBuy = OrderLots() + LotsPlus;
}
Print ("LotBuy: ",LotsBuy);
LastBuy = 0;
}
}
}
}
// --------------------------
// OrderLots für Sell erhöhen
// --------------------------
if (LastSel > 0)
{
//Print ("Gewinn LastSeL fragen: ",LastSel);
for(i=History_index;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderTicket() == LastSel)
{
Print ("OrderProfit LastSel: ",LastSel," ",DoubleToString(OrderProfit(),2));
if (OrderProfit()>0.0)
{
if(OLPO_LP==false)LotsSel = LotsSel + LotsPlus;
if(OLPO_LP==true)LotsSel = OrderLots() + LotsPlus;
}
Print (" LotsSel: ",LotsSel);
LastSel = 0;
}
}
}
}
}
LastHistory_index = History_index;
//=============================================================================================================
// O P E N O R D E R S
//=============================================================================================================
.
.
.