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, Fragen (http://www.expert-advisor.com/forum/showthread.php?t=6717)

Alex60 08.07.20 09:31

Trailing Stop, Fragen
 
Hallo, ich habe da mal ein paar Fragen zu dem Trailing stop der im EA eingebaut ist. Wenn ich das richtig sehe ist es ja nach Punkten bezogen nicht Pips.
Wenn ich das dann richtig lese ist der Start des Trails bei 10 punkten im plus was dann auch 1 Pip sein müssten. und das er den sl dann auf 7 punkte also nicht mal 1 Pip entfernt vom aktuellen Preis setzt und dann immer so weiter
Und dann noch eine Frage gibts ne Möglichkeit das in Pips einzustellen?

Code:

/| expert initialization function                                  |
//+------------------------------------------------------------------+
int init()
  {
//----
  if(Digits==3 || Digits==5)
      pt=10*Point;
  else
      pt=Point;

Code:

input string TrailingStopLoss    = "--------------------< Trailing Stop >--------------------";//Trailing Stop Settings ............................................................................................................
input bool  UseTrailingStop      = 0;      // Use Trailing
input double TrailingStart        = 10;    // Trailing Start
input double TrailingStop        = 7;      // Trailing Stop

Code:

void TrailingStops()
  {
  if(!UseTrailingStop || TrailingStop == 0)
      return;
  if(trail_sek>TimeCurrent())
      return;
  for(int i = 0; i < OrdersTotal(); i++)
    {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
        if(OrderSymbol() == Symbol() && (magic == 0 || OrderMagicNumber() == magic))
          {
            if(OrderType() == OP_BUY)
              {
              if(Bid - OrderOpenPrice() > TrailingStart * _Point && OrderStopLoss() < ND(Bid-TrailingStop*_Point))
                {
                  Trail(ND(Bid - TrailingStop * _Point),OrderTicket());
                }
              }
            if(OrderType() == OP_SELL)
              {
              if(OrderOpenPrice() - Ask > TrailingStart * _Point && (OrderStopLoss()==0||OrderStopLoss()>ND(Ask+TrailingStop*_Point)))
                {
                  Trail(ND(Ask + TrailingStop * _Point),OrderTicket());
                }
              }
          }
        }
    }
  }
//+------------------------------------------------------------------------------------------------------------------------------------+
void Trail(double sl, int ticket)
  {
  if(OrderSelect(ticket, SELECT_BY_TICKET,MODE_TRADES))
    {
      double stop=MarketInfo(Symbol(),MODE_STOPLEVEL);
      if(OrderType()==0 && sl<Bid-stop*Point())
        {
        trail_sek=TimeCurrent()+5;
        bool modify = OrderModify(ticket, OrderOpenPrice(), sl, OrderTakeProfit(), 0, clrGold);
        int err = GetLastError();
        if(err!=ERR_NO_ERROR)
          {
            Print("Error on Trail Order modify = ", ErrorDescription(err));
          }

        }

      if(OrderType()==1 && sl>Ask+stop*Point())
        {
        trail_sek=TimeCurrent()+5;
        bool modify = OrderModify(ticket, OrderOpenPrice(), sl, OrderTakeProfit(), 0, clrGold);
        int err = GetLastError();
        if(err!=ERR_NO_ERROR)
          {
            Print("Error on Trail Order modify = ", ErrorDescription(err));
          }


Alex60 10.07.20 09:11

Keiner ne Antwort? oder so

MA-EA 11.07.20 11:16

Code:

input bool Trailing_Stop=false; // Zum Testen aus
extern int Trailing_Stop_Step=40; // Zum Testen 40. Bei TSS 6 wurden gar keine Orders geöffnet.

Code:

if(Trailing_Stop==true){


//////////////////////////////////////////////////////////////////////////////////////////////////////////////


//Neuer SELL-"SL" (S_TS) Funktionen/Berechnungen
  if(open_Sel==true){
    for(int k=OrdersTotal()-1;k>=0;k--){
      if(OrderSelect(k,SELECT_BY_POS)){
        if(OrderSymbol()==Symbol()){
          if(OrderMagicNumber()==MN_Sel){


//          gesendeter SELL_SL - Öffnungskurs, um double-Wert zu ermitteln, der zum BID dazu gerechnet wurde:
            double OSLS_OOPS = OrderStopLoss() - OrderOpenPrice();


//          Bid + SELL-SL double-Wert = neuer SELL-"SL", der bei OrderModify gesendet werden soll
            double TS_Sel = Bid + OSLS_OOPS;


            double TSS_TSS=NormalizeDouble( TS_Sel + Trailing_Stop_Step *_Point,_Digits);
       

            if(OrderStopLoss() > TSS_TSS){
              if(IsTradeAllowed()==true)OrderModify(OrderTicket(),OrderOpenPrice(),TS_Sel,OrderTakeProfit(),NULL,Blue);
              if(IsTradeContextBusy()==true)Sleep(Sl_MS);

} } } } } }


//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 
  if(open_Buy==true){
    for(int l=OrdersTotal()-1;l>=0;l--){
      if(OrderSelect(l,SELECT_BY_POS)){
        if(OrderSymbol()==Symbol()){
          if(OrderMagicNumber()==MN_Buy){


//          BUY-Öffnungskurs - gesendeten BUY-SL, um Wert zu ermitteln, der vom Ask abgezogen wurde:
            double OOPB_OSLB = OrderOpenPrice() - OrderStopLoss();


//          Ask - BUY_SL double-Wert = neuer BUY-"SL", der bei OrderModify gesendet werden soll:
            double TS_Buy = Ask - OOPB_OSLB;


//          neuer BUY_"SL" - Trailing_Stop_Step.
//          Damit soll geprüft werden, ob BUY_"SL" (B_TS) nach gezogen werden muss.
            double TSB_TSS = NormalizeDouble( TS_Buy - Trailing_Stop_Step *_Point,_Digits);


//          Wenn aktueller BUY_SL kleiner als
//          neuer BUY_SL - TSS ist, soll neuer BUY_"SL" (BUY_TS) gesendet werden:
            if( OrderStopLoss() < TSB_TSS ){
              if(IsTradeAllowed()==true)OrderModify(OrderTicket(),OrderOpenPrice(),TS_Buy,OrderTakeProfit(),NULL,Blue);
              if(IsTradeContextBusy()==true)Sleep(Sl_MS);
           
} } } } } }


//////////////////////////////////////////////////////////////////////////////////////////////////////////////


 }


Anja 11.07.20 12:09

Nach meiner, erst sehr kurzen Erfahrung, ist es besser erst zu trailen, wenn man im Gewinn ist. Mit Punkten und Pips kann ich nicht wirklich helfen, aber ich würde die Werte z.B. um Faktor 10 erhöhen:

input bool UseTrailingStop = true; // Use Trailing
input double TrailingStart = 100; // Trailing Start
input double TrailingStop = 70; // Trailing Stop

In dieser Zeile könnte TrailingStart auch 0 sein oder sogar negativ, wenn du früher trailen willst:
if(Bid - OrderOpenPrice() > TrailingStart * _Point && OrderStopLoss() < ND(Bid-TrailingStop*_Point))

TrailingStop ist der Abstand zum aktuellen Bid-Preis, nicht zum Einstiegspreis.


Alle Zeitangaben in WEZ +2. Es ist jetzt 14:44 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