等级: 免费版
- 注册:
- 2024-1-11
- 曾用名:
|
咨询下大佬,MT5的FVG指标改动金字塔指标后为什么一直错误呢?
是哪儿出了问题呢,请大佬帮忙修改下。
一、原代码
//+------------------------------------------------------------------+
//| Fair Value Gap Indicator |
//| Copyright 2024, Hieu Hoang |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, hieuhoangcntt@gmail.com"
#property indicator_chart_window
#property indicator_buffers 0
double _low, _high;
string object_names[];
datetime pre_time = 0;
const int bull = 5;
const int bear = 5;
int c_bull;
int c_bear;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool isGreenCandle(double open, double close)
{
return open < close;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool isRedCandle(double open, double close)
{
return !isGreenCandle(open, close);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool isBullFVG(int index,
const double &open[],
const double &high[],
const double &low[],
const double &close[])
{
if(isGreenCandle(open[index-1], close[index-1]) &&
high[index-2] < low[index] && high[index-2] < _low
)
return true;
return false;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool isBearFVG(int index,
const double &open[],
const double &high[],
const double &low[],
const double &close[])
{
if(isRedCandle(open[index-1], close[index-1]) &&
low[index-2] > high[index] && low[index-2] > _high
)
return true;
return false;
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void create_object(string name, color clrColor,const datetime time1, const datetime time2, const double low, const double high)
{
ArrayResize(object_names, ArraySize(object_names) + 1);
object_names[ArraySize(object_names) - 1] = name;
ObjectCreate(0, name, OBJ_RECTANGLE, 0, time1, low, time2, high);
ObjectSetInteger(0, name, OBJPROP_COLOR, clrColor);
ObjectSetInteger(0, name, OBJPROP_STYLE, STYLE_SOLID);
ObjectSetInteger(0, name, OBJPROP_FILL, true);
ObjectSetInteger(0, name, OBJPROP_RAY_RIGHT, true);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
if(pre_time == time[rates_total - 1])
return(rates_total);
pre_time = time[rates_total - 1];
delete_objects();
_low = low[rates_total - 1];
_high = high[rates_total - 1];
c_bull = 0;
c_bear = 0;
for(int i = rates_total - 2; i >= 2; i--)
{
_low = _low < low ? _low : low;
_high = _high > high ? _high: high;
if(c_bull < bull && isBullFVG(i, open, high, low, close))
{
create_object("Buy range " + high[i-2] + " ↗ " + low, clrBlue, time[i-2], time[rates_total-1], low, high[i-2]);
c_bull ++;
if(c_bull >= bull && c_bear >= bear)
break;
}
else if(c_bear < bear && isBearFVG(i, open, high, low, close))
{
create_object("Sell range " + low[i-2] + " ↘ " + high, clrRed, time[i-2], time[rates_total-1], high, low[i-2]);
c_bear ++;
if(c_bull >= bull && c_bear >= bear)
break;
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
void delete_objects()
{
for(int i = 0; i < ArraySize(object_names); i++)
ObjectDelete(0, object_names);
ArrayResize(object_names, 0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
pre_time = 0;
delete_objects();
}
//+------------------------------------------------------------------+
二、帮修改代码
// Fair Value Gap Indicator for Pyramid v7.20
// Converted from MT4
VARIABLE:
BullCount=0,
BearCount=0,
CurrentLow=0,
CurrentHigh=0,
PreTime=0,
i=0,
IsGreenCandle=False,
IsRedCandle=False,
IsBullFVG=False,
IsBearFVG=False;
CONST:
BullLimit=5,
BearLimit=5;
// 主程序
Begin
// 如果是新K线才开始计算
If Time[0] <> PreTime Then
Begin
PreTime := Time[0];
// 删除所有图形对象 - 金字塔v7.20使用DELETEDRAW(0)
DELETEDRAW(0);
CurrentLow := Low[0];
CurrentHigh := High[0];
BullCount := 0;
BearCount := 0;
// 从倒数第二根K线开始向前遍历
For i = BarCount - 2 DownTo 2 Do
Begin
// 更新当前最低价和最高价
If Low < CurrentLow Then CurrentLow := Low;
If High > CurrentHigh Then CurrentHigh := High;
// 判断是否为阳线
IsGreenCandle := Open[i-1] < Close[i-1];
// 判断是否为阴线
IsRedCandle := Open[i-1] > Close[i-1];
// 判断是否为看涨FVG
IsBullFVG := IsGreenCandle AND (High[i-2] < Low) AND (High[i-2] < CurrentLow);
// 判断是否为看跌FVG
IsBearFVG := IsRedCandle AND (Low[i-2] > High) AND (Low[i-2] > CurrentHigh);
// 检查看涨FVG
If BullCount < BullLimit And IsBullFVG Then
Begin
// 在金字塔中绘制矩形
DRAWRECTANGLE('BuyFVG_' + NumToStr(i, 0), 0, Time[i-2], Low, Time[BarCount-1], High[i-2], ColorBlue);
// 设置矩形属性
SETDRAWSTYLE('BuyFVG_' + NumToStr(i, 0), 0); // 实线
SETDRAWFILL('BuyFVG_' + NumToStr(i, 0), 1); // 填充
BullCount := BullCount + 1;
If BullCount >= BullLimit And BearCount >= BearLimit Then
Break;
End
// 检查看跌FVG
Else If BearCount < BearLimit And IsBearFVG Then
Begin
// 在金字塔中绘制矩形
DRAWRECTANGLE('SellFVG_' + NumToStr(i, 0), 0, Time[i-2], High, Time[BarCount-1], Low[i-2], ColorRed);
// 设置矩形属性
SETDRAWSTYLE('SellFVG_' + NumToStr(i, 0), 0); // 实线
SETDRAWFILL('SellFVG_' + NumToStr(i, 0), 1); // 填充
BearCount := BearCount + 1;
If BullCount >= BullLimit And BearCount >= BearLimit Then
Break;
End;
End;
End;
End;
// 指标卸载时清理对象
OnExit:
Begin
DELETEDRAW(0); // 删除所有图形对象
PreTime := 0;
End;
请问大佬,怎么修改呢
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?
x
|