Probleme bei der richtigen Kalkulation des Risikos

 

Hallo allerseits,

ich code grade weiter an meinem EA und komme an einer Stelle einfach nicht zu einer gut funktionierenden & allgemein gültigen Lösung.

Es geht dabei darum, dass ich die Lot Size basierend auf dem eingestellten Risiko kalkulieren möchte.

So weit so gut habe ich das gecoded und für das Paar GBP USD beispielsweise funktioniert das tadellos. 1% Risiko = 1000 Dollar.

Im Backtest ist mir aber jetzt aufgefallen, dass das für andere Forex Paare, wie z.B. CHF JPY plötzlich nicht mehr funktioniert und das Risiko falsch kalkuliert ist.
Das Problem liegt meiner Auffassung nach in der tick Größe und dem Tick Volumen, welches ich mir wie im Bild gezeigt ausgeben lassen habe.

Ich komme aber trotz Recherche auf keine Lösung, wodurch sich das Problem beheben lässt und ich das Risiko für verschiedene Forex Märkte und Indizes einstellen kann.

Daher die Frage, ob jemand von euch mit helfen kann?

Ich wäre sehr Dankbar.

Viele Grüße und einen schönen Sonntag.


Edit:
GBP USD = tick size 0.00001, tick value 0.912
CHF JPY = tick size 0.001, tick value 1.0
US100 = tick size 0.1, tick value = 0.1

Dateien:
9.png  55 kb
8.png  11 kb
4.png  8 kb
7.png  6 kb
6.png  15 kb
5.png  15 kb
 

Das ist doch ein ganz fundamentales Problem für das es hunderte Lösungen gibt!

Such mal in der Codebase nach lot calculation: https://www.mql5.com/en/search#!keyword=lot%20calculation&module=mql5_module_codebase

Es gibt fast nichts, was nicht schon für MT4/5 programmiert wurde => Suchen und kopieren ist schneller als programmieren!

 

Hallo zusammen,

ist schon ein älteres Problem, aber ich werde bisschen Behilflich sein.

Der Kode kommt noch vom MQL4, aber den habe ich an MQL5 angepasst.

Hier ist ein Beispiel Kode:

//+------------------------------------------------------------------+
//|                                          Lot Calculate.mq5       |
//|                              Copyright 2025, MetaQuotes Ltd.     |
//|                                            https://www.mql5.com  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

input double  Risiko    = 1.00;  // Risiko in Prozent
input int     StopLoss  = 100;   // Stopp Loss in punkten (keine Pips!)
input bool    BuyOrder  = true;  // Art der Position Buy
input bool    SellOrder = false; // Art der Position Sell

static double lot = 0;

int OnInit() {

   return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason) {

// Löschen des Kommentares auf dem Chart!
Comment("");
}

void OnTick() {

// Ausgabe auf dem Chart und im Jornal
   if(BuyOrder == true){
   lot = DoubleToString(LotsByRisk(ORDER_TYPE_BUY,Risiko,(int)StopLoss),2);
   }else{
   lot = DoubleToString(LotsByRisk(ORDER_TYPE_SELL,Risiko,(int)StopLoss),2);
   }
   Comment("\n\nVolumen: "+lot); // Ausgabe auf dem Chart
   Print("Volumen: "+lot);       // Ausgabe im Jornal


}

//+------------------------------------------------------------------+
//| Funktion für Volumenberechnung in Prozent                        |
//+------------------------------------------------------------------+
double LotsByRisk(int op_type,double risk,int sloss) {

   double  lot_min = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
   double  lot_max = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
   double lot_step = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
   double  lotcost = ((SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE)*_Point)/(SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE)));
   lot = 0.0;
   double UsdPerPip = 0.0;

   lot = AccountInfoDouble(ACCOUNT_BALANCE)*risk/100;
   UsdPerPip = lot/sloss;
   if(UsdPerPip <= 0.0)
      return(0);
   lot = NormalizeDouble(UsdPerPip/lotcost, 2);
   if(lot <= 0.0)
      return(0);
   lot = NormalizeDouble(lot/lot_step, 0) * lot_step;
   if(lot < lot_min)
      lot = lot_min;
   if(lot > lot_max)
      lot = lot_max;
   return(lot);
}

Habe nicht getestet, müsste aber funktionieren.

Gruß Igor