引言
成交量加权移动平均(On-Balance Volume,OBV)是一种常用的技术分析工具,用于衡量市场情绪和成交量的变化。在MetaTrader 4(MT4)平台上,OBV指标可以通过编写源码来实现。本文将深入解析MT4 OBV源码指标,探讨其实战应用和优化技巧。
OBV指标原理
OBV指标通过计算成交量的累积变化来衡量市场趋势的强度。其基本原理是:当收盘价高于开盘价时,认为市场趋势向上,将成交量加到OBV指标上;当收盘价低于开盘价时,认为市场趋势向下,从OBV指标中减去成交量。
MT4 OBV源码解析
以下是一个简单的MT4 OBV源码示例:
”`pascal //+——————————————————————+ //| OBV.mq4 | //| Copyright 2019, MetaQuotes Software Corp. | //| https://www.mql5.com | //+——————————————————————+ #property strict
//+——————————————————————+ //| Expert initialization function | //+——————————————————————+ procedure OnInit(); begin // 设置OBV指标 Input(“Length”, 14); Input(“MA Period”, 14); Input(“Shift”, 0); Input(“MA Method”, 0); Input(“MA Price”, 3); Input(“PlotStyle”, 0); Input(“PlotColor”, colorRed); Input(“DrawStyle”, 0); Input(“DrawMode”, 0); Input(“DrawObjectColor”, colorRed); Input(“LabelColor”, colorRed); Input(“FontStyle”, 0); Input(“FontSize”, 8); Input(“FontName”, “Arial”); Input(“FontAngle”, 0); Input(“FontColor”, colorRed); Input(“FontTransparency”, 0); Input(“Label”, “OBV”); Input(“UseJapaneseMode”, false); Input(“UseOldVersion”, false); Input(“ShowInChart”, true); Input(“ShowInDataWindow”, true); Input(“ShowInTerminal”, true); Input(“UseExpertSuppression”, true); Input(“UseAllowExpertSuppression”, true); Input(“UseAllowOpenPriceAction”, true); Input(“UseAllowClosePriceAction”, true); Input(“UseAllowSlippage”, true); Input(“UseAllowPriceStep”, true); Input(“UseAllowTrailingStop”, true); Input(“UseAllowMagicNumber”, true); Input(“UseAllowAutoLeverage”, true); Input(“UseAllowDeleteTrade”, true); Input(“UseAllowModifyTrade”, true); Input(“UseAllowArrows”, true); Input(“UseAllowDot”, true); Input(“UseAllowLabel”, true); Input(“UseAllowGrid”, true); Input(“UseAllowFibonacci”, true); Input(“UseAllowGann”, true); Input(“UseAllowElliott”, true); Input(“UseAllowATR”, true); Input(“UseAllowIchimoku”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowBollinger”, true); Input(“UseAllowKeltner”, true); Input(“UseAllowEnvelopes”, true); Input(“UseAllowFisher”, true); Input(“UseAllowADX”, true); Input(“UseAllowAroon”, true); Input(“UseAllowMomentum”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllowStochastic”, true); Input(“UseAllowWillR”, true); Input(“UseAllowAverage”, true); Input(“UseAllowMA”, true); Input(“UseAllowVolume”, true); Input(“UseAllowOBV”, true); Input(“UseAllowMACD”, true); Input(“UseAllowFractals”, true); Input(“UseAllowParabolicSAR”, true); Input(“UseAllowBillWilliamsR”, true); Input(“UseAllowBollingerBands”, true); Input(“UseAllowIchimokuCloud”, true); Input(“UseAllowKDJ”, true); Input(“UseAllowMFI”, true); Input(“UseAllowParabolic”, true); Input(“UseAllowRSI”, true); Input(“UseAllow
