Files
xMQL5/BKPS/XEU5 14022022/Libraries/x-saherelm.models.lib.mq5
T
2024-01-25 04:09:42 +03:30

439 lines
13 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Models Library
// ---------------------------------------
// Name: XModels
// Description: provides all required models ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// START Inputs ...
//
//
// END Inputs ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Provided Functions ...
//
//
// How To Calculate Static Volume ...
enum ENUM_STATIC_VOLUME_METHODS
{
//
// Based On Deposit ...
X_STATIC_VOLUME_BASED_ON_DEPOSIT,
//
// Based On Balance ...
X_STATIC_VOLUME_BASED_ON_BALANCE,
};
//
// START Model Definitions ...
//
//
// OHCL Candel Model ...
enum ENUM_X_PRICE
{
X_PRICE_HIGH,
X_PRICE_OPEN,
X_PRICE_CLOSE,
X_PRICE_LOW
};
//
// Describe an Specific Candle ...
struct XOHCL
{
double high;
double open;
double close;
double low;
};
//
// Swing Types Enum ...
enum ENUM_X_SWING_TYPE
{
X_NO_SWING = 0,
X_SWING_HIGH = 1,
X_SWING_LOW = -1,
};
//
// XTrader Execution Signal Result ...
enum ENUM_EXECUTION_SIGNAL_RESULT
{
//
X_TRADER_UNKNOWN_ERROR,
X_TRADER_SUCCEED_EXECUTION,
X_TRADER_INVALID_SIGNAL_ERROR,
X_TRADER_NOT_ENOUGH_EQUITY_ERROR,
X_TRADER_MAX_TRADES_REACHED_ERROR,
X_TRADER_NOT_ENOUGH_BALANCE_ERROR,
X_TRADER_NOT_ENOUGH_MARIGIN_ERROR
//
};
//
// Signal Types ...
enum ENUM_X_SIGNAL_TYPE
{
X_SIGNAL_LONG,
X_SIGNAL_SHORT,
X_SIGNAL_UNKNOWN,
};
//
// Signal Structure ...
struct XSignal
{
//
// Identifier ...
ulong id;
//
// Which Symbol used for Signal ...
string symbol;
//
// Which Type of operations ...
ENUM_X_SIGNAL_TYPE type;
//
// Magic Number ...
ulong magicNumber;
//
// Ticket ...
ulong ticket;
//
// Entry/Open Price ...
double entry;
//
// TP ...
double tp;
//
// SL ...
double sl;
//
// Make Risk Free Trade on this Value if provided ...
double riskFreeStep;
//
// a Multiplier for determines how much trade volume exit on risk free time ...
double riskFreeRate;
//
// Trade Profit ...
double profit;
//
// Time of Operation ...
datetime time;
//
// Volume ...
double volume;
//
// Comment ...
string comment;
};
//
// Signal Additional Info ...
struct XProvidedSignal
{
//
// Suggested TP ...
double tp;
//
// Suggested SL ...
double sl;
//
// Signallers ...
string signallers[];
};
//
// Model Specific Deal ...
struct XDeal
{
//
// the ID of the Expert Advisor, that executed the deal ...
ulong magic;
//
// the ID of position, in which the deal was involved ...
ulong positionId;
//
// Ticket ...
ulong ticket;
//
// the name of the deal symbol ...
string symbol;
//
// order by which the deal is executed ...
ulong order;
//
// the time of deal execution ...
datetime time;
//
// Deal price ...
double price;
//
// the financial result of the deal (in deposit currency) ...
double profit;
//
// the amount of swap when position is closed ...
double swap;
//
// the amount of commission of the deal ...
double commission;
//
// the volume of deal ...
double volume;
//
// the deal comment ...
string comment;
//
// the deal type ...
// ------------------------------------------------------------------
// DEAL_TYPE_BUY => Buy ...
// DEAL_TYPE_SELL => Sell ...
// DEAL_TYPE_BUY_CANCELED => Canceled buy deal ...
// There can be a situation when a previously executed buy deal is canceled. In this case,
// the type of the previously executed deal (DEAL_TYPE_BUY) is changed to DEAL_TYPE_BUY_CANCELED,
// and its profit/loss is zeroized. Previously obtained profit/loss is charged/withdrawn using a separated balance operation ...
//
// DEAL_TYPE_SELL_CANCELED => Canceled sell deal ...
// There can be a situation when a previously executed sell deal is canceled. In this case,
// the type of the previously executed deal (DEAL_TYPE_SELL) is changed to DEAL_TYPE_SELL_CANCELED,
// and its profit/loss is zeroized. Previously obtained profit/loss is charged/withdrawn using a separated balance operation
//
// DEAL_TYPE_BALANCE => Balance ...
// DEAL_TYPE_CREDIT => Credit ...
// DEAL_TYPE_CHARGE => Additional charge ...
// DEAL_TYPE_CORRECTION => Correction ...
// DEAL_TAX => Tax charges ...
// DEAL_TYPE_BONUS => Bonus ...
// DEAL_TYPE_INTEREST => Interest rate ...
// DEAL_DIVIDEND => Dividend operations...
// DEAL_DIVIDEND_FRANKED => Franked (non-taxable) dividend operations ...
// DEAL_TYPE_COMMISSION => Additional commission ...
// DEAL_TYPE_COMMISSION_DAILY => Daily commission ...
// DEAL_TYPE_COMMISSION_MONTHLY => Monthly commission ...
// DEAL_TYPE_COMMISSION_AGENT_DAILY => Daily agent commission ...
// DEAL_TYPE_COMMISSION_AGENT_MONTHLY => Monthly agent commission
ENUM_DEAL_TYPE type;
//
// the deal direction ...
// ----------------------------------
// DEAL_ENTRY_IN => Entry in ...
// DEAL_ENTRY_OUT => Entry out ...
// DEAL_ENTRY_INOUT => Reverse ...
// DEAL_ENTRY_OUT_BY => Close a position by an opposite one ...
ENUM_DEAL_ENTRY entry;
//
// deal reson ...
// ---------------------
// DEAL_REASON_SL => The deal was executed as a result of Stop Loss activation ...
// DEAL_REASON_TP => The deal was executed as a result of Take Profit activation ...
// DEAL_REASON_SO => The deal was executed as a result of the Stop Out event ...
// DEAL_REASON_WEB => The deal was executed as a result of activation of an order placed from the web platform ...
// DEAL_REASON_SPLIT => The deal was executed after the split (price reduction) of an instrument, which had an open position during split announcement ...
// DEAL_REASON_CLIENT => The deal was executed as a result of activation of an order placed from a desktop terminal ...
// DEAL_REASON_MOBILE => The deal was executed as a result of activation of an order placed from a mobile application ...
// DEAL_REASON_EXPERT => The deal was executed as a result of activation of an order placed from an MQL5 program, i.e. an Expert Advisor or a script ...
// DEAL_REASON_VMARGIN => The deal was executed after charging the variation margin ...
// DEAL_REASON_ROLLOVER => The deal was executed due to a rollover ...
ENUM_DEAL_REASON reason;
};
//
// Model Specific Order ...
struct XOrder
{
//
// the ID of expert that placed the order ...
ulong magic;
//
// the ID of position ...
ulong positionId;
//
// the name of order symbol ...
string symbol;
//
// the ticket of an order, previously selected for access ...
ulong ticket;
//
// the time of order placement ...
datetime timeSetup;
//
// the time of order execution or cancellation ...
datetime timeDone;
//
// the order expiration time ...
datetime timeExpiration;
//
// the order price ...
double priceOpen;
//
// the current price by order symbol ...
double priceCurrent;
//
// the price of a pending order ...
double priceStopLimit;
//
// the order's Stop Loss ...
double stopLoss;
//
// the order's Take Profit ...
double takeProfit;
//
// the initial volume of order ...
double volumeInitial;
//
// the unfilled volume of order ...
double volumeCurrent;
//
// the order comment ...
string comment;
//
// the order type ...
// --------------------
// ORDER_TYPE_BUY => Market Buy order ...
// ORDER_TYPE_SELL => Market Sell order ...
// ORDER_TYPE_BUY_LIMIT => Buy Limit pending order ...
// ORDER_TYPE_SELL_LIMIT => Sell Limit pending order ...
// ORDER_TYPE_BUY_STOP => Buy Stop pending order ...
// ORDER_TYPE_SELL_STOP => Sell Stop pending order ...
// ORDER_TYPE_BUY_STOP_LIMIT => Upon reaching the order price, a pending Buy Limit order is placed at the StopLimit price ...
// ORDER_TYPE_SELL_STOP_LIMIT => Upon reaching the order price, a pending Sell Limit order is placed at the StopLimit price ...
// ORDER_TYPE_CLOSE_BY => Order to close a position by an opposite one ...
ENUM_ORDER_TYPE type;
//
// the order state ...
// --------------------------
// ORDER_STATE_STARTED => Order checked, but not yet accepted by broker ...
// ORDER_STATE_PLACED => Order accepted ...
// ORDER_STATE_CANCELED => Order canceled by client ...
// ORDER_STATE_PARTIAL => Order partially executed ...
// ORDER_STATE_FILLED => Order fully executed ...
// ORDER_STATE_REJECTED => Order rejected ...
// ORDER_STATE_EXPIRED => Order expired ...
// ORDER_STATE_REQUEST_ADD => Order is being registered (placing to the trading system)
// ORDER_STATE_REQUEST_MODIFY => Order is being modified (changing its parameters) ...
// ORDER_STATE_REQUEST_CANCEL => Order is being deleted (deleting from the trading system) ...
ENUM_ORDER_STATE state;
//
// the order filling type ...
// ----------------------------
// ORDER_FILLING_FOK => Fill or Kill
// An order can be executed in the specified volume only.
// If the necessary amount of a financial instrument is currently unavailable in the market,
// the order will not be executed.
// The desired volume can be made up of several available offers.
// The possibility of using FOK orders is determined at the trade server.
// ORDER_FILLING_IOC => Immediate or Cancel
// A trader agrees to execute a deal with the volume maximally available in the market within that indicated in the order.
// If the request cannot be filled completely, an order with the available volume will be executed,
// and the remaining volume will be canceled.
// The possibility of using IOC orders is determined at the trade server.
// ORDER_FILLING_BOC => Passive (Book or Cancel)
// The BoC order assumes that the order can only be placed in the Depth of Market and cannot be immediately executed.
// If the order can be executed immediately when placed, then it is canceled.
// In fact, the BOC policy guarantees that the price of the placed order will be worse than
// the current market. BoC orders are used to implement passive trading,
// so that the order is not executed immediately when placed and does not affect current liquidity.
// Only limit and stop limit orders are supported (ORDER_TYPE_BUY_LIMIT, ORDER_TYPE_SELL_LIMIT, ORDER_TYPE_BUY_STOP_LIMIT, ORDER_TYPE_SELL_STOP_LIMIT).
// ORDER_FILLING_RETURN => Return
// In case of partial filling, an order with remaining volume is not canceled but processed further.
// Return orders are not allowed in the Market Execution
// mode (market execution — SYMBOL_TRADE_EXECUTION_MARKET).
ENUM_ORDER_TYPE_FILLING typeFilling;
//
// the type of order at the time of the expiration ...
// --------------------------------------------------------
// ORDER_TIME_GTC => Good till cancel order ...
// ORDER_TIME_DAY => Good till current trade day order ...
// ORDER_TIME_SPECIFIED => Good till expired order ...
// ORDER_TIME_SPECIFIED_DAY => The order will be effective till 23:59:59 of the specified day.
// If this time is outside a trading session, the order expires in the nearest trading time ...
ENUM_ORDER_TYPE_TIME typeTime;
//
// The reason for order placing ...
// --------------------------------------
// ORDER_REASON_SL => The order was placed as a result of Stop Loss activation ...
// ORDER_REASON_TP => The order was placed as a result of Take Profit activation ...
// ORDER_REASON_SO => The order was placed as a result of the Stop Out event ...
// ORDER_REASON_WEB => The order was placed from a web platform ...
// ORDER_REASON_CLIENT => The order was placed from a desktop terminal ...
// ORDER_REASON_MOBILE => The order was placed from a mobile application ...
// ORDER_REASON_EXPERT => The order was placed from an MQL5-program, i.e. by an Expert Advisor or a script ...
ENUM_ORDER_REASON reason;
};
//
// END Provided Functions ...
//