Trailing Stop
Liebes Forum,
ich habe ein Problem mit meinem Trailing Stop. Dieser funktioniert wunderbar bei BUY Positionen nicht aber bei Sell Positionen.
Erkennt jemand den Fehler
Nette Grüße
Code:
int ticket;
int BUY;
double Preis;
input int Average;
input int TP=10;
input int TrailingStop_Abstand = 15;
input int TrailingStop_Schritt = 2;
void OnTick()
{
Preis=Ask;
double MA=iMA ( NULL,0,Average,0,1,4,0 );
if (Preis>=MA){
if (OpenPosCount(BUY)==0){ticket=OrderSend(Symbol(), OP_BUY, 1, Preis, 1,0 , Preis+TP*10*Point, "MarketOrder", 0, 0, Blue);}
}
if (Preis<=MA){
if (OpenPosCount(BUY)==0){ticket=OrderSend(Symbol(), OP_SELL, 1, Preis, 1,0, Preis-TP*10*Point, "MarketOrder", 0, 0, Red);}
}
int OrdersT = OrdersTotal();
string O_Sym;
double O_Point, O_Price;
for(int i=OrdersT-1; i>=0; i--)
{
// Alle offenen Orders durchgehen...
OrderSelect(i,SELECT_BY_POS);
O_Sym = OrderSymbol();
O_Point = MarketInfo(O_Sym,MODE_POINT); // Größe eines Punktes im Symbol der Order
O_Point = O_Point*10;
if(OrderType() == OP_BUY)
{
O_Price = MarketInfo(O_Sym,MODE_BID); // Aktuellen Preis des entsprechenden Symbols
if(OrderStopLoss() < O_Price-((TrailingStop_Abstand+TrailingStop_Schritt) * O_Point))
{
if(!OrderModify(OrderTicket(),OrderOpenPrice(),O_Price-(TrailingStop_Abstand*O_Point),OrderTakeProfit(),0))
Alert("Order #",IntegerToString(OrderTicket())," konnte nicht modifiziert werden! Fehler Nr: ",IntegerToString(GetLastError()));
} }
else if(OrderType() == OP_SELL)
{
O_Price = MarketInfo(O_Sym,MODE_ASK); // Aktuellen Preis des entsprechenden Symbols
if(OrderStopLoss() > O_Price+((TrailingStop_Abstand+TrailingStop_Schritt) * O_Point))
{
if(!OrderModify(OrderTicket(),OrderOpenPrice(),O_Price+(TrailingStop_Abstand*O_Point),OrderTakeProfit(),0))
Alert("Order #",IntegerToString(OrderTicket())," konnte nicht modifiziert werden! Fehler Nr: ",IntegerToString(GetLastError()));
}
}
}
}
int OpenPosCount(int BUY){int OffenePositionen=0;for(int x=0;x<=OrdersTotal()-1;x++){if(OrderSelect(x,SELECT_BY_POS,MODE_TRADES)==true){if(OrderSymbol()==Symbol())OffenePositionen ++;}}return(OffenePositionen);
}
|