Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools

Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools (http://www.expert-advisor.com/forum/index.php)
-   Programmierung MQL4 (http://www.expert-advisor.com/forum/forumdisplay.php?f=220)
-   -   Trailing Stop (http://www.expert-advisor.com/forum/showthread.php?t=6374)

dd2509 31.03.19 21:47

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);
       
}



Alle Zeitangaben in WEZ +2. Es ist jetzt 05:26 Uhr.

Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.1
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum