Get trade volume given entry price and stoploss using CheckOpenLong

brettles  

Hi there,

Pretty standard question I'm sure but the answer seems to allude me.  I'm trying to calculate trade volume as a percentage of account equity given a specified entry price and stoploss.

#include<Trade\Trade.mqh>
#include <Expert\Money\MoneyFixedRisk.mqh>

CTrade trade;
CMoneyFixedRisk m_money;

double risk_percent = 2; // have also tried with 0.02 with same result in console.

void OnInit()
 {
  double entry_level = GetEntryLevel();
  double initial_stoploss = GetInitialStopLossLevel();
  double profit_target = GetProfitTarget(entry_level, initial_stoploss);
  m_money.Percent(risk_percent);
  double trade_volume = m_money.CheckOpenLong(entry_level, initial_stoploss);
  Print("entry: ", entry_level);
  Print("initial stoploss: ", initial_stoploss);
  Print("Vol: ", trade_volume);
 }

But trade_volume = 0.0.


How do I get the desired value for trade_volume please?

Thanks.

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Account Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Account Properties
  • www.mql5.com
Account Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
brettles  
Is this something I need to pay someone to help me with?
Reason: