存成 MQL5/Scripts/Lesson1ContractSpec.mq5,編譯,然後拖到任何一張圖表上。在 Experts 分頁讀輸出——這裡每一個數字都是券商專屬的,所以永遠不要硬編它們。
//+------------------------------------------------------------------+
//| Lesson 1 - Print the contract spec for the current symbol |
//+------------------------------------------------------------------+
#property copyright "Strategist Academy"
#property version "1.00"
void OnStart()
{
string sym = _Symbol;
double tickSize = SymbolInfoDouble(sym, SYMBOL_TRADE_TICK_SIZE);
double tickValue = SymbolInfoDouble(sym, SYMBOL_TRADE_TICK_VALUE);
double contract = SymbolInfoDouble(sym, SYMBOL_TRADE_CONTRACT_SIZE);
double volMin = SymbolInfoDouble(sym, SYMBOL_VOLUME_MIN);
double volStep = SymbolInfoDouble(sym, SYMBOL_VOLUME_STEP);
double volMax = SymbolInfoDouble(sym, SYMBOL_VOLUME_MAX);
long stopsLevel = SymbolInfoInteger(sym, SYMBOL_TRADE_STOPS_LEVEL);
double ask = SymbolInfoDouble(sym, SYMBOL_ASK);
double bid = SymbolInfoDouble(sym, SYMBOL_BID);
Print("=== ", sym, " contract spec ===");
Print("Digits: ", _Digits);
Print("Point: ", DoubleToString(_Point, _Digits));
Print("Tick size: ", DoubleToString(tickSize, _Digits));
Print("Tick value: ", DoubleToString(tickValue, 2), " (money per tick, per 1 lot)");
Print("Contract size: ", DoubleToString(contract, 2));
Print("Volume min/step/max: ", DoubleToString(volMin, 2), " / ",
DoubleToString(volStep, 2), " / ",
DoubleToString(volMax, 2));
Print("Stops level: ", stopsLevel, " points (minimum SL/TP distance)");
Print("Bid / Ask: ", DoubleToString(bid, _Digits), " / ", DoubleToString(ask, _Digits));
Print("Spread: ", DoubleToString((ask - bid) / _Point, 1), " points");
Print("Account leverage: ", (int)AccountInfoInteger(ACCOUNT_LEVERAGE));
}