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

blackjack01 31.12.21 10:00

Take Profit
 
Hallo

Ich würde bitte mit Hilfe brauchen . Danke !!!!!

Habe mich an einen EA versucht .

1) Problem wenn ich keinen TP und SL angebe macht er keine Ordes ???
Der EA soll auch mehrere Ordes eröffnen .
2) Ich hätte gerne einen Takeprofit in Euro (zB. wenn 100 Euro erreicht sind
alle Positionen schliesen )

3) Ist es möglich zB. ich habe ein Ziel 300 Euro TP (soll beim erreichen aber nicht alle Positionen schließen ) sondern einen Trailing Stop auf zB. 200 Euro setzen (ein Wert wäre super zB. beim erreichen von 300 kommt der Trailing Stop 30 % darunter und wird nachgezogen ) und im abstand von 100 Euro (zB. 30 % )nachgezogen ????

Danke

Freue mich über jede Hilfe !!!!!

Code:



// 31.12.2021 V-2


#property strict

 input double Lots = 0.01;
 input int SLPoints = 500;
 input int TPPoints = 500;
 input int TSLPoint = 500;
 
 
 input ENUM_TIMEFRAMES Timeframe = PERIOD_H4;
 input int PeriodsMAFast = 50;
 input ENUM_MA_METHOD MethdeMAFast = MODE_SMA;
 input int PeriodsMASlow = 200;
 input ENUM_MA_METHOD MethdeMASlow = MODE_SMA;
 
 input string Commententary = "Andy";
 input int Magic = 210879 ;
 
 datetime timestamp ;
 
int OnInit()
  {

  return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {

 
  }

void OnTick(){


  TrailingStop(); 


  if(timestamp == iTime(Symbol(),Timeframe,0)) return ;
  timestamp = iTime(Symbol(),Timeframe,0);

 
 
    double maFast = iMA (Symbol(),Timeframe,PeriodsMAFast ,0,MethdeMAFast ,PRICE_CLOSE,1);
    double maSlow = iMA (Symbol(),Timeframe,PeriodsMASlow ,0,MethdeMASlow ,PRICE_CLOSE,1);
    double maFastLast = iMA (Symbol(),Timeframe,PeriodsMAFast ,0,MethdeMAFast ,PRICE_CLOSE,2);
    double maSlowLast = iMA (Symbol(),Timeframe,PeriodsMASlow ,0,MethdeMASlow ,PRICE_CLOSE,2);
     
    if(maFast > maSlow && maFastLast <  maSlowLast ){
    Print("Long");
    int ticket = executeLong();
    Print(IntegerToString(ticket));
 
  }else if ( maFast < maSlow && maFastLast >  maSlowLast ){
 
    Print("Short");
    int ticket = executeShort() ;
    Print(IntegerToString(ticket));
  }
  }
 
  int executeLong ( ){
  double entry = Ask ;
  entry = NormalizeDouble (entry,Digits);
 
  double sl = entry - SLPoints * Point;
  sl= NormalizeDouble(sl,Digits);
 
  double tp = entry + TPPoints * Point;;
  tp = NormalizeDouble(tp,Digits);
 
  int ticket = OrderSend (Symbol(),OP_BUY,Lots,entry,1000,sl,tp,Commententary,Magic);
 
  return ticket;
 
    } 
 
  int executeShort (){
  double entry = Bid ;
  entry = NormalizeDouble (entry,Digits);
   
  double sl = entry + SLPoints * Point;
  sl= NormalizeDouble(sl,Digits);
 
  double tp = entry - TPPoints * Point;
  tp = NormalizeDouble(tp,Digits);
   
  int ticket = OrderSend (Symbol(),OP_SELL,Lots,entry,1000,sl,tp,Commententary,Magic);
 
  return ticket;
 
  }
   
  void TrailingStop(){
    for(int i = 0; i < OrdersTotal(); i++){
      if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == Magic ) {
        if(OrderType() == OP_BUY){
          double sl = Bid - TSLPoint * Point ;
          sl = NormalizeDouble(sl,Digits);
          if(sl > OrderStopLoss()){
            bool res = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration());
           
            }
            }
        if(OrderType() == OP_SELL){
          double sl = Ask + TSLPoint * Point ;
          sl = NormalizeDouble(sl,Digits);
          if(sl < OrderStopLoss() || OrderStopLoss() == 0){
            bool res = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration()); 
           
           
           
        }
        }
      }
      }
    }


Raul0 01.01.22 02:01

Hallo,

1) Wird Print("Long"); oder Print("Short"); ausgegeben?

blackjack01 01.01.22 09:29

Hallo

Ja aber leider wenn ich keinen tp und sl angebe macht
Er nix .

Lg

traderdoc 01.01.22 11:06

Nun, dann schau doch mal in die Reiter "Experten" und/oder Journal des Terminal, welche Fehlermeldung der Ea dort ausgibt.
Ich vermute mal, dass dieser Broker ein ECN-Broker ist, und dann muss man erst die Order ohne sl und tp öffnen, und erst nach dem Öffnen kann man den sl und tp ändern (setzen).

Happy new year!

traderdoc

blackjack01 01.01.22 14:12

Hallo

Das ist die fehlermeldung


130 ERR_INVALID_STOPS Invalid stops

glg

traderdoc 01.01.22 15:05

Jep, genau.
Dann musst Du die Orders erst ohne SL und TP öffnen (entweder im Code durch Abfangen des Fehlers 130 oder gleich Öffnung immer ohne SL und TP) und erst danach mittels OrderModify() den SL und TP ändern.

traderdoc

blackjack01 01.01.22 15:44

Hallo

Danke das hab ich hinbekommen Danke

und jetzt hätte ich gerne einen TP in Euro , zu dem Thema finde ich nirgens etwas .

Danke

MA-EA 01.01.22 17:21

Da wirst Du wohl für jedes WP ausrechnen müssen, welchen Wert ihre Punkte in EURO haben. Viel Spass. ;)

Edit: Die Margin, die man für jedes WP in Euro hinter legen muss, müsste eigentlich auch schon weiter helfen... :confused:

traderdoc 02.01.22 10:49

Ach der @MA-EA wieder???

Die Formel ist doch ganz einfach:

TP-Kurs = OrderOpen + (Profit*Point/Lot/Tickvalue)
bzw.
TP-Kurs = OrderOpen - (Profit*Point/Lot/Tickvalue)

traderdoc

blackjack01 02.01.22 14:25

Danke

Werde es probieren umzusetzen .

Danke


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