What are Expert Magic Numbers?

Expert magic numbers are ids given to a particular expert advisor.

Care should be taken to ensure the ids are unique.

This is because the magic number is used by the MetaTrader back end to know which expert advisor to send information to. For example, when a trade notification is received, MetaTrader will have stamped the order with the expert advisor’s magic number, and it therefore knows which expert advisor to send the trade notification to.

It can therefore also be used to find out which expert advisor sent a particular order.

Advertisements

CSymbolInfo: obtain information about a symbol

To obtain information about a symbol, create a CSymbolInfo instance, and set it’s Name.

I’ve create a quick utility class which prints out all the members of the CSymbolInfo class:

#include <Trade/SymbolInfo.mqh>
#include "SymbolCalcMode.mqh"

struct SymbolInfo
{
    static void Print(const CSymbolInfo& symbol)
    {
        Print("Name: " + symbol.Name());
        Print("Selected in market watch: " + IntegerToString(symbol.Select()));
        Print("Synchronised: " + IntegerToString(symbol.IsSynchronized()));
        Print("Volume: " + IntegerToString(symbol.Volume()));
        Print("VolumeHigh: " + IntegerToString(symbol.VolumeHigh()));
        Print("VolumeLow: " + IntegerToString(symbol.VolumeLow()));
        Print("Time: " + TimeToString(symbol.Time()));
        Print("Spread: " + IntegerToString(symbol.Spread()));
        Print("SpreadFloat: " + IntegerToString(symbol.SpreadFloat()));
        Print("TicksBookDepth: " + IntegerToString(symbol.TicksBookDepth()));
        Print("StopsLevel: " + IntegerToString(symbol.StopsLevel()));
        Print("FreezeLevel: " + IntegerToString(symbol.FreezeLevel()));
        Print("Bid: " + DoubleToString(symbol.Bid()));
        Print("BidHigh: " + DoubleToString(symbol.BidHigh()));
        Print("BidLow: " + DoubleToString(symbol.BidLow()));
        Print("Ask: " + DoubleToString(symbol.Ask()));
        Print("AskHigh: " + DoubleToString(symbol.AskHigh()));
        Print("AskLow: " + DoubleToString(symbol.AskLow()));
        Print("Last: " + DoubleToString(symbol.Last()));
        Print("LastHigh: " + DoubleToString(symbol.LastHigh()));
        Print("LastLow: " + DoubleToString(symbol.LastLow()));
        Print("TradeCalcMode: " + SymbolCalcMode::ToString(symbol.TradeCalcMode()));
        Print("TradeCalcModeDesc: " + symbol.TradeCalcModeDescription());
        Print("MarginFormula: " + SymbolCalcMode::MarginFormula(symbol.TradeCalcMode()));
        Print("ProfitFormula: " + SymbolCalcMode::ProfitFormula(symbol.TradeCalcMode()));
        Print("TradeMode: " + IntegerToString(symbol.TradeMode()));
        Print("TradeModeDesc: " + symbol.TradeModeDescription());
        Print("TradeExecution: " + IntegerToString(symbol.TradeExecution()));
        Print("TradeExecutionDesc: " + symbol.TradeExecutionDescription());
        Print("SwapMode: " + IntegerToString(symbol.SwapMode()));
        Print("SwapModeDesc: " + symbol.SwapModeDescription());
        Print("SwapRollover3days: " + IntegerToString(symbol.SwapRollover3days()));
        Print("SwapRollover3daysDes: " + symbol.SwapRollover3daysDescription());
        Print("MarginInitial: " + DoubleToString(symbol.MarginInitial()));
        Print("MarginMaintenance: " + DoubleToString(symbol.MarginMaintenance()));
        Print("MarginLong: " + DoubleToString(symbol.MarginLong()));
        Print("MarginShort: " + DoubleToString(symbol.MarginShort()));
        Print("MarginLimit: " + DoubleToString(symbol.MarginLimit()));
        Print("MarginStop: " + DoubleToString(symbol.MarginStop()));
        Print("MarginStopLimit: " + DoubleToString(symbol.MarginStopLimit()));
        Print("TradeTimeFlags: " + IntegerToString(symbol.TradeTimeFlags()));
        Print("TradeFillFlags: " + IntegerToString(symbol.TradeFillFlags()));
        Print("Digits: " + IntegerToString(symbol.Digits()));
        Print("Point: " + DoubleToString(symbol.Point()));
        Print("TickValue: " + DoubleToString(symbol.TickValue()));
        Print("TickValueProfit: " + DoubleToString(symbol.TickValueProfit()));
        Print("TickValueLoss: " + DoubleToString(symbol.TickValueLoss()));
        Print("TickSize: " + DoubleToString(symbol.TickSize()));
        Print("ContractSize: " + DoubleToString(symbol.ContractSize()));
        Print("LotsMin: " + DoubleToString(symbol.LotsMin()));
        Print("LotsMax: " + DoubleToString(symbol.LotsMax()));
        Print("LotsStep: " + DoubleToString(symbol.LotsStep()));
        Print("LotsLimit: " + DoubleToString(symbol.LotsLimit()));
        Print("SwapLong: " + DoubleToString(symbol.SwapLong()));
        Print("SwapShort: " + DoubleToString(symbol.SwapShort()));
        Print("CurrencyBase: " + symbol.CurrencyBase());
        Print("CurrencyProfit: " + symbol.CurrencyProfit());
        Print("CurrencyMargin: " + symbol.CurrencyMargin());
        Print("Bank: " + symbol.Bank());
        Print("Description: " + symbol.Description());
        Print("Path: " + symbol.Path());
        Print("SessionDeals: " + IntegerToString(symbol.SessionDeals()));
        Print("SessionBuyOrders: " + IntegerToString(symbol.SessionBuyOrders()));
        Print("SessionSellOrders: " + IntegerToString(symbol.SessionSellOrders()));
        Print("SessionTurnover: " + DoubleToString(symbol.SessionTurnover()));
        Print("SessionInterest: " + DoubleToString(symbol.SessionInterest()));
        Print("SessionBuyOrdersVolume: " + DoubleToString(symbol.SessionBuyOrdersVolume()));
        Print("SessionSellOrdersVolume: " + DoubleToString(symbol.SessionSellOrdersVolume()));
        Print("SessionOpen: " + DoubleToString(symbol.SessionOpen()));
        Print("SessionClose: " + DoubleToString(symbol.SessionClose()));
        Print("SessionAW: " + DoubleToString(symbol.SessionAW()));
        Print("SessionPriceSettlement: " + DoubleToString(symbol.SessionPriceSettlement()));
        Print("SessionPriceLimitMin: " + DoubleToString(symbol.SessionPriceLimitMin()));
        Print("SessionPriceLimitMax: " + DoubleToString(symbol.SessionPriceLimitMax()));
    }
};

It uses another small utility class for printing out the symbol calculation mode

struct SymbolCalcMode
{
    static string ToString(int id)
    {
        switch (id)
        {
            case SYMBOL_CALC_MODE_FOREX:       return "Forex mode";
            case SYMBOL_CALC_MODE_FUTURES:     return "Futures mode";
            case SYMBOL_CALC_MODE_CFD:         return "CFD  mode";
            case SYMBOL_CALC_MODE_CFDINDEX:    return "CFD Index mode";
            case SYMBOL_CALC_MODE_CFDLEVERAGE: return "CFD Leverage mode";
        }
        return "unknown " + IntegerToString(id);
    }
    static string MarginFormula(int id)
    {
        switch (id)
        {
            case SYMBOL_CALC_MODE_FOREX:       return "lots * contract_size / leverage";
            case SYMBOL_CALC_MODE_FUTURES:     return "lots * initial_margin * percentage / 100";
            case SYMBOL_CALC_MODE_CFD:         return "lots * contract_size * market_price * percentage / 100";
            case SYMBOL_CALC_MODE_CFDINDEX:    return "(lots * contract_size * market_price) * tick_price / tick_size";
            case SYMBOL_CALC_MODE_CFDLEVERAGE: return "(lots * contract_size * market_price * percentage) / leverage";
        }
        return "unknown " + IntegerToString(id);
    }
    static string ProfitFormula(int id)
    {
        switch (id)
        {
            case SYMBOL_CALC_MODE_FOREX:       return "(close_price - open_price) * contract_size * lots";
            case SYMBOL_CALC_MODE_FUTURES:     return "(close_price - open_price) * tick_price / tick_size * lots";
            case SYMBOL_CALC_MODE_CFD:         return "(close_price - open_price) * contract_size * lots";
            case SYMBOL_CALC_MODE_CFDINDEX:    return "(close_price - open_price) * contract_size * lots";
            case SYMBOL_CALC_MODE_CFDLEVERAGE: return "(close_price - open_price) * contract_size * lots";
        }
        return "unknown " + IntegerToString(id);
    }
};

Here I initialise an object with the current symbol and display the details in the OnInit method of an expert advisor.

#include "../../Include/SymbolInfo.mqh"
#include <Trade/SymbolInfo.mqh>

int OnInit()
{
    CSymbolInfo symbol;
    symbol.Name(_Symbol);
    SymbolInfo::Print(symbol);
    
    return INIT_SUCCEEDED;
}