Thema: Take Profit
Einzelnen Beitrag anzeigen
  #1 (permalink)  
Alt 31.12.21
blackjack01 blackjack01 ist offline
Mitglied
 
Registriert seit: Nov 2020
Beiträge: 40
blackjack01 befindet sich auf einem aufstrebenden Ast
Standard 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());   
            
            
            
         }
        }
       }
      }
     }