Previous Next

GTrade

The class GTrade gives you the possibility to carry out the most common trading actions extremely easily.


Create and destroy the class

To create the class and destroy it when the program ends, there are 5 simple steps. You can see these steps in the example.

Example:

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

//--- Generation of 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)
{
   //--- Free memory on closing
   delete trade;
}

From this point on you can use the class functions.


Class Functions

Return value

Function call

Function

void

Init()

Initialization of the class default data. Set the preferences for the class to work with.

int

Open()

Opens a trade. Only a stoploss value is necessary. Other values are optional.

int

CloseAllOnSymbol()

Closes all open positions on a symbol.

int

CloseWithComment()

Closes all positions with a specific comment on a symbol.

int

MoveStopLoss()

Moves all StopLoss of the positions on a symbol.

int

MoveStopLossWithComment()

Moves all StopLoss of the positions with a certain comment on a symbol.

double

OpenStopLoss()

Returns the stop loss of the last open and open position on a symbol.

double

OpenStopLossWithComment()

Returns the stop loss of the last open and open position with a comment on a symbol.

double

TradeProfit()

Returns the current profit or loss of the last opened and open position on a symbol.

double

TradeProfitWithComment()

Returns the current profit or loss of the last opened and open position with annotation on a symbol.

double

TradeOpenPrice()

Returns the opening price of the last opened and open position on a symbol.

GDirections

TradeDirection()

Returns the trade direction of the last opened and open position on a symbol.

int

TradesOnSymbol()

Returns how many open positions are on a symbol.

int

TradesOnSymbolDirection()

Returns how many open positions in a given direction are on a symbol.

double

LastTradeProfit()

Returns the profit of the last closed position.

datetime

LastTradeDate()

Returns the opening date of the last closed position.

void

CalculateCRV()

Draws the Chance-Risk-Value on the chart in conjunction with quick trade lines.

double

CalculateCRV()

Returns the Chance-Risk-Value.

void

AddButton()

Automatically generates a Quick Trade button with the specified values.

void

ChartEvent()

Sets the chart events to break down the class and to increase clarity in the chart.


Enumerations of the class

GTradeRisks

Identifier

Description

RISK_PERCENT

Indication of the risk in percent.

RISK_FIXED

Expressing the risk as a fixed value of a currency.