Previous Next

GTrade.Init()

This function is used to prepare the data of GTrade.

The call must take place before the first call of a data-reading function.

void  GTrade.Init(
   string        symbol = NULL,             // Symbol
   GTradeRisks   RiskMode = RISK_FIXED,     // Risk in percent or money
   double        RiskPercent = 2,           // Value in percent at RISK_PERCENT
   double        RiskFixed = 50,            // Value in money at RISK_FIXED
   bool          RoundOutOfRange = false,   // Rounds when exceeding min lot and max lot (OWN RISK!)
   bool          ForceOpen = false,         // If margin is not enough, use maximum possible value (OWN RISK!)
   int           Leverage = -1              // Broker leverage
   );

Parameter

symbol

[in]  The symbol whose data the class should process.

RiskMode

[in]  The desired risk mode. RISK_PERCENT indicates that the risk should be calculated in percent of the current account size. RISK_FIXED sets the risk to a value in money.

RiskPercent

[in]  The desired risk in percent of the current account size.

RiskFixed

[in]  The desired value in percent if the RiskMode is set to RISK_PERCENT.

RoundOutOfRange

[in]  If the calculated order volume is greater or smaller than the broker's specification, this function rounds to the minimum or maximum values.

ForceOpen

[in]  If the margin for the calculated order volume is not sufficient, this function can execute a position with the maximum possible order volume. However, Leverage (the leverage) must be set to the correct value.

Leverage

[in]  The leverage of the broker. If -1, then the standard leverage transmitted by the broker is automatically determined. Attention: the leverage transmitted by the broker is often not maintained correctly or differs in different trading instruments. Please check the leverage values on the website of your broker and enter them manually here if necessary. E.g.: 500 for a leverage of 1:500.

Note

The .Init() function call can be made at any point in the code. It can also be used several times to change data during runtime. However, it is recommended to call it at least once in the OnInit().


Example:

//--- Include the Glib classes
#include <Glib.mqh>

//--- Create a pointer to an empty class object
GTrade *trade;


int OnInit ()
{
   //--- Assign the class to the empty class object
   trade = gTrade();

   //--- Initialize the class data
   trade.Init();

   return(INIT_SUCCEEDED);
}

void OnDeinit (const int reason)
{
   //--- Release memory when exiting
   delete trade;
}


See also

GTrade, GTrade.AddButton, GTrade.ChartEvent