请高手帮忙改写一个MT4指标xSuperTrend candles (mtf)为MT5适用
我不懂MT5编程,想请各位高手帮忙改写一个指标, 我用CHATGPT4改写过,最终有一个错误解决不了。今天用国产AI,deepseek改写,也是没有解决。论坛中高手如云,或许可以帮忙看看。错误如下:'ATR'-wrong parameters count
是这一句出了问题:double atr = iATR(Symbol(), actualTimeFrame, period, i);// 修复 iATR 参数
先谢过热心的兄弟们,附上源码:
#property copyright "外汇EA之家,免费下载EA、指标"
#property link "http://www.eazhijia.com"
#property indicator_separate_window
#property indicator_buffers 9
#property indicator_color1LimeGreen//clrBlue
#property indicator_color2clrRed
#property indicator_color3LimeGreen//clrBlue
#property indicator_color4clrRed
#property strict
//
//
//
//
//
input ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Time frame
input int period = 10; // Super trend period
input double multiplier = 1.7; // Super trend multiplier原周期为3.0
input int WickWidth = 1; // Candle wick width
input int BodyWidth = 2; // If auto width = false then use this
input bool UseAutoWidth = true; // Auto adjust candle body width
double valhu[], valhd[], valhbu[], valhbd[], Up[], Dn[], valc[], Trend[], count[];
string indicatorFileName;
int candlewidth = 0;
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
int OnInit()
{
if (UseAutoWidth)
{
int scale = (int)ChartGetInteger(0, CHART_SCALE);
switch (scale)
{
case 0: candlewidth = 1; break;
case 1: candlewidth = 1; break;
case 2: candlewidth = 2; break;
case 3: candlewidth = 3; break;
case 4: candlewidth = 6; break;
case 5: candlewidth = 14; break;
}
}
else { candlewidth = BodyWidth; }
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
//IndicatorBuffers(9);
SetIndexBuffer(0, valhu, INDICATOR_DATA);
PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_HISTOGRAM);
PlotIndexSetInteger(0, PLOT_LINE_WIDTH, WickWidth);
SetIndexBuffer(1, valhd, INDICATOR_DATA);
PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_HISTOGRAM);
PlotIndexSetInteger(1, PLOT_LINE_WIDTH, WickWidth);
SetIndexBuffer(2, valhbu, INDICATOR_DATA);
PlotIndexSetInteger(2, PLOT_DRAW_TYPE, DRAW_HISTOGRAM);
PlotIndexSetInteger(2, PLOT_LINE_WIDTH, candlewidth);
SetIndexBuffer(3, valhbd, INDICATOR_DATA);
PlotIndexSetInteger(3, PLOT_DRAW_TYPE, DRAW_HISTOGRAM);
PlotIndexSetInteger(3, PLOT_LINE_WIDTH, candlewidth);
SetIndexBuffer(4, Trend, INDICATOR_CALCULATIONS);
SetIndexBuffer(5, Up, INDICATOR_CALCULATIONS);
SetIndexBuffer(6, Dn, INDICATOR_CALCULATIONS);
SetIndexBuffer(7, valc, INDICATOR_CALCULATIONS);
SetIndexBuffer(8, count, INDICATOR_CALCULATIONS);
indicatorFileName = __FILE__;
return (INIT_SUCCEEDED);
}
void OnDeinit(const int reason) { }
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
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[])
{
int i, counted_bars = prev_calculated;
if (counted_bars < 0) return (-1);
if (counted_bars > 0) counted_bars--;
int limit = rates_total - counted_bars;
ENUM_TIMEFRAMES actualTimeFrame = TimeFrame;// 使用临时变量
if (actualTimeFrame < _Period) {
actualTimeFrame = _Period;// 如果需要调整时间框架
}
if (TimeFrame != _Period)
{
limit = (int)MathMax(limit, MathMin(rates_total - 1, rates_total * (int)TimeFrame / (int)_Period));
for (i = limit; i >= 0 && !IsStopped(); i--)
{
int y = iBarShift(NULL, TimeFrame, time);
valc = iCustom(NULL, TimeFrame, indicatorFileName, period, multiplier, WickWidth, BodyWidth, UseAutoWidth, 7, y);
if (valc == 1)
{
valhu = high;
valhd = low;
valhbu = MathMax(open, close);
valhbd = MathMin(open, close);
}
if (valc == -1)
{
valhu = low;
valhd = high;
valhbu = MathMin(open, close);
valhbd = MathMax(open, close);
}
}
return (rates_total);
}
//
//
//
//
//
for (i = limit; i >= 0; i--)
{
double atr = iATR(Symbol(), actualTimeFrame, period, i);// 修复 iATR 参数
double cprice = close;
double mprice = (high + low) / 2;
Up = mprice + multiplier * atr;
Dn = mprice - multiplier * atr;
//
//
//
//
//
valc = (i < rates_total - 1) ? (cprice > Up) ? 1 : (cprice < Dn) ? -1 : valc : 0;
if (valc == 1) { Dn = MathMax(Dn, Dn); Trend = Dn; }
if (valc == -1) { Up = MathMin(Up, Up); Trend = Up; }
if (valc == 1)
{
valhu = high;
valhd = low;
valhbu = MathMax(open, close);
valhbd = MathMin(open, close);
}
if (valc == -1)
{
valhu = low;
valhd = high;
valhbu = MathMin(open, close);
valhbd = MathMax(open, close);
}
}
return (rates_total);
}
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//
string sTfTable[] = { "M1","M5","M15","M30","H1","H4","D1","W1","MN" };
int iTfTable[] = { 1,5,15,30,60,240,1440,10080,43200 };
string timeFrameToString(int tf)
{
for (int i = ArraySize(iTfTable) - 1; i >= 0; i--)
if (tf == iTfTable) return (sTfTable);
return ("");
}
看看这个能不能用上 我这个是主图K线变色的指标,因为用习惯了,想在MT5上也用它,不管怎么说,谢谢了
页:
[1]