Overview
PineCompat.mqh is a single include file for developers who port TradingView Pine Script indicators and strategies to MetaTrader 5. Each function keeps the meaning of its Pine counterpart, so a line such as up = ta.crossover(fast, slow) becomes bool up = Pine::Crossover(fast, slow, shift); and the MQL5 code can be compared with the Pine source line by line.
The package contains:
Conventions
Functions
na helpers
Crosses
Event memory
Highest / Lowest
Pivots
Change
Moving averages and oscillators (single value)
Whole-array versions for OnCalculate (incremental, pass prev_calculated)
Higher timeframe (request.security)
Checked against MT5 built-in indicators
Example
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#include <PineCompat.mqh>
double FastBuf[], SlowBuf[]; // two INDICATOR_DATA buffers, set as series in OnInit
int OnInit()
{
SetIndexBuffer(0, FastBuf, INDICATOR_DATA);
SetIndexBuffer(1, SlowBuf, INDICATOR_DATA);
ArraySetAsSeries(FastBuf, true);
ArraySetAsSeries(SlowBuf, true);
return(INIT_SUCCEEDED);
}
int OnCalculate(const int rates_total, const int prev_calculated,
const datetime &time[], const double &open[], const double &high[],
const double &low[], const double &close[], const long &tick_volume[],
const long &volume[], const int &spread[])
{
ArraySetAsSeries(close, true); // series order: 0 = newest bar
ArraySetAsSeries(high, true);
// fast = ta.ema(close, 9), slow = ta.ema(close, 21)
if(Pine::EmaOnArray(close, 9, FastBuf, rates_total, prev_calculated) == 0) return(0);
if(Pine::EmaOnArray(close, 21, SlowBuf, rates_total, prev_calculated) == 0) return(0);
// ta.crossover(fast, slow)[1] (evaluated on the last closed bar)
bool crossedUp = Pine::Crossover(FastBuf, SlowBuf, 1);
// ta.pivothigh(high, 5, 5)[1]: the pivot bar itself is 1 + 5 bars back
double ph = Pine::PivotHigh(high, 5, 5, 1);
if(!Pine::IsNa(ph))
{
// a pivot high was confirmed on bar 1
}
// request.security(syminfo.tickerid, "240", close[1], lookahead = barmerge.lookahead_on)
double h4Close = Pine::SecurityClose(_Symbol, PERIOD_H4, 1);
return(rates_total);
} The demo indicator (PineCompat_Demo.mq5) shows a complete example: RSI (ta.rsi), a signal EMA of the RSI (ta.ema), pivot dots (ta.pivothigh / ta.pivotlow drawn on the pivot bar), crossover arrows (ta.crossover / ta.crossunder) and a higher-timeframe RSI using the non-repainting Security mode.
Demo inputs: RSI length (14), Signal EMA length (9), Pivot left bars (5), Pivot right bars (5), Signals on closed bars only (true), Show higher-timeframe RSI (true), Higher timeframe (H4), Max higher-TF bars to load (5000).
The arrows and dots only show what the functions return. They are a coding example, not trade signals.
Notes
Disclaimer
PineCompat is a free programming example. It contains no trading method, gives no investment advice and does not suggest any result. Use it at your own responsibility.
TradingView and Pine Script are trademarks of TradingView, Inc. MetaTrader is a trademark of MetaQuotes Ltd. This project is not affiliated with or endorsed by either company.
VelaMayor MTF - Higher Timeframe Candle Overlay
カスタマイズ可能な実体、独立した枠線、正確なヒゲを備え、高時間足のローソク足を低時間足のチャートに直接重ねて表示できます。 画面を切り替えることなく、マクロ的なトレンドの方向性、セッションの始値、流動性の範囲を簡単に把握できます。 ボックス境界が分離された超軽量エンジンと、堅牢なチャート変更時の自動復旧機能を搭載しています。
Margin Risk Simulator
現在の銘柄について、口座がマージンコールおよびストップアウトに達する価格を表示します。また、取引量の増加を想定した「仮定モード」、追加可能な最大取引量、およびその過程で発動する指値注文についても表示されます。
Session Range Boxes - Asia, London, New York with breakout alerts
Draws the high/low range of up to three trading sessions (default Asia, London, New York) as boxes, with optional extended level lines, range-size labels and one-time breakout alerts. Display tool only - it does not trade.
EA Template - signal-agnostic MT5 Expert Advisor framework (risk sizing, SL and TP, trailing, filters)
A reusable Expert Advisor template for MT5. Write your own entry logic in one function (GetSignal returns +1, -1 or 0); the template handles lot sizing, SL/TP with stop-level checks, break-even, trailing stop, spread / time / weekday / news filters, order filling, retries and netting / hedging accounts. The included MA cross is an example signal only, not a trading strategy.