MQL 到 Pine Script 的转换产生不同的结果
MQL to Pine Script conversion yields different results
我正在尝试将 MQL4 指标转换为 Pine 脚本,但它产生了完全不同的输出;指标值不匹配。
与 PineScript
相比,MQL4 指标线更平滑
MQL4 指标代码为
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Crimson
#property indicator_width1 2
extern int period = 20;
double Signal_Buffer[];
int init() {
IndicatorDigits( Digits + 4 );
IndicatorShortName("Indi (" + string(period) + ")");
SetIndexBuffer(0, Signal_Buffer);
SetIndexStyle(0, DRAW_LINE);
SetIndexLabel(0, "Indi (" + string(period) + ")");
return (0);
}
int start() {
int bars_loaded = IndicatorCounted();
if (bars_loaded > 0) bars_loaded--;
int total_bars = Bars - bars_loaded;
double current_high = 0;
double current_low = 0;
double high_low_median = 0;
double signal = 0;
double a = 0;
double b = 0;
for (int i = 0; i < total_bars; i++) {
current_high = High[iHighest(Symbol(), Period(), MODE_HIGH, period, i)];
current_low = Low[iLowest(Symbol(), Period(), MODE_LOW, period, i)];
high_low_median = (High[i] + Low[i]) / 2.0;
a = 0.66 * ( (high_low_median - current_low) / (current_high - current_low) - 0.5 ) + 0.67 * b;
a = MathMin( MathMax( a, -0.999 ), 0.999 );
Signal_Buffer[i] = MathLog( ( a + 1.0 ) / ( 1 - a ) ) / 2.0 + signal / 2.0;
b = a;
signal = Signal_Buffer[i];
}
return (0);
}
Pine 脚本代码是
//@version=5
indicator(title='Indi', shorttitle='Indi')
per = input.int( defval=20, title='Period', minval=1 )
a = 0.0
b = 0.0
signal = 0.0
h = ta.highest( high, per )
l = ta.lowest( low, per )
m = hl2
a := 0.66 * ( (m - l) / (h - l) - 0.5 ) + 0.67 * b
a := math.min( math.max( a, -0.999 ), 0.999 )
signal := math.log( ( a + 1.0 ) / ( 1 - a ) ) / 2.0 + signal / 2.0
b := a
plot( signal )
我认为您可能需要在这一行中将 b
替换为 nz(a[1]
:
a = 0.66 * ( (high_low_median - current_low) / (current_high - current_low) - 0.5 ) + 0.67 * b;
到
a = 0.66 * ( (high_low_median - current_low) / (current_high - current_low) - 0.5 ) + 0.67 * nz(a[1]);
我正在尝试将 MQL4 指标转换为 Pine 脚本,但它产生了完全不同的输出;指标值不匹配。 与 PineScript
相比,MQL4 指标线更平滑MQL4 指标代码为
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Crimson
#property indicator_width1 2
extern int period = 20;
double Signal_Buffer[];
int init() {
IndicatorDigits( Digits + 4 );
IndicatorShortName("Indi (" + string(period) + ")");
SetIndexBuffer(0, Signal_Buffer);
SetIndexStyle(0, DRAW_LINE);
SetIndexLabel(0, "Indi (" + string(period) + ")");
return (0);
}
int start() {
int bars_loaded = IndicatorCounted();
if (bars_loaded > 0) bars_loaded--;
int total_bars = Bars - bars_loaded;
double current_high = 0;
double current_low = 0;
double high_low_median = 0;
double signal = 0;
double a = 0;
double b = 0;
for (int i = 0; i < total_bars; i++) {
current_high = High[iHighest(Symbol(), Period(), MODE_HIGH, period, i)];
current_low = Low[iLowest(Symbol(), Period(), MODE_LOW, period, i)];
high_low_median = (High[i] + Low[i]) / 2.0;
a = 0.66 * ( (high_low_median - current_low) / (current_high - current_low) - 0.5 ) + 0.67 * b;
a = MathMin( MathMax( a, -0.999 ), 0.999 );
Signal_Buffer[i] = MathLog( ( a + 1.0 ) / ( 1 - a ) ) / 2.0 + signal / 2.0;
b = a;
signal = Signal_Buffer[i];
}
return (0);
}
Pine 脚本代码是
//@version=5
indicator(title='Indi', shorttitle='Indi')
per = input.int( defval=20, title='Period', minval=1 )
a = 0.0
b = 0.0
signal = 0.0
h = ta.highest( high, per )
l = ta.lowest( low, per )
m = hl2
a := 0.66 * ( (m - l) / (h - l) - 0.5 ) + 0.67 * b
a := math.min( math.max( a, -0.999 ), 0.999 )
signal := math.log( ( a + 1.0 ) / ( 1 - a ) ) / 2.0 + signal / 2.0
b := a
plot( signal )
我认为您可能需要在这一行中将 b
替换为 nz(a[1]
:
a = 0.66 * ( (high_low_median - current_low) / (current_high - current_low) - 0.5 ) + 0.67 * b;
到
a = 0.66 * ( (high_low_median - current_low) / (current_high - current_low) - 0.5 ) + 0.67 * nz(a[1]);