Hier mal ein CodeSnippet.
Code:
int hstTotal = 10; // Nur Beispiel von 10 Trades in der Historie
int HistoryOrderType;
int HistoryOrderTicket;
int HistoryOrderCloseTime;
double HistoryOrderClosePrice;
int HistoryOrderOpenTime;
double HistoryOrderOpenPrice;
double HistoryOrderOpenProfit;
double HistoryOrderOpenStopLoss;
string OrderName;
for(i=0;i<hstTotal;i++)
{
//---- check selection result
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
{
Print("Access to history failed with error (",GetLastError(),")");
break;
}
HistoryOrderType = OrderType();
if (OrderSymbol() == Symbol())
{
HistoryOrderCloseTime=OrderCloseTime();
HistoryOrderClosePrice=OrderClosePrice();
HistoryOrderOpenTime=OrderOpenTime();
HistoryOrderOpenPrice=OrderOpenPrice();
HistoryOrderOpenProfit=OrderProfit();
HistoryOrderOpenStopLoss=OrderStopLoss();
HistoryOrderTicket=OrderTicket();
OrderName=DoubleToStr(HistoryOrderTicket,0)+" "+TimeToStr(HistoryOrderOpenTime)+" "+DoubleToStr(HistoryOrderOpenPrice,4);
if(!ObjectCreate(DoubleToStr(HistoryOrderTicket,0), OBJ_TEXT, 0, HistoryOrderOpenTime, (HistoryOrderOpenPrice+HistoryOrderOpenStopLoss)/2))
{
Print("error: can't create text_object! code #",GetLastError());
return(0);
}
ObjectSetText(DoubleToStr(HistoryOrderTicket,0),OrderName,10,"Times New Roman", Yellow);
if (HistoryOrderType == OP_BUY)
{
Print("Order ",OrderName,": BUY t/p ",HistoryOrderOpenProfit," s/l ",HistoryOrderOpenStopLoss);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice,233,Blue);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice + HistoryOrderOpenProfit * Point,177,Blue);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenStopLoss,251,Yellow);
if (HistoryOrderClosePrice >= HistoryOrderOpenProfit)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,252,Blue);
if (HistoryOrderClosePrice <= HistoryOrderOpenStopLoss)
{
if (HistoryOrderClosePrice <= HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,78,Yellow);
if (HistoryOrderClosePrice > HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,254,Blue);
}
}
if (HistoryOrderType == OP_BUYSTOP)
{
Print("Order ",OrderName,": BUYSTOP t/p ",HistoryOrderOpenProfit," s/l ",HistoryOrderOpenStopLoss);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice,228,Blue);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice + HistoryOrderOpenProfit * Point,177,Blue);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenStopLoss,251,Yellow);
if (HistoryOrderClosePrice >= HistoryOrderOpenProfit)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,252,Blue);
if (HistoryOrderClosePrice <= HistoryOrderOpenStopLoss)
{
if (HistoryOrderClosePrice <= HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,78,Yellow);
if (HistoryOrderClosePrice > HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,254,Blue);
}
}
if (HistoryOrderType == OP_BUYLIMIT)
{
Print("Order ",OrderName,": BUYLIMIT t/p ",HistoryOrderOpenProfit," s/l ",HistoryOrderOpenStopLoss);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice,200,Blue);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice + HistoryOrderOpenProfit * Point,177,Blue);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenStopLoss,251,Yellow);
if (HistoryOrderClosePrice >= HistoryOrderOpenProfit)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,252,Blue);
if (HistoryOrderClosePrice <= HistoryOrderOpenStopLoss)
{
if (HistoryOrderClosePrice <= HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,78,Yellow);
if (HistoryOrderClosePrice > HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,254,Blue);
}
}
if (HistoryOrderType == OP_SELL)
{
Print("Order ",OrderName,": SELL t/p ",HistoryOrderOpenProfit," s/l ",HistoryOrderOpenStopLoss);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice,234,Red);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice - HistoryOrderOpenProfit * Point,177,Red);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenStopLoss,251,Yellow);
if (HistoryOrderClosePrice <= HistoryOrderOpenProfit)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,252,Red);
if (HistoryOrderClosePrice >= HistoryOrderOpenStopLoss)
{
if (HistoryOrderClosePrice >= HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,78,Yellow);
if (HistoryOrderClosePrice < HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,254,Red);
}
}
if (HistoryOrderType == OP_SELLSTOP)
{
Print("Order ",OrderName,": SELLSTOP t/p ",HistoryOrderOpenProfit," s/l ",HistoryOrderOpenStopLoss);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice,230,Red);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice - HistoryOrderOpenProfit * Point,177,Red);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenStopLoss,251,Yellow);
if (HistoryOrderClosePrice <= HistoryOrderOpenProfit)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,252,Red);
if (HistoryOrderClosePrice >= HistoryOrderOpenStopLoss)
{
if (HistoryOrderClosePrice >= HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,78,Yellow);
if (HistoryOrderClosePrice < HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,254,Red);
}
}
if (HistoryOrderType == OP_SELLLIMIT)
{
Print("Order ",OrderName,": SELLIMIT t/p ",HistoryOrderOpenProfit," s/l ",HistoryOrderOpenStopLoss);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice,202,Red);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice - HistoryOrderOpenProfit * Point,177,Red);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenStopLoss,251,Yellow);
if (HistoryOrderClosePrice <= HistoryOrderOpenProfit)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,252,Red);
if (HistoryOrderClosePrice >= HistoryOrderOpenStopLoss)
{
if (HistoryOrderClosePrice >= HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,78,Yellow);
if (HistoryOrderClosePrice < HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,254,Red);
}
}
}
{
}
}