Don't understand the usage of CMoneyFixedRisk

 

Hello to all,

as I understand it, first I have to include and declare the class

#include <Expert\Money\MoneyFixedRisk.mqh>
CMoneyFixedRisk      risk;

I have to define the percentage that I want to risk in the method

void  Percent( 
   double  percent      // Risk percentage
   )

after that I expected the class to give me double values of lotsize that allow me to stay in that risk percentage, depending on whether I was planning on going short or long:

virtual double  CheckOpenLong( 
   double  price,     // Preis 
   double  sl         // Preis von Stop Loss 
   )

or

virtual double  CheckOpenShort( 
   double  price,     // Preis 
   double  sl         // Preis von Stop Loss 
   )


But it didn't seem to work in this code example:

#include <Expert\Money\MoneyFixedRisk.mqh>
CMoneyFixedRisk      risk;

input string magic_comment = "1133557";
int SL;
double Lots = 0.01;
int pos_max = 1;
double pct = 5.0;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit() {
//---
   risk.Percent(pct);
//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
//---

}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick() {
//---
   double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
   double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
   long stops_lvl = SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
   SL=stops_lvl*1.5;
   
   Print("stops_lvl: ",stops_lvl," SL= ",SL);
   
   
   double Lot_calc_long = risk.CheckOpenLong(1.1, (ask - SL * _Point));
   Print("Lot_calc_long: ", Lot_calc_long);
   
   double Lot_calc_short = risk.CheckOpenShort(1.1, (bid + SL * _Point));
   Print("Lot_calc_short: ", Lot_calc_short);
}

It only produces zeros.

money

I was also having trouble finding the respective passage that I needed in the article on CodeBase and I wasn't sure if I should post it there.

So why does it only produce  0.0 lots?

 

Illustrative examples:

Money Fixed Risk
Money Fixed Risk
  • www.mql5.com
An example for calculating the lot value in accordance with the risk per trade.
 
Yes, I'll go with the code that is there. My bad, this is what I get for making a habit of browsing on the phone...