### Get Order String Property (MT5) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Trading-snippets Retrieves string properties of an order in MT5. It takes an order property identifier as input. Example: `OrderGetString(ORDER_SYMBOL)`. ```MQL5 OrderGetString(|ORDER_SYMBOL,ORDER_COMMENT,ORDER_EXTERNAL_ID|) ``` -------------------------------- ### Get Order Double Property (MT5) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Trading-snippets Retrieves double-precision floating-point properties of an order in MT5. It takes an order property identifier as input. Example: `OrderGetDouble(ORDER_VOLUME_INITIAL)`. ```MQL5 OrderGetDouble(|ORDER_VOLUME_INITIAL,ORDER_VOLUME_CURRENT,ORDER_PRICE_OPEN,ORDER_SL,ORDER_TP,ORDER_PRICE_CURRENT,ORDER_PRICE_STOPLIMIT|) ``` -------------------------------- ### Get History Deal String Property (MT5) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Trading-snippets Retrieves string properties of a historical deal in MT5, identified by a ticket ID. It takes a deal property identifier as input. Example: `HistoryDealGetString(ticketId, DEAL_SYMBOL)`. ```MQL5 HistoryDealGetString(ticketId, |DEAL_SYMBOL,DEAL_COMMENT,DEAL_EXTERNAL_ID|) ``` -------------------------------- ### Get Position Double Property (MT5) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Trading-snippets Retrieves double-precision floating-point properties of a position in MT5. It takes a position property identifier as input. Example: `PositionGetDouble(POSITION_VOLUME)`. ```MQL5 PositionGetDouble(|POSITION_VOLUME,POSITION_PRICE_OPEN,POSITION_SL,POSITION_TP,POSITION_PRICE_CURRENT,POSITION_SWAP,POSITION_PROFIT|) ``` -------------------------------- ### Get MT5 Account String Values Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Account-properties Retrieves account information that is represented as a string. This includes details like account name, server name, currency, and company name. ```MQL5 AccountInfoString(ACCOUNT_NAME) AccountInfoString(ACCOUNT_SERVER) AccountInfoString(ACCOUNT_CURRENCY) AccountInfoString(ACCOUNT_COMPANY) ``` -------------------------------- ### Get Position String Property (MT5) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Trading-snippets Retrieves string properties of a position in MT5. It takes a position property identifier as input. Example: `PositionGetString(POSITION_SYMBOL)`. ```MQL5 PositionGetString(|POSITION_SYMBOL,POSITION_COMMENT,POSITION_EXTERNAL_ID|) ``` -------------------------------- ### Get Order Integer Property (MT5) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Trading-snippets Retrieves integer properties of an order in MT5. It takes an order property identifier as input. Example: `OrderGetInteger(ORDER_TICKET)`. ```MQL5 OrderGetInteger(|ORDER_TICKET,ORDER_TIME_SETUP,ORDER_TYPE,ORDER_STATE,ORDER_TIME_EXPIRATION,ORDER_TIME_DONE,ORDER_TIME_SETUP_MSC,ORDER_TIME_DONE_MSC,ORDER_TYPE_FILLING,ORDER_TYPE_TIME,ORDER_MAGIC,ORDER_REASON,ORDER_POSITION_ID,ORDER_POSITION_BY_ID|) ``` -------------------------------- ### Get Position Integer Property (MT5) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Trading-snippets Retrieves integer properties of a position in MT5. It takes a position property identifier as input. Example: `PositionGetInteger(POSITION_TICKET)`. ```MQL5 PositionGetInteger(|POSITION_TICKET,POSITION_TIME,POSITION_TIME_MSC,POSITION_TIME_UPDATE,POSITION_TIME_UPDATE_MSC,POSITION_TYPE,POSITION_MAGIC,POSITION_IDENTIFIER,POSITION_REASON|) ``` -------------------------------- ### Get History Deal Double Property (MT5) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Trading-snippets Retrieves double-precision floating-point properties of a historical deal in MT5, identified by a ticket ID. It takes a deal property identifier as input. Example: `HistoryDealGetDouble(ticketId, DEAL_VOLUME)`. ```MQL5 HistoryDealGetDouble(ticketId, |DEAL_VOLUME,DEAL_PRICE,DEAL_COMMISSION,DEAL_SWAP,DEAL_PROFIT,DEAL_FEE|) ``` -------------------------------- ### Get History Deal Integer Property (MT5) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Trading-snippets Retrieves integer properties of a historical deal in MT5, identified by a ticket ID. It takes a deal property identifier as input. Example: `HistoryDealGetInteger(ticketId, DEAL_TICKET)`. ```MQL5 HistoryDealGetInteger(ticketId, |DEAL_TICKET,DEAL_ORDER,DEAL_TIME,DEAL_TIME_MSC,DEAL_TYPE,DEAL_ENTRY,DEAL_MAGIC,DEAL_REASON,DEAL_POSITION_ID|) ``` -------------------------------- ### Get MT5 Account Server Name Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Account-properties Retrieves the name of the trading server the account is connected to. This is an analog to MT4's AccountServer() function. ```MQL5 AccountInfoString(ACCOUNT_SERVER) ``` -------------------------------- ### Get MT5 Account Leverage Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Account-properties Retrieves the leverage applied to the trading account. This is an analog to MT4's AccountLeverage() function. ```MQL5 AccountInfoInteger(ACCOUNT_LEVERAGE) ``` -------------------------------- ### Get MT5 Account Integer Values Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Account-properties Retrieves account information that is represented as an integer. This includes values like account login, trade mode, leverage, and trade allowance status. ```MQL5 AccountInfoInteger(ACCOUNT_LOGIN) AccountInfoInteger(ACCOUNT_TRADE_MODE) AccountInfoInteger(ACCOUNT_LEVERAGE) AccountInfoInteger(ACCOUNT_LIMIT_ORDERS) AccountInfoInteger(ACCOUNT_MARGIN_SO_MODE) AccountInfoInteger(ACCOUNT_TRADE_ALLOWED) AccountInfoInteger(ACCOUNT_TRADE_EXPERT) AccountInfoInteger(ACCOUNT_MARGIN_MODE) AccountInfoInteger(ACCOUNT_CURRENCY_DIGITS) AccountInfoInteger(ACCOUNT_FIFO_CLOSE) ``` -------------------------------- ### Get Ask Price Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Symbol-properties Retrieves the current ask price for the active trading symbol. The ask price is the price at which a seller is willing to sell the asset. ```MQL5 double askPrice = SymbolInfoDouble(Symbol(), SYMBOL_ASK); ``` -------------------------------- ### Get MT5 Account Name Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Account-properties Retrieves the name of the trading account. This is an analog to MT4's AccountName() function. ```MQL5 AccountInfoString(ACCOUNT_NAME) ``` -------------------------------- ### Get MT5 Account Double Values Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Account-properties Retrieves account information that is represented as a double-precision floating-point number. This includes financial values like balance, profit, equity, and margin details. ```MQL5 AccountInfoDouble(ACCOUNT_BALANCE) AccountInfoDouble(ACCOUNT_CREDIT) AccountInfoDouble(ACCOUNT_PROFIT) AccountInfoDouble(ACCOUNT_EQUITY) AccountInfoDouble(ACCOUNT_MARGIN) AccountInfoDouble(ACCOUNT_MARGIN_FREE) AccountInfoDouble(ACCOUNT_MARGIN_LEVEL.ACCOUNT_MARGIN_SO_CALL) AccountInfoDouble(ACCOUNT_MARGIN_SO_SO) AccountInfoDouble(ACCOUNT_MARGIN_INITIAL) AccountInfoDouble(ACCOUNT_MARGIN_MAINTENANCE) AccountInfoDouble(ACCOUNT_ASSETS) AccountInfoDouble(ACCOUNT_LIABILITIES) AccountInfoDouble(ACCOUNT_COMMISSION_BLOCKED) ``` -------------------------------- ### Symbol Information Retrieval (Double Properties) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Symbol-properties Provides a comprehensive way to get double-precision floating-point properties of a trading symbol. It supports a wide range of properties related to pricing, volume, and trading parameters. ```APIDOC SymbolInfoDouble(const string& symbol, ENUM_SYMBOL_PROPERTY_DOUBLE property) Description: Retrieves a double-precision floating-point property of a trading symbol. Parameters: symbol: The name of the trading symbol (e.g., "EURUSD"). If empty, the current symbol is used. property: An enumeration value specifying which property to retrieve. Common values include: - SYMBOL_BID: Current bid price. - SYMBOL_ASK: Current ask price. - SYMBOL_LAST: Last traded price. - SYMBOL_BIDHIGH: Highest bid price for the current day. - SYMBOL_BIDLOW: Lowest bid price for the current day. - SYMBOL_ASKHIGH: Highest ask price for the current day. - SYMBOL_ASKLOW: Lowest ask price for the current day. - SYMBOL_POINT: The value of one point in the quote currency. - SYMBOL_TRADE_TICK_VALUE: The value of a tick for the trade currency. - SYMBOL_TRADE_TICK_VALUE_PROFIT: The profit value of a tick for the trade currency. - SYMBOL_TRADE_TICK_VALUE_LOSS: The loss value of a tick for the trade currency. - SYMBOL_TRADE_TICK_SIZE: The size of a tick. - SYMBOL_TRADE_CONTRACT_SIZE: The contract size for trading. - SYMBOL_VOLUME_REAL: Real volume of the last trade. - SYMBOL_VOLUMEHIGH_REAL: Highest real volume for the current day. - SYMBOL_VOLUMELOW_REAL: Lowest real volume for the current day. - SYMBOL_SWAP_LONG: Swap value for long positions. - SYMBOL_SWAP_SHORT: Swap value for short positions. - SYMBOL_MARGIN_INITIAL: Initial margin for a trade. - SYMBOL_MARGIN_MAINTENANCE: Maintenance margin for a trade. - SYMBOL_PRICE_CHANGE: Price change for the current day. - SYMBOL_PRICE_VOLATILITY: Price volatility. - SYMBOL_PRICE_THEORETICAL: Theoretical price. - SYMBOL_PRICE_DELTA: Delta sensitivity. - SYMBOL_PRICE_THETA: Theta sensitivity. - SYMBOL_PRICE_GAMMA: Gamma sensitivity. - SYMBOL_PRICE_VEGA: Vega sensitivity. - SYMBOL_PRICE_RHO: Rho sensitivity. - SYMBOL_PRICE_OMEGA: Omega sensitivity. - SYMBOL_SESSION_VOLUME: Volume traded during the current session. - SYMBOL_SESSION_TURNOVER: Turnover during the current session. - SYMBOL_SESSION_INTEREST: Interest accrued during the current session. - SYMBOL_SESSION_BUY_ORDERS_VOLUME: Volume of buy orders in the session. - SYMBOL_SESSION_SELL_ORDERS_VOLUME: Volume of sell orders in the session. - SYMBOL_SESSION_OPEN: Opening price of the session. - SYMBOL_SESSION_CLOSE: Closing price of the session. - SYMBOL_SESSION_AW: Average weighted price of the session. - SYMBOL_SESSION_PRICE_SETTLEMENT: Settlement price of the session. - SYMBOL_SESSION_PRICE_LIMIT_MIN: Minimum price limit of the session. - SYMBOL_SESSION_PRICE_LIMIT_MAX: Maximum price limit of the session. - SYMBOL_MARGIN_HEDGED: Hedged margin. - SYMBOL_OPTION_STRIKE: Strike price for options. Returns: The requested double property value, or 0.0 if an error occurs. Example: double bid = SymbolInfoDouble(Symbol(), SYMBOL_BID); double ask = SymbolInfoDouble(Symbol(), SYMBOL_ASK); double point = SymbolInfoDouble(Symbol(), SYMBOL_POINT); ``` -------------------------------- ### Get Bid Price Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Symbol-properties Retrieves the current bid price for the active trading symbol. The bid price is the price at which a buyer is willing to purchase the asset. ```MQL5 double bidPrice = SymbolInfoDouble(Symbol(), SYMBOL_BID); ``` -------------------------------- ### CopyBuffer: Copy Indicator Data Buffer in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Copies data from a specified buffer of an indicator. This function is essential for retrieving calculated indicator values. It requires the indicator handle, buffer number, starting position or time, and the number of elements to copy. It returns the number of copied elements. ```MQL5 double buffer[count]; if (CopyBuffer(indicator_handle, buffer_num, start_pos_or_time, count, buffer) == count) { } ``` -------------------------------- ### Get MT5 Account Company Name Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Account-properties Retrieves the company name associated with the trading account. This is an analog to MT4's AccountCompany() function. ```MQL5 AccountInfoString(ACCOUNT_COMPANY) ``` -------------------------------- ### Find Lowest Value in Array (MQL5) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Streams Finds the index and value of the lowest element within a specified range of an array using the ArrayMinimum function. Requires an array, a starting index, and a count of elements to consider. ```MQL5 int lowestIndex = ArrayMinimum(array, start, count); double lowest = array[lowestIndex]; ``` -------------------------------- ### Find Highest Value in Array (MQL5) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Streams Finds the index and value of the highest element within a specified range of an array using the ArrayMaximum function. Requires an array, a starting index, and a count of elements to consider. ```MQL5 int highestIndex = ArrayMaximum(array, start, count); double highest = array[highestIndex]; ``` -------------------------------- ### Get Spread Value Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Symbol-properties Retrieves the current spread value for a given symbol. The spread is the difference between the ask and bid prices. This function is useful for understanding market liquidity and trading costs. ```MQL5 double spread = SymbolInfoInteger(symbol, SYMBOL_SPREAD); // Or for float precision: double spread_float = SymbolInfoDouble(symbol, SYMBOL_SPREAD_FLOAT); ``` -------------------------------- ### OnInit Function Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/General-purpose-snippets Inserts the OnInit function, which is executed once when an indicator or expert advisor is initialized. It includes logic for generating a unique prefix and setting indicator properties. ```MQL5 string IndicatorObjPrefix; bool NamesCollision(const string name) { for (int k = ObjectsTotal(0); k >= 0; k--) { if (StringFind(ObjectName(0, k), name) == 0) { return true; } } return false; } string GenerateIndicatorPrefix(const string target) { for (int i = 0; i < 1000; ++i) { string prefix = target + "_" + IntegerToString(i); if (!NamesCollision(prefix)) { return prefix; } } return target; } int OnInit(void) { IndicatorObjPrefix = GenerateIndicatorPrefix("123Patterns"); IndicatorSetString(INDICATOR_SHORTNAME, "123Patterns"); IndicatorSetInteger(INDICATOR_DIGITS, Digits()); return INIT_SUCCEEDED; } ``` -------------------------------- ### Create Text Object in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Objects Creates an OBJ_TEXT object in MQL5. It handles object creation, setting properties like font, size, color, and anchor, and updating the text content. ```MQL5 string id = IndicatorObjPrefix + "textId"; if (ObjectFind(chart_ID, id) == -1) { if (ObjectCreate(chart_ID, name, OBJ_TEXT, sub_window, time, price)) { ObjectSetString(chart_ID,name,OBJPROP_FONT,font); ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle); ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,|ANCHOR_LEFT_UPPER,ANCHOR_LEFT,ANCHOR_LEFT_LOWER,ANCHOR_LOWER,ANCHOR_RIGHT_LOWER,ANCHOR_RIGHT,ANCHOR_RIGHT_UPPER,ANCHOR_UPPER,ANCHOR_CENTER|); ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); } } ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); ``` -------------------------------- ### OnDeinit Function Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/General-purpose-snippets Inserts the OnDeinit function, which is executed when an indicator or expert advisor is removed from the chart or the terminal is closed. It handles cleanup tasks, such as deleting graphical objects. ```MQL5 void OnDeinit(const int reason) { ObjectsDeleteAll(0, IndicatorObjPrefix); } ``` -------------------------------- ### Create Arrow Stream (MQL5) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Streams Configures an indicator buffer to draw arrows. It sets the buffer as data, specifies the drawing type as an arrow, and sets an arrow shift. ```MQL5 SetIndexBuffer(id, buffer, INDICATOR_DATA); PlotIndexSetInteger(id, PLOT_DRAW_TYPE, DRAW_ARROW); PlotIndexSetInteger(id, PLOT_ARROW, code); PlotIndexSetInteger(id, PLOT_ARROW_SHIFT, 5); ``` -------------------------------- ### Create Color Stream (MQL5) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Streams Configures an indicator buffer to be used for color indexing. This is typically used to apply conditional coloring to chart elements based on indicator values. ```MQL5 SetIndexBuffer(id, stream, INDICATOR_COLOR_INDEX); ``` -------------------------------- ### MQL5: Create and Configure Rectangle Label Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Objects This MQL5 code snippet demonstrates the creation and configuration of a rectangle object on a MetaTrader 5 chart. It handles object existence checks, setting properties such as color, style, width, fill, and Z-order, and updating its coordinates using MQL5's object management functions. ```MQL5 string id = IndicatorObjPrefix + "textId"; if (ObjectFind(chart_ID, id) == -1) { if (ObjectCreate(chart_ID, id, OBJ_RECTANGLE, sub_window, time1, price1, time2, price2)) { ObjectSetInteger(chart_ID, id, OBJPROP_COLOR, clr); ObjectSetInteger(chart_ID, id, OBJPROP_STYLE, style); ObjectSetInteger(chart_ID, id, OBJPROP_WIDTH, width); ObjectSetInteger(chart_ID, id, OBJPROP_FILL, fill); ObjectSetInteger(chart_ID, id, OBJPROP_BACK, back); ObjectSetInteger(chart_ID, id, OBJPROP_SELECTABLE, selection); ObjectSetInteger(chart_ID, id, OBJPROP_SELECTED, selection); ObjectSetInteger(chart_ID, id, OBJPROP_HIDDEN, hidden); ObjectSetInteger(chart_ID, id, OBJPROP_ZORDER, z_order); } } ObjectSetInteger(chart_ID, id, OBJPROP_TIME, 0, time1); ObjectSetDouble(chart_ID, id, OBJPROP_PRICE, 0, price1); ObjectSetInteger(chart_ID, id, OBJPROP_TIME, 1, time2); ObjectSetDouble(chart_ID, id, OBJPROP_PRICE, 1, price2); ``` -------------------------------- ### OnCalculate Function Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/General-purpose-snippets Inserts the OnCalculate function, which is called for each new tick or bar. It handles calculations based on historical data and returns the number of bars calculated. ```MQL5 int OnCalculate(const int rates_total, // size of input time series const int prev_calculated, // number of handled bars at the previous call const datetime& time[], // Time array const double& open[], // Open array const double& high[], // High array const double& low[], // Low array const double& close[], // Close array const long& tick_volume[], // Tick Volume array const long& volume[], // Real Volume array const int& spread[] // Spread array ) { if (prev_calculated <= 0 || prev_calculated > rates_total) { ArrayInitialize(out, EMPTY_VALUE); } int first = 0; for (int pos = MathMax(first, prev_calculated - 1); pos < rates_total; ++pos) { int oldPos = rates_total - pos - 1; } return rates_total; ``` -------------------------------- ### OnTick Function Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/General-purpose-snippets Inserts the OnTick function, which is called every time a new tick arrives for the symbol the EA or indicator is attached to. It's the primary entry point for real-time processing. ```MQL5 void OnTick() { } ``` -------------------------------- ### Set Text Object Properties in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Objects Provides backward compatibility for setting text object properties, similar to MT4's ObjectSetText. It allows updating text, font, font size, and color of an object. ```MQL5 void ObjectSetText(string id, string text, int fontSize, string font, color clr) { ObjectSetString(0, id, OBJPROP_TEXT, text); ObjectSetString(0, id, OBJPROP_FONT, font); ObjectSetInteger(0, id, OBJPROP_FONTSIZE, fontSize); ObjectSetInteger(0, id, OBJPROP_COLOR, clr); } ``` -------------------------------- ### Configure Stream Properties (MQL5) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Streams Sets various properties for an indicator stream, including type, color, width, style, and label. These properties define how the stream is displayed on the chart. ```MQL5 #property indicator_type1 |DRAW_NONE,DRAW_LINE,DRAW_SECTION,DRAW_HISTOGRAM,DRAW_HISTOGRAM2,DRAW_ARROW,DRAW_ZIGZAG,DRAW_FILLING,DRAW_BARS,DRAW_CANDLES,DRAW_COLOR_LINE,DRAW_COLOR_SECTION,DRAW_COLOR_HISTOGRAM,DRAW_COLOR_HISTOGRAM2,DRAW_COLOR_ARROW,DRAW_COLOR_ZIGZAG,DRAW_COLOR_BARS,DRAW_COLOR_CANDLES| #property indicator_color1 RoyalBlue #property indicator_width1 1 #property indicator_style1 |STYLE_SOLID,STYLE_DASH,STYLE_DOT,STYLE_DASHDOT,STYLE_DASHDOTDOT| #property indicator_label1 "Name" ``` -------------------------------- ### Get MT5 Account Number (Login) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Account-properties Retrieves the unique account number (login ID) for the trading account. This is an analog to MT4's AccountNumber() function. ```MQL5 AccountInfoInteger(ACCOUNT_LOGIN) ``` -------------------------------- ### Create Rectangle Object in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Objects Creates an OBJ_RECTANGLE object in MQL5. It manages the creation of rectangles, setting properties such as color, style, width, fill, and position. ```MQL5 string id = IndicatorObjPrefix + "textId"; if (ObjectFind(chart_ID, id) == -1) { if (ObjectCreate(chart_ID, id, OBJ_RECTANGLE, sub_window, time1, price1, time2, price2)) { ObjectSetInteger(chart_ID, id, OBJPROP_COLOR, clr); ObjectSetInteger(chart_ID, id, OBJPROP_STYLE, style); ObjectSetInteger(chart_ID, id, OBJPROP_WIDTH, width); ObjectSetInteger(chart_ID, id, OBJPROP_FILL, fill); ObjectSetInteger(chart_ID, id, OBJPROP_BACK, back); ObjectSetInteger(chart_ID, id, OBJPROP_SELECTABLE, selection); ObjectSetInteger(chart_ID, id, OBJPROP_SELECTED, selection); ObjectSetInteger(chart_ID, id, OBJPROP_HIDDEN, hidden); ObjectSetInteger(chart_ID, id, OBJPROP_ZORDER, z_order); } } ObjectSetInteger(chart_ID, id, OBJPROP_TIME, 0, time1); ObjectSetDouble(chart_ID, id, OBJPROP_PRICE, 0, price1); ObjectSetInteger(chart_ID, id, OBJPROP_TIME, 1, time2); ObjectSetDouble(chart_ID, id, OBJPROP_PRICE, 1, price2); ``` -------------------------------- ### stochasticMT5: Create Stochastic Indicator in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Creates a Stochastic indicator handle. This function allows you to access the Stochastic oscillator's data. It requires symbol, timeframe, and parameters for K, D, and Slowing periods, along with mode and price types. ```MQL5 handle = iStochastic(_Symbol, _Period, stoch_k, stoch_d, stoch_slowing, |MODE_SMA,MODE_EMA,MODE_SMMA,MODE_LWMA|, |STO_LOWHIGH,STO_CLOSECLOSE|); ``` -------------------------------- ### createInternalStreamMT5: Create Internal Indicator Stream in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Sets up an internal data buffer for an indicator, typically used for calculations that are not directly plotted. This function is part of indicator buffer management. ```MQL5 SetIndexBuffer(id, stream, INDICATOR_CALCULATIONS); ``` -------------------------------- ### Define ENUM for Price Input Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Parameters Defines an enumeration for different price types used in input parameters. This ENUM specifies the possible values for price inputs in trading systems. ```mql5 input ENUM_APPLIED_PRICE price = |PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW,PRICE_MEDIAN,PRICE_TYPICAL,PRICE_WEIGHTED|; // Price type ``` -------------------------------- ### adMT5: Create AD Indicator in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Creates an Accumulation/Distribution (AD) indicator handle. AD relates the asset's closing price to its trading range over a period, using volume. It requires the symbol, timeframe, and volume type. ```MQL5 handle = iAD(_Symbol, _Period, |VOLUME_TICK,VOLUME_REAL|); ``` -------------------------------- ### CustomIndicator: Create Custom Indicator in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Creates a custom indicator using the iCustom function. This function allows integration of external custom indicators into your MQL5 programs. It requires the symbol, timeframe, indicator path, and parameters. ```MQL5 handle = iCustom(_Symbol, _Period, "::Indicators\indicatorName", params); ``` -------------------------------- ### MT5 Price Type Switch Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/General-purpose-snippets A switch statement for handling different price types (e.g., PRICE_CLOSE, PRICE_OPEN) in MT5. This is useful when selecting which price data to use for calculations or plotting. ```MQL5 switch (priceType) { case PRICE_CLOSE: break; case PRICE_OPEN: break; case PRICE_HIGH: break; case PRICE_LOW: break; case PRICE_MEDIAN: break; case PRICE_TYPICAL: break; case PRICE_WEIGHTED: break; } ``` -------------------------------- ### demarkerMT5: Create DeMarker Indicator in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Creates a DeMarker indicator handle. DeMarker is used to identify potential turning points in the market by measuring the likelihood of a reversal. It requires the symbol, timeframe, and period. ```MQL5 handle = iDeMarker(_Symbol, _Period, demarker_period); ``` -------------------------------- ### createStreamMT5: Create Indicator Data Plot Stream in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Configures a data stream for plotting on a chart and sets its visual properties. This includes defining the draw type, color, and label for the indicator's output. It uses SetIndexBuffer and PlotIndexSet functions. ```MQL5 SetIndexBuffer(id, stream, INDICATOR_DATA); PlotIndexSetInteger(id, PLOT_DRAW_TYPE, |DRAW_NONE,DRAW_LINE,DRAW_SECTION,DRAW_HISTOGRAM,DRAW_HISTOGRAM2,DRAW_ARROW,DRAW_ZIGZAG,DRAW_FILLING,DRAW_BARS,DRAW_CANDLES,DRAW_COLOR_LINE,DRAW_COLOR_SECTION,DRAW_COLOR_HISTOGRAM,DRAW_COLOR_HISTOGRAM2,DRAW_COLOR_ARROW,DRAW_COLOR_ZIGZAG,DRAW_COLOR_BARS,DRAW_COLOR_CANDLES|); PlotIndexSetInteger(id, PLOT_LINE_COLOR, clr); PlotIndexSetString(id, PLOT_LABEL, name); ``` -------------------------------- ### MT5 Plotting API Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/General-purpose-snippets Documentation for MT5 plotting functions, specifically `SetIndexBuffer` and `PlotIndexSetInteger`. These functions are used to define how indicator data is displayed on the chart. ```APIDOC SetIndexBuffer(int index, double& buffer[], int type) - Assigns a data buffer to an indicator's output line. - Parameters: - index: The index of the indicator's output line (0 to 7). - buffer[]: The array containing the data to be plotted. - type: The drawing type for the buffer (e.g., INDICATOR_DATA, DRAW_LINE). PlotIndexSetInteger(int index, int prop_id, int value) - Sets integer properties for an indicator's output line. - Parameters: - index: The index of the indicator's output line. - prop_id: The property to set (e.g., PLOT_DRAW_TYPE, PLOT_LINE_STYLE, PLOT_LINE_WIDTH, PLOT_SHIFT, PLOT_SHOW_DATA, PLOT_ARROW, PLOT_ARROW_SHIFT, PLOT_DRAW_BEGIN, PLOT_COLOR_INDEXES). - value: The integer value for the specified property. - Example Usage: SetIndexBuffer(id, stream, INDICATOR_DATA); PlotIndexSetInteger(id, PLOT_DRAW_TYPE, DRAW_LINE); PlotIndexSetInteger(id, PLOT_LINE_COLOR, clr); PlotIndexSetString(id, PLOT_LABEL, name); PlotIndexSetDouble(int index, int prop_id, double value) - Sets double properties for an indicator's output line. - Parameters: - index: The index of the indicator's output line. - prop_id: The property to set (e.g., PLOT_LINE_WIDTH). - value: The double value for the specified property. PlotIndexSetString(int index, int prop_id, string value) - Sets string properties for an indicator's output line. - Parameters: - index: The index of the indicator's output line. - prop_id: The property to set (e.g., PLOT_LABEL). - value: The string value for the specified property. ``` -------------------------------- ### StochasticOutput: Stochastic Indicator Output Streams in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Defines the possible output streams for a Stochastic indicator. These constants specify which line of the indicator (e.g., main line or signal line) is being referenced. ```MQL5 |MAIN_LINE,SIGNAL_LINE| ``` -------------------------------- ### bandsMT5: Create Bands Indicator in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Creates a Bollinger Bands indicator handle. Bollinger Bands consist of a middle band (a simple moving average) and two outer bands plotted at a standard deviation level. It requires symbol, timeframe, period, shift, deviation, and price type. ```MQL5 handle = iBands(_Symbol, _Period, bb_period, bb_shift, bb_deviation, |PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW,PRICE_MEDIAN,PRICE_TYPICAL,PRICE_WEIGHTED|); ``` -------------------------------- ### averagesMT5: Create Moving Average Indicator in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Creates a Moving Average (MA) indicator handle. This function supports various MA methods (SMA, EMA, SMMA, LWMA) and price types. It requires the symbol, timeframe, MA period, shift, method, and price type. ```MQL5 handle = iMA(_Symbol, _Period, ma_period, ma_shift, |MODE_SMA,MODE_EMA,MODE_SMMA,MODE_LWMA|, |PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW,PRICE_MEDIAN,PRICE_TYPICAL,PRICE_WEIGHTED|); ``` -------------------------------- ### cciMT5: Create CCI Indicator in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Creates a Commodity Channel Index (CCI) indicator handle. CCI measures the current price level relative to an average price level over a given period. It requires the symbol, timeframe, period, and price type. ```MQL5 handle = iCCI(_Symbol, _Period, mom_period, |PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW,PRICE_MEDIAN,PRICE_TYPICAL,PRICE_WEIGHTED|); ``` -------------------------------- ### Symbol Information Retrieval (Integer Properties) Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Symbol-properties Allows retrieval of integer-based properties for a trading symbol. This includes various flags, modes, and count-based information relevant to symbol trading and display. ```APIDOC SymbolInfoInteger(const string& symbol, ENUM_SYMBOL_PROPERTY_INTEGER property) Description: Retrieves an integer property of a trading symbol. Parameters: symbol: The name of the trading symbol (e.g., "EURUSD"). If empty, the current symbol is used. property: An enumeration value specifying which property to retrieve. Common values include: - SYMBOL_DIGITS: Number of digits after the decimal point. - SYMBOL_SPREAD: Current spread in points (integer part). - SYMBOL_SPREAD_FLOAT: Current spread in fractional points (double). - SYMBOL_VOLUME: Volume of the last trade (integer part). - SYMBOL_VOLUMEHIGH: Highest volume for the current day (integer part). - SYMBOL_VOLUMELOW: Lowest volume for the current day (integer part). - SYMBOL_TRADE_MODE: Trading mode of the symbol. - SYMBOL_TRADE_CALC_MODE: Calculation mode for trading operations. - SYMBOL_TRADE_STOPS_LEVEL: Minimum distance for Stop Loss and Take Profit levels. - SYMBOL_TRADE_FREEZE_LEVEL: Minimum distance for order modification. - SYMBOL_EXPIRATION_TIME: Expiration time of the contract. - SYMBOL_SWAP_MODE: Swap calculation mode. - SYMBOL_SWAP_ROLLOVER3DAYS: Number of days for swap rollover. - SYMBOL_FILLING_MODE: Order filling mode. - SYMBOL_ORDER_MODE: Order execution mode. - SYMBOL_ORDER_GTC_MODE: Good 'til canceled order mode. - SYMBOL_OPTION_MODE: Option trading mode. - SYMBOL_OPTION_RIGHT: Option right (call/put). - SYMBOL_CUSTOM: Indicates if the symbol is custom. - SYMBOL_EXIST: Indicates if the symbol exists. - SYMBOL_SELECT: Indicates if the symbol is selected. - SYMBOL_VISIBLE: Indicates if the symbol is visible in Market Watch. - SYMBOL_SESSION_DEALS: Number of deals in the current session. - SYMBOL_SESSION_BUY_ORDERS: Number of buy orders in the current session. - SYMBOL_SESSION_SELL_ORDERS: Number of sell orders in the current session. - SYMBOL_TIME: Time of the last tick. - SYMBOL_TIME_MSC: Time of the last tick in milliseconds. - SYMBOL_TICKS_BOOKDEPTH: Tick book depth. - SYMBOL_TRADE_EXEMODE: Execution mode for trades. - SYMBOL_EXPIRATION_MODE: Expiration mode for contracts. - SYMBOL_SECTOR: Sector of the symbol. - SYMBOL_INDUSTRY: Industry of the symbol. - SYMBOL_CHART_MODE: Chart display mode. - SYMBOL_BACKGROUND_COLOR: Background color of the chart. - SYMBOL_MARGIN_HEDGED_USE_LEG: Use of hedged margin for legs. Returns: The requested integer property value, or 0 if an error occurs. Example: int digits = SymbolInfoInteger(Symbol(), SYMBOL_DIGITS); int tradeMode = SymbolInfoInteger(Symbol(), SYMBOL_TRADE_MODE); ``` -------------------------------- ### rsiMT5: Create RSI Indicator in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Creates a Relative Strength Index (RSI) indicator handle. RSI is a momentum oscillator measuring the speed and change of price movements. It requires the symbol, timeframe, RSI period, and price type. ```MQL5 handle = iRSI(_Symbol, _Period, rsi_period, |PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW,PRICE_MEDIAN,PRICE_TYPICAL,PRICE_WEIGHTED|); ``` -------------------------------- ### atrMT5: Create ATR Indicator in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Creates an Average True Range (ATR) indicator handle. ATR measures market volatility. This function requires the symbol, timeframe, and the period for calculation. ```MQL5 handle = iATR(_Symbol, _Period, length); ``` -------------------------------- ### momentumMT5: Create Momentum Indicator in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Creates a Momentum indicator handle. Momentum measures the rate of price change. It requires the symbol, timeframe, momentum period, and price type. ```MQL5 handle = iMomentum(_Symbol, _Period, mom_period, |PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW,PRICE_MEDIAN,PRICE_TYPICAL,PRICE_WEIGHTED|); ``` -------------------------------- ### osmaMT5: Create OsMA Indicator in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Creates an Oscillator Moving Average (OsMA) indicator handle. OsMA is the difference between the MACD line and its signal line. It requires the symbol, timeframe, fast EMA period, slow EMA period, signal period, and price type. ```MQL5 handle = iOsMA(_Symbol, _Period, fast_ema_period, slow_ema_period, signal_period, |PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW,PRICE_MEDIAN,PRICE_TYPICAL,PRICE_WEIGHTED|); ``` -------------------------------- ### adxMT5: Create ADX Indicator in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Creates an Average Directional Movement Index (ADX) indicator handle. ADX is used to quantify trend strength. It requires the symbol, timeframe, and the ADX period. ```MQL5 handle = iADX(_Symbol, _Period, adx_period); ``` -------------------------------- ### MT5 Symbol Pip Size Calculation Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/General-purpose-snippets Calculates the pip size for the current trading symbol in MT5. This is essential for position sizing and risk management, accounting for different digit counts. ```MQL5 double point = SymbolInfoDouble(_Symbol, SYMBOL_POINT); int digit = (int)SymbolInfoInteger(_Symbol, SYMBOL_DIGITS); int mult = digit == 3 || digit == 5 ? 10 : 1; double pipSize = point * mult; ``` -------------------------------- ### sarMT5: Create PSAR Indicator in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Creates a Parabolic SAR (Stop and Reverse) indicator handle. PSAR is a trend-following indicator used to identify potential reversals. It requires the symbol, timeframe, step, and maximum values. ```MQL5 handle = iSAR(_Symbol, _Period, step, maximum); ``` -------------------------------- ### macdMT5: Create MACD Indicator in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Creates a Moving Average Convergence Divergence (MACD) indicator handle. MACD is a trend-following momentum indicator. It requires the symbol, timeframe, fast EMA period, slow EMA period, signal period, and price type. ```MQL5 handle = iMACD(_Symbol, _Period, fast_ema_period, slow_ema_period, signal_period, |PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW,PRICE_MEDIAN,PRICE_TYPICAL,PRICE_WEIGHTED|); ``` -------------------------------- ### Variance and StDev Calculation Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/General-purpose-snippets Provides functions to calculate the variance and standard deviation of a data series over a specified period. These are common statistical functions used in technical analysis. ```MQL5 double StDev(double& data[], int period, int pos) { return MathSqrt(Variance(data, period, pos)); } double Variance(double& data[], int period, int pos) { double sum = 0; double ssum = 0; for (int i = 0; i < period; i++) { sum += data[pos - i]; ssum += MathPow(data[pos - i], 2); } return (ssum * period - sum * sum) / (period * (period - 1)); ``` -------------------------------- ### Create Trend Object in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Objects Creates an OBJ_TREND object in MQL5. This function is used to draw trend lines, configuring properties like color, style, width, and ray extensions. ```MQL5 string id = IndicatorObjPrefix + "textId"; if (ObjectFind(chart_ID, id) == -1) { if (ObjectCreate(chart_ID, id, OBJ_TREND, sub_window, time1, price1, time2, price2)) { ObjectSetInteger(chart_ID, id, OBJPROP_COLOR, clr); ObjectSetInteger(chart_ID, id, OBJPROP_STYLE, style); ObjectSetInteger(chart_ID, id, OBJPROP_WIDTH, width); ObjectSetInteger(chart_ID, id, OBJPROP_FILL, fill); ObjectSetInteger(chart_ID, id, OBJPROP_BACK, back); ObjectSetInteger(chart_ID, id, OBJPROP_SELECTABLE, selection); ObjectSetInteger(chart_ID, id, OBJPROP_SELECTED, selection); ObjectSetInteger(chart_ID, id, OBJPROP_RAY_LEFT, ray_left); ObjectSetInteger(chart_ID, id, OBJPROP_RAY_RIGHT, ray_right); ObjectSetInteger(chart_ID, id, OBJPROP_HIDDEN, hidden); ObjectSetInteger(chart_ID, id, OBJPROP_ZORDER, z_order); } } ObjectSetInteger(chart_ID, id, OBJPROP_TIME, 0, time1); ObjectSetDouble(chart_ID, id, OBJPROP_PRICE, 0, price1); ObjectSetInteger(chart_ID, id, OBJPROP_TIME, 1, time2); ObjectSetDouble(chart_ID, id, OBJPROP_PRICE, 1, price2); ``` -------------------------------- ### wprMT5: Create WPR Indicator in MQL5 Source: https://github.com/sibvic/vsc-mq5-snippets/wiki/Working-with-indicators Creates a Williams' Percent Range (WPR) indicator handle. WPR is a momentum indicator that measures overbought and oversold levels. It requires the symbol, timeframe, and calculation period. ```MQL5 handle = iWPR(_Symbol, _Period, calc_period); ```