Einzelnen Beitrag anzeigen
  #1 (permalink)  
Alt 04.11.19
Bucardo Bucardo ist offline
Mitglied
 
Registriert seit: Nov 2014
Beiträge: 31
Bucardo befindet sich auf einem aufstrebenden Ast
Standard Problem mit SL-Setzung bei JPY-Paaren

Hallo zusammen,

ich habe einen relativ simplen EA geschrieben, der meine aktuellen Trades mit einem automatischen Stop versieht, falls noch kein SL festgelegt wurde. Soweit so gut.

Mein Problem ist, dass ich falsche Stops erhalte, wenn ich z.B. den CHart EUR/USD geöffnet habe, der Trade aber im USD/JPY eröffnet wurde. Das Problem sind die unterschiedlichen Digits. Aber wie löse ich die SL-Setzung vom aktuell geöffneten Chart ab? So dass der EA automatisch erkennt, ob es 2 oder 4 Nachkommastellen sind?

S. AutoSL-Funktion()

Code:
//+------------------------------------------------------------------+
//|                                                Overwatch_0.1.mq4 |
//|                                                                   |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "XX"
#property link      ""
#property version   "0.4"
#property strict



//+------------------------------------------------------------------+
//| Variablendefinitionen                                            |
//+------------------------------------------------------------------+
datetime LastActiontime;                  //Variable für Once-Per-Bar-Aktion
int x ;                                   //Platzhalter für OrderSend
double StopSumme = 0;                     //Variable für StopSumme
static bool flag_notification = false;    //flag für Bericht


//+------------------------------------------------------------------+
//| Unterprogramme                                                   |
//+------------------------------------------------------------------+
   void Testorders()
   {
    x=OrderSend(Symbol(),OP_BUY,0.01,Ask,500*Point,0,0,"",0);
    x=OrderSend(Symbol(),OP_SELL,0.01,Bid,500*Point,0,0,"",0);
   }
   
   void StopAddition()
   {
    if(Hour() == 17 && flag_notification == false)
    {
    for(int i=0;i<OrdersTotal();i++)
    {
     x=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
     if(OrderType() == OP_BUY)
     {
      StopSumme = StopSumme + ((OrderOpenPrice() - OrderStopLoss()) /Point /10);
     }
     if(OrderType() == OP_SELL)
     {
      StopSumme = StopSumme + ((OrderStopLoss() - OrderOpenPrice()) /Point /10);
     }
    }
    SendNotification("Gesamtrisiko: "+NormalizeDouble(StopSumme,3)+" Pips / " + OrdersTotal() + " offene Orders");
    Print("Gesamtrisiko: " + NormalizeDouble(StopSumme,3) + " Pips / " + OrdersTotal() + " offene Orders");
    StopSumme = 0;
    flag_notification = true;
    }
    if(Hour() == 22)       
    {
     flag_notification = false;
    }
   }

   void AutoSL()
   {
    for(int j=0;j<OrdersTotal();j++)
    {
     x=OrderSelect(j,SELECT_BY_POS,MODE_TRADES);
     if(OrderType() == OP_BUY && OrderStopLoss() == 0)
     {
      x=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() - 500 * Point,OrderTakeProfit(),0,0);
     }
     if(OrderType() == OP_SELL && OrderStopLoss() == 0)
     {
      x=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() + 500 * Point,OrderTakeProfit(),0,0);
     }
    }
   }
   
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  
    
   if(LastActiontime!=Time[0])
   {
    //Code to execute once in the bar START
    
    //Testorders();
    
    AutoSL(); //AutoStoploss
   
    StopAddition(); //StopAddition
    
    //Code to execute once in the bar ENDE
    LastActiontime=Time[0];
   }   
  }
//+------------------------------------------------------------------+
Danke für eure Hilfe!