很棒的指标!我使用缓冲区创建了同样的指标,有没有办法绘制每天的支撑位和阻力位,而不是只有当天的支撑位和阻力位?
这是我目前的版本。但我找不到为每个"当前时间框架"条形图获取 10 天的日线条形图的方法......
//+------------------------------------------------------------------+ //|B_ATR_Levels.mq5 //+------------------------------------------------------------------+ #property copyright "Skullnick" #property link "https://www.mql5.com" #property version "1.00" //--- 指标绘图设置 #property indicator_chart_window #property indicator_buffers 6 #property indicator_plots 6 #property indicator_type1 DRAW_LINE #property indicator_color1 clrDeepSkyBlue #property indicator_width1 1 #property indicator_label1 "Resistance 1" #property indicator_style1 STYLE_DASH #property indicator_type2 DRAW_LINE #property indicator_color2 clrDeepSkyBlue #property indicator_width2 1 #property indicator_label2 "Resistance 2" #property indicator_style2 STYLE_DASH #property indicator_type3 DRAW_LINE #property indicator_color3 clrDeepSkyBlue #property indicator_width3 1 #property indicator_label3 "Resistance 3" #property indicator_style3 STYLE_DASH #property indicator_type4 DRAW_LINE #property indicator_color4 clrOrangeRed #property indicator_width4 1 #property indicator_label4 "Support 1" #property indicator_style4 STYLE_DASH #property indicator_type5 DRAW_LINE #property indicator_color5 clrOrangeRed #property indicator_width5 1 #property indicator_label5 "Support 2" #property indicator_style5 STYLE_DASH #property indicator_type6 DRAW_LINE #property indicator_color6 clrOrangeRed #property indicator_width6 1 #property indicator_label6 "Support 3" #property indicator_style6 STYLE_DASH //--- 输入 input int inpAtrPeriod = 21; // ATR 期间 //--- 指示器缓冲区 double ExtR1Buffer[]; double ExtR2Buffer[]; double ExtR3Buffer[]; double ExtS1Buffer[]; double ExtS2Buffer[]; double ExtS3Buffer[]; // 平均真实范围权重 double dWeights[]; // 全局变量 double dATR = 0; double dPreviousClose = 0; //+------------------------------------------------------------------+ //| 自定义指示器初始化函数 //+------------------------------------------------------------------+ int OnInit() { //--- 指示器缓冲区映射 SetIndexBuffer(0,ExtR1Buffer, INDICATOR_DATA); // 阻力 1 级 SetIndexBuffer(1,ExtR2Buffer, INDICATOR_DATA); // 阻力 2 级 SetIndexBuffer(2,ExtR3Buffer, INDICATOR_DATA); // 阻力 3 级 SetIndexBuffer(3,ExtS1Buffer, INDICATOR_DATA); // 1 级支持 SetIndexBuffer(4,ExtS2Buffer, INDICATOR_DATA); // 支持级别 2 SetIndexBuffer(5,ExtS3Buffer, INDICATOR_DATA); // 支持级别 3 ArraySetAsSeries(ExtR1Buffer, true); ArraySetAsSeries(ExtR2Buffer, true); ArraySetAsSeries(ExtR3Buffer, true); ArraySetAsSeries(ExtS1Buffer, true); ArraySetAsSeries(ExtS2Buffer, true); ArraySetAsSeries(ExtS3Buffer, true); // 调整权重 ArrayResize(dWeights, inpAtrPeriod); // 设置平滑 double dSmoothing = 2.0 / (ArraySize(dWeights) + 1); // 重量计算 for(int i = 0; i < ArraySize(dWeights); i++) dWeights[i] = dSmoothing * MathPow(1 - dSmoothing, i); //--- 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[]) { //--- // 获取每日数据并检查数据是否充足 MqlRates oDailyRates[]; ArraySetAsSeries(oDailyRates, true); int iLast = 0; if(prev_calculated == 0) iLast = rates_total - 1; else iLast = rates_total - prev_calculated; //--- 计算水位 for(int i = iLast; i >= 0 && !IsStopped();i--) { int iNumDaysCopied = CopyRates(_Symbol, PERIOD_D1, 1, inpAtrPeriod + 1, oDailyRates); if(iNumDaysCopied >= (inpAtrPeriod+1) && bIsNewDay() == true) { // 计算当天的 ATR dATR = dCalculateATR(oDailyRates); dPreviousClose = oDailyRates[0].close; } ExtR1Buffer[i] = dPreviousClose + 0.5 * dATR; ExtR2Buffer[i] = dPreviousClose + 0.75 * dATR; ExtR3Buffer[i] = dPreviousClose + 1.0 * dATR; ExtS1Buffer[i] = dPreviousClose - 0.5 * dATR; ExtS2Buffer[i] = dPreviousClose - 0.75 * dATR; ExtS3Buffer[i] = dPreviousClose - 1.0 * dATR; } //--- 为下一次调用返回 prev_calculated 的值 return(rates_total); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| 计算 ATR| //+------------------------------------------------------------------+ double dCalculateATR(const MqlRates &oRates[]) { double dValue = 0; int iIndex = 0; for (int i = 0; i < ArraySize(dWeights); i++) { double dHL = oRates[i].high - oRates[i].low; double dHCp = MathAbs(oRates[i].high - oRates[i+1].close); double dLCp = MathAbs(oRates[i].low - oRates[i+1].close); double dTR = MathMax(MathMax(dHL, dHCp),dLCp); dValue += dTR * dWeights[iIndex]; iIndex++; } return dValue; } //----------------------------- // -- 检查新的一天 //----------------------------- bool bIsNewDay(void) { bool bNewDay = false; static datetime oDateOld; datetime oDateNew[1]; MqlDateTime oStructDateOld; MqlDateTime oStructDateNew; // 将当前时间数组复制到 New_Time 中 int iCopyHandle = CopyTime(_Symbol, PERIOD_D1, 0, 1, oDateNew); TimeToStruct(oDateNew[0] , oStructDateNew); TimeToStruct(oDateOld , oStructDateOld); // 如果复制成功 if(iCopyHandle>0) { // 如果新的一天 if(oStructDateNew.day != oStructDateOld.day) { bNewDay = true; oDateOld = oDateNew[0]; } } return bNewDay; }
请给我一个 mt4 版本。
xy618z 水平线 改为短水平线,只显示右侧。
您好
您可以尝试使用
ObjectCreate(0,_name,OBJ_HLINE,0,0,0);
和开始时间 + 'n' 作为停止时间。
水平线总是在整个图表上展开 - 您不能用时间参数来限制它 :https://www.mql5.com/zh/docs/constants/objectconstants/enum_object/obj_hline
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_HLINE
- www.mql5.com
OBJ_HLINE - Object Types - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
谢谢。
无法编译有 4 个错误

ATR 概率水平:
基于 ATR 的概率水平。"概率" 是通过投射过的平均真实范围指标和之前时间段的收盘价来计算的。
作者: Mladen Rakic