MT5平台日均波动幅度指标-汇有钱途

MT5平台日均波动幅度指标

XM十周年100万美元奖励活动

这个日均波动幅度指标是用AI把MT4版本的源代码转换为MT5平台指标,这个指标自动统计过去5天(5days)、昨天(yesterday)、过去一周(weekly)、过去一个月(monthly)和过去180天(180days)的平均波动幅度。MT4版本详见:一个非常实用的日均波幅统计指标

这个指标本质上是在回答交易者一个问题:这个品种在不同周期内“通常能动多大”?

指标截图如下
日均波动幅度指标
截图中是 USTEC / 纳斯达克100指数 H1 图表上的平均波动幅度统计,包含:

  • 过去5日平均波幅(5 days)
  • 昨日波幅(Yesterday)
  • 过去一周平均波幅(Weekly)
  • 月度平均波幅(Monthly)
  • 过去180天平均波幅(180 Days)
  • 当日高点(Today High)、当日低点(Today Low)
  • 当前价格距离今日高点(Pips to Today High)
  • 当前价格距离今日低点(Pips to Today Low)
  • ADR高点(ADR High)
  • ADR低点(ADR Low)

以上统计除了ADR高低点,都很好理解。ADR高低点是根据 平均日波幅 ADR 推算出来今日“理论上的日内波动边界”,大致的计算公式是,

ADR Low=今日开盘价−5日ADR/2

它的作用是告诉交易者,如果今天按照历史平均波动幅度运行,价格大概可能到哪里。

从交易角度看,这类指标更偏向于波动率参考工具,不是直接给买卖信号的指标。

一、这个指标的核心作用

1. 判断当前市场是否已经“走够了”

例如截图中显示:

  • 5日平均波幅:520.74
  • 昨日波幅:523.20
  • 周平均波幅:488.40
  • 月平均波幅:456.27
  • 180日平均波幅:433.84

这说明近期纳指的波动明显高于长期平均水平。

如果某一天盘中已经走出了接近甚至超过平均波幅,那么交易者就要警惕:

  • 追涨追跌的性价比下降
  • 后续可能进入震荡
  • 价格可能出现回撤或假突破
  • 止盈目标不宜再设得过远

简单说,当日波幅接近 ADR 区间后,市场继续单边扩展的概率会下降,追单风险会增加。


2. 判断近期波动率环境

从数据看:

  • 5日ADR > 周ADR > 月ADR > 180日ADR

说明纳指近期处于波动放大阶段

这对交易者有几个提示:

对趋势交易者

近期波动大,说明市场机会多,但同时回撤也大。

交易时需要:

  • 放宽止损
  • 降低仓位
  • 不要用过小止损硬扛波动
  • 避免在高位/低位追单

对震荡交易者

波动放大时,传统区间震荡策略容易被打穿。

需要特别注意:

  • 假突破增多
  • 区间扩大
  • 均值回归可能失效
  • 逆势抄顶摸底风险增加

二、对交易者的提示作用

1. 辅助设置止损

平均波幅可以帮助判断止损是否合理。

例如纳指过去5天平均日内波幅约为520点,如果你只设置很小的止损,比如九十点甚至100点都很容易被正常波动扫掉。

合理做法是:

  • 日内短线止损可参考当前周期结构 + 平均波幅
  • 趋势单止损应考虑近期 ADR 是否放大
  • 波动越大,仓位应越小

核心逻辑是:

止损不能小到被市场正常噪音轻易触发


2. 辅助设置止盈

如果当天价格已经从低点上涨了接近平均日波幅,那么继续追多的性价比就下降。

比如:

  • 今日高点:28930.20
  • 今日低点:28708.40
  • 当前日内已走出约:221.80 点实际价格波幅

如果指标单位换算后显示的 ADR 约对应更大范围,那么可以观察当前价格距离平均波幅上沿还有多少空间。

交易者可用它判断:

  • 目标位是否过于理想化
  • 当前行情是否还有空间
  • 是否应分批止盈
  • 是否不适合继续追单

3. 判断突破是否有延续空间

突破交易中,很多人只看价格突破高低点,但忽视了当天已经走了多少。

如果价格突破昨日高点或今日高点时,日内波幅已经接近平均波幅,那么可能出现:

  • 突破后快速回落
  • 假突破
  • 追单被套
  • 主力扫单后反向运行

相反,如果突破发生时,当日波幅还没走出太多,且成交时间处于欧美盘活跃时段,那么突破延续性可能更好。


4. 判断市场异常状态

如果某天波幅远超180天平均波幅,说明当天可能有重大事件或情绪冲击,比如:

  • CPI
  • 美联储利率决议
  • 非农
  • 科技股财报
  • 地缘政治事件
  • 美债收益率剧烈波动

这时应避免用平常策略机械交易。

因为在极端波动日:

  • 技术位容易失效
  • 滑点扩大
  • 止损可能被快速击穿
  • 点差可能放大
  • 反转和假突破都更剧烈

三、对日内交易的具体提示作用

1. 开盘前制定交易计划

日内交易者可以在开盘前观察:

  • 昨日波幅是多少
  • 5日平均波幅是多少
  • 180日平均波幅是多少
  • 当前价格处于昨日区间的什么位置
  • 距离 ADR 高低区间还有多少空间

例如:

如果美盘开盘前价格已经接近ADR上沿,那么开盘后继续做多就要谨慎。

如果价格处于日内中间区域,则上下都有空间,可以等待突破方向。


2. 判断当天适合追单还是等回调

当天已走出大部分平均波幅

如果日内已经完成了大部分ADR,适合:

  • 减少追单
  • 等回调
  • 做区间内短线
  • 关注反转形态
  • 锁定利润

当天波幅还很小

如果到欧美盘前,当天波幅仍明显低于平均值,说明可能还有扩张空间。

此时可以关注:

  • 区间突破
  • 昨日高低点突破
  • 重要均线突破
  • 美盘开盘后的方向选择

3. 辅助判断止盈区域

日内交易中,ADR 上沿/下沿常被用作潜在止盈区。

例如:

  • 做多时,若价格接近 ADR High,不宜再贪
  • 做空时,若价格接近 ADR Low,要考虑减仓
  • 如果价格到达平均波幅边界后出现背离或反转K线,可考虑离场

但要注意:
ADR不是阻力支撑,只是统计意义上的波动范围

趋势极强时,价格可以轻松突破 ADR 区间

4. 避免在“空间不足”的位置进场

这是该指标对日内交易最重要的价值之一。

例如:

价格已经上涨很多,并且距离 ADR High 只剩很小空间。

这时再做多,可能出现:

  • 盈亏比不好
  • 上方空间有限
  • 一回调就亏损
  • 容易追在日内高点附近

更合理的做法是:

  • 等回调后再找多头机会
  • 或等待突破 ADR High 后重新确认强势
  • 或干脆放弃这笔交易

四、结合截图看当前纳指的交易提示

从截图数据看,近期纳指波动率偏高:

  • 过去5日平均波幅高于180日平均
  • 昨日波幅也高于长期均值
  • 说明当前市场短期波动强度较大

对交易者的提示是:

1. 不适合用太小止损

纳指当前波动大,过小止损很容易被正常震荡扫出。

2. 仓位要控制

波幅变大意味着同样手数下,账户盈亏波动也会变大。

应根据止损距离调整仓位,而不是固定手数交易。

3. 追涨追跌要谨慎

如果当天价格已经接近平均波幅边界,再去追单风险较高。

4. 更适合等待关键位置

比如:

  • 昨日高点/低点
  • 今日高点/低点
  • ADR High/ADR Low
  • 美盘开盘后的方向确认
  • 重要数据公布后的波动稳定

五、实战使用思路

可以把这个指标融入日内交易流程:

开盘前

看:

  • 昨日波幅
  • 5日平均波幅
  • 180日平均波幅
  • 今日已走波幅
  • 当前价格距离ADR上下沿的位置

判断今天是:

  • 高波动环境
  • 低波动环境
  • 趋势延续环境
  • 潜在震荡环境

交易中

用它判断:

  • 还有没有波动空间
  • 是否适合追单
  • 止盈是否应提前
  • 止损是否过小
  • 仓位是否过重

临近目标位

如果价格接近 ADR High / ADR Low,可以:

  • 分批止盈
  • 移动止损
  • 观察反转信号
  • 不再追单
  • 等突破后的回踩确认

六、需要注意的误区

误区一:价格到ADR上沿就一定会跌

不一定。

强趋势日中,价格可以突破平均波幅很多。

ADR只能说明:
继续延伸的统计性空间变小了,不代表必然反转。


误区二:ADR可以单独作为买卖信号

不建议。

它最好结合:

  • 趋势方向
  • 支撑阻力
  • 成交时段
  • K线结构
  • 均线
  • 经济数据
  • 市场情绪

误区三:所有品种都用同一套参数

不同品种波动特征不同。

纳指、黄金、原油、外汇的日内节奏完全不同,ADR参考周期也应根据品种调整。

总结

这个平均波动幅度指标的主要价值是:

  1. 判断当前波动环境
  2. 衡量日内剩余空间
  3. 辅助止损和止盈设置
  4. 避免在行情已经走满时追单
  5. 帮助控制仓位和风险
  6. 识别异常波动日

对日内交易者来说,它尤其适合用来判断:今天行情是否还有空间、当前进场位置是否划算、止盈止损是否合理、是否应该追单或等待回调。

它不是方向指标,而是一个非常实用的波动率和交易空间管理工具

指标设置如下图所示
日均波动幅度指标
指标源代码如下,编译教程详见:使用人工智能AI来编写MT4/MT5指标,实在不会,就下载MT5平台日均波动幅度指标ADR.mq5,提取码: y89j

//+------------------------------------------------------------------+
//| ADR_Pro_Calculator_MQ5.mq5 |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_plots 0

string gs_76 = "";
input string Custom_Indicator = "Average Daily Range Pro Calculator";
input string Label0 = "=== Calculation setting ===";
input string Input_Days = "Enter number of days to calculate.";
input int Day_x = 5;
input string Label1 = "=== Corner settings ===";
input string Upper_Corner_Help = "0 = Upper Left, 1 = Right";
input string Lower_Corner_Help = "2 = Lower Left, 3 = Right";
input int Corner = 2;
input string Label2 = "=== Color settings ===";
input string Color_Help = "Select ADR color:";
input color ADR_Color = clrGoldenrod;
input color Daily_High_Color = clrLimeGreen;
input color Daily_Low_Color = clrFuchsia;
input string Label3 = "=== Display settings ===";
input string Display_Help = "Enter Yes or No";
input string Show_Daily_High_Low_Lines = "Yes";
input string Show_Weekly_Lines = "Yes";
input string Show_Mini_ADR = "No";
input string Label4 = "=== Font settings ===";
input string Font_Size_Help = "Font size can be 6 to 14";
input int Font_Size = 8;
input int Vertical_Spacing_Adjustment = 0;

//--- 内部变量,用于替代不可修改的 input 变量
int g_FontSize;
int g_Corner;

int gia_248[34][2];
int gi_252 = 1;
int gi_256 = 100;
int gi_260 = 3;
bool gi_268 = true;
int gi_unused_272 = 5;
int gi_unused_276 = 15;
double gd_280;
double gd_288;
string gs_296 = "";
string gs_304 = "";
string gs_312;
string gs_320;
string gs_328;
string gs_336;
string gs_344;
string gs_352;
string gs_360;
string g_dbl2str_368;
string g_dbl2str_376;
string g_dbl2str_384;
string g_dbl2str_392;
string g_dbl2str_400;
string gs_408;
string gs_416;
string gs_424;
string gs_432;
string gs_440;
string gs_448;
string gs_456;
string gs_464;
string g_dbl2str_472;
string g_dbl2str_480;
string g_dbl2str_488;
string g_dbl2str_496;
string g_dbl2str_504;
string g_dbl2str_512;
string g_dbl2str_520;
string g_dbl2str_528;
string gs_536 = "";
int gi_544;
bool gi_548;
bool gi_552;
int gi_556;
bool gi_560 = true;
datetime g_time_564 = 0;
bool gi_568 = true;
int gi_unused_572 = 0;
datetime g_time_576 = 0;

// 自定义函数:获取星期几
int TimeDayOfWeek(datetime time) {
MqlDateTime tm;
TimeToStruct(time, tm);
return tm.day_of_week;
}

int OnInit() {
string str_concat_8 = gs_536 + gs_76;
gs_536 = Decrypt(str_concat_8);

if (gi_260 > 3) gi_260 = 3;

// 内部变量初始化
g_FontSize = Font_Size;
if (g_FontSize < 6) g_FontSize = 6;
else if (g_FontSize > 14) g_FontSize = 14;

g_Corner = Corner;
if (g_Corner < 0) g_Corner = 0;
else if (g_Corner > 3) g_Corner = 3;

gi_544 = IsYes(Show_Weekly_Lines);
gi_548 = IsYes(Show_Mini_ADR);
gi_552 = IsYes(Show_Daily_High_Low_Lines);

DeleteObjs();

if (_Digits == 5 || _Digits == 3) gi_556 = 10;
else gi_556 = 1;

return (INIT_SUCCEEDED);
}

void OnDeinit(const int reason) {
DeleteObjs();
}

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 (!gi_268) return (rates_total);
if (!gi_548) NormalDisplay();
else MiniDisplay();

if (gi_544 && _Period < PERIOD_W1) ShowWeekLines();
return (rates_total);
}

void NormalDisplay() {
int day_of_week_56;
double ld_148;
double ld_0 = 0;
double ld_8 = 0;
double ld_16 = 0;
double ld_24 = 0;
double ilow_32 = 0;
double ihigh_40 = 0;
int li_48 = 0;

if (gi_560) {
SetTextData();
createLabelObjects();
gi_560 = false;
}

double ld_76 = 0;
double ld_116 = 0;
double ld_124 = 0;
double ld_132 = 0;
double ld_140 = 0;
double ld_68 = (iHigh(NULL, PERIOD_D1, 1) - iLow(NULL, PERIOD_D1, 1)) / _Point;

ld_24 = 0.0;
double ld_84 = 0.0;
double ld_92 = 0.0;
ld_76 = 0.0;
int count_52 = 0;
int count_60 = 0;
int count_64 = 0;

for (li_48 = 1; li_48 < 220; li_48++) {
count_52++;
if (count_52 > 220) break;
day_of_week_56 = TimeDayOfWeek(iTime(NULL, PERIOD_D1, li_48));
if (day_of_week_56 != 0) {
if (day_of_week_56 == 5 && count_64 == 0) count_64 = 1;
count_60++;
ld_148 = iHigh(NULL, PERIOD_D1, li_48) - iLow(NULL, PERIOD_D1, li_48);
if (count_60 <= Day_x) ld_24 += ld_148;
if (count_64 > 0 && count_64 <= 5) {
ld_76 += ld_148;
count_64++;
}
if (count_60 <= 22) ld_84 += ld_148;
if (count_60 <= 180) ld_92 += ld_148;
if (count_60 >= 180) break;
}
}

double ld_100 = NormalizeDouble(ld_24 / Day_x / _Point, 0);
ld_0 = NormalizeDouble(ld_100 / 2.0 * _Point, _Digits);
ld_76 = NormalizeDouble(0.2 * ld_76 / _Point, 0);
ld_84 = NormalizeDouble(ld_84 / 22.0 / _Point, 0);
ld_92 = NormalizeDouble(ld_92 / 180.0 / _Point, 0);

ilow_32 = iLow(NULL, PERIOD_D1, 0);
ihigh_40 = iHigh(NULL, PERIOD_D1, 0);
double Ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
double Bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);

ld_116 = (ihigh_40 - Ask) / _Point;
ld_124 = (Bid - ilow_32) / _Point;
ld_8 = iOpen(NULL, PERIOD_D1, 0) + ld_0;
ld_16 = iOpen(NULL, PERIOD_D1, 0) - ld_0;
ld_132 = (ld_8 - Ask) / _Point;
ld_140 = (Bid - ld_16) / _Point;

g_dbl2str_368 = DoubleToString(ld_100 / gi_556, 0);
g_dbl2str_376 = DoubleToString(ld_68 / gi_556, 0);
g_dbl2str_384 = DoubleToString(ld_76 / gi_556, 0);
g_dbl2str_392 = DoubleToString(ld_84 / gi_556, 0);
g_dbl2str_400 = DoubleToString(ld_92 / gi_556, 0);
g_dbl2str_472 = DoubleToString(ld_8, _Digits);
g_dbl2str_480 = DoubleToString(ihigh_40, _Digits);
g_dbl2str_488 = DoubleToString(ilow_32, _Digits);
g_dbl2str_496 = DoubleToString(ld_16, _Digits);
g_dbl2str_504 = DoubleToString(ld_116 / gi_556, 0);
g_dbl2str_512 = DoubleToString(ld_132 / gi_556, 0);
g_dbl2str_520 = DoubleToString(ld_124 / gi_556, 0);
g_dbl2str_528 = DoubleToString(ld_140 / gi_556, 0);

if (gi_552) DoADRHighLowLines(ld_8, ld_16);
updateText();
}

void DoADRHighLowLines(double ad_0, double ad_8) {
datetime time0 = iTime(_Symbol, _Period, 0);
if (g_time_564 != time0) {
CreateHTLine("TextPlace_ADRHighLine", "ADR High", 0, ad_0, 0, ad_0, STYLE_SOLID, 3, Daily_High_Color, true, false);
CreateHTLine("TextPlace_ADRLowLine", "ADR Low", 0, ad_8, 0, ad_8, STYLE_SOLID, 3, Daily_Low_Color, true, false);
g_time_564 = time0;
}
}

void MiniDisplay() {
int day_of_week_8;
double ld_84;
int li_100 = 0; // 初始化防止警告
int li_104 = 0; // 初始化防止警告
int li_108 = 0; // 初始化防止警告
int count_4 = 0;
double ld_16 = 0.0;

string ls_40 = StringSubstr(gs_536, 16);
string str_concat_48 = "ADR Pro Calculator" + ls_40;

switch (g_FontSize) {
case 6: gi_252 = 0; break;
case 7: gi_252 = 0; break;
case 8: gi_252 = 2; break;
case 9: gi_252 = 3; break;
case 10: gi_252 = 4; break;
case 11: gi_252 = 5; break;
case 12: gi_252 = 7; break;
case 13: gi_252 = 7; break;
case 14: gi_252 = 8; break;
default: gi_252 = 2; break;
}
gi_252 += Vertical_Spacing_Adjustment;

int li_0 = 1;
count_4 = 0;
int count_12 = 0;
ld_16 = 0.0;

for (li_0 = 1; li_0 < 10; li_0++) {
count_4++;
if (count_4 > 10) break;
day_of_week_8 = TimeDayOfWeek(iTime(NULL, PERIOD_D1, li_0));
if (day_of_week_8 != 0) {
count_12++;
ld_84 = iHigh(NULL, PERIOD_D1, li_0) - iLow(NULL, PERIOD_D1, li_0);
if (count_12 <= Day_x) ld_16 += ld_84;
if (count_12 >= Day_x) break;
}
}

ld_16 /= Day_x;
double ld_24 = iOpen(NULL, PERIOD_D1, 0) + ld_16 / 2.0;
double ld_32 = iOpen(NULL, PERIOD_D1, 0) - ld_16 / 2.0;

// 规范字符串拼接,替换 StringConcatenate
string str_concat_92 = "ADR: " + IntegerToString(Day_x) + " days / " + DoubleToString(ld_16 / gi_556 / _Point, 0) + " pips | ADR H/L: " + DoubleToString(ld_24, _Digits) + " / " + DoubleToString(ld_32, _Digits);

if (gi_568) {
ObjectDelete(0, "TextPlace_mini1");
ObjectDelete(0, "TextPlace_mini2");
count_4 = 0;
switch (g_Corner) {
case 0:
li_100 = 15;
li_104 = gi_252 + 27;
li_108 = 5;
break;
case 1:
li_100 = 15;
li_104 = gi_252 + 27;
li_108 = 15;
break;
case 2:
li_100 = gi_252 + 20;
li_104 = 8;
li_108 = 5;
break;
case 3:
li_100 = gi_252 + 20;
li_104 = 8;
li_108 = 15;
break;
}
myObjCreate("TextPlace_mini1", li_108, li_100, str_concat_48);
myObjCreate("TextPlace_mini2", li_108, li_104, str_concat_92);
gi_568 = false;
}

ObjectSetString(0, "TextPlace_mini1", OBJPROP_TEXT, str_concat_48);
ObjectSetString(0, "TextPlace_mini2", OBJPROP_TEXT, str_concat_92);

if (gi_552) DoADRHighLowLines(ld_24, ld_32);
}

void ShowWeekLines() {
int li_8 = 0; // 初始化防止警告
int day_of_week_12;
int count_16;
double ld_28;
double iclose_36;
double ld_44;
int li_56;
int li_60;
double ld_64;
double ld_72;
double ld_80;
double ld_88;
double ld_96;
double ld_104;
double ld_112;
double ld_120;
double ld_128;
double ld_136;
int li_4 = 0;

datetime time0 = iTime(_Symbol, _Period, 0);
if (time0 != g_time_576) {
if (TimeDayOfWeek(iTime(NULL, PERIOD_D1, li_4)) > 5 && TimeDayOfWeek(iTime(NULL, PERIOD_D1, li_4)) < 1)
Alert("ADR Template ", _Symbol, " Waiting for start of week at 5:00 PM Eastern.");
else {
li_8 = 0;
for (li_4 = 1; li_4 <= 12; li_4++) {
if (li_8 == 0 && TimeDayOfWeek(iTime(NULL, PERIOD_D1, li_4)) == 5) {
li_8 = li_4;
break;
}
}
iclose_36 = iClose(NULL, PERIOD_D1, li_8);
ld_28 = 0.0;
for (li_8 = li_4; li_8 <= li_4 + 4; li_8++) ld_28 += iHigh(NULL, PERIOD_D1, li_8) - iLow(NULL, PERIOD_D1, li_8);
ld_28 = MathRound(ld_28 / 5.0 / _Point / gi_556);
g_time_576 = time0;
ld_44 = 0.0;
li_4 = 1;
li_8 = 0;
count_16 = 0;
for (li_4 = 1; li_4 < 35; li_4++) {
li_8++;
if (li_8 > 35) break;
day_of_week_12 = TimeDayOfWeek(iTime(NULL, PERIOD_D1, li_4));
if (day_of_week_12 != 0) {
ld_44 += iHigh(NULL, PERIOD_D1, li_4) - iLow(NULL, PERIOD_D1, li_4);
count_16++;
if (count_16 >= 22) break;
}
}
ld_44 = MathRound(ld_44 / 22.0 / _Point / gi_556);
li_56 = (int)((ld_28 + ld_44) / 2.0);
li_60 = li_56 / 2;
ld_64 = iclose_36 + li_56 * _Point * gi_556;
CreateHTLine("TextPlace_WklyHigh", "Wk Hi ", gi_256, ld_64, 0, ld_64, STYLE_SOLID, 2, clrGreen, true, false);
ld_72 = iclose_36 - li_56 * _Point * gi_556;
CreateHTLine("TextPlace_WklyLow", "Wk Lo ", gi_256, ld_72, 0, ld_72, STYLE_SOLID, 2, clrRed, true, false);
ld_80 = iclose_36 + li_60 * _Point * gi_556;
CreateHTLine("TextPlace_WklyMidHigh", "Wk Mid Hi", gi_256, ld_80, 0, ld_80, STYLE_SOLID, 2, clrMediumSeaGreen, true, false);
ld_88 = iclose_36 - li_60 * _Point * gi_556;
CreateHTLine("TextPlace_WklyMidLow", "Wk Mid Lo", gi_256, ld_88, 0, ld_88, STYLE_SOLID, 2, clrMediumVioletRed, true, false);
ld_96 = ld_64 + li_60 * _Point * gi_556;
CreateHTLine("TextPlace_WklyExtHigh_1", "Wk Ex Hi 1", gi_256, ld_96, 0, ld_96, STYLE_DASH, 1, clrGreen, true, false);
ld_104 = ld_96 + li_60 * _Point * gi_556;
CreateHTLine("TextPlace_WklyExtHigh_2", "Wk Ex Hi 2", gi_256, ld_104, 0, ld_104, STYLE_DASH, 1, clrGreen, true, false);
ld_112 = ld_104 + li_60 * _Point * gi_556;
CreateHTLine("TextPlace_WklyExtHigh_3", "Wk Ex Hi 3", gi_256, ld_112, 0, ld_112, STYLE_DASH, 1, clrGreen, true, false);
ld_120 = ld_72 - li_60 * _Point * gi_556;
CreateHTLine("TextPlace_WklyExtLow_1", "Wk Ex Lo 1", gi_256, ld_120, 0, ld_120, STYLE_DASH, 1, clrRed, true, false);
ld_128 = ld_120 - li_60 * _Point * gi_556;
CreateHTLine("TextPlace_WklyExtLow_2", "Wk Ex Lo 2", gi_256, ld_128, 0, ld_128, STYLE_DASH, 1, clrRed, true, false);
ld_136 = ld_128 - li_60 * _Point * gi_556;
CreateHTLine("TextPlace_WklyExtLow_3", "Wk Ex Lo 3", gi_256, ld_136, 0, ld_136, STYLE_DASH, 1, clrRed, true, false);
}
}
}

void CreateHTLine(string a_name_0, string as_8, int ai_16, double a_price_20, int ai_28, double a_price_32, int a_style_40, int a_width_44, color a_color_48, bool a_bool_52, bool a_bool_56) {
int width_76;
int li_80 = 4;

datetime time_60 = iTime(_Symbol, _Period, ai_16);
datetime datetime_64 = iTime(_Symbol, _Period, ai_28);
datetime time0 = iTime(_Symbol, _Period, 0);

if (as_8 == "ADR High" || as_8 == "ADR Low") datetime_64 = time0 + PeriodSeconds(_Period) * (li_80 + 1);

ObjectDelete(0, a_name_0);
ai_28 += 5 * PeriodSeconds(_Period);

ObjectCreate(0, a_name_0, OBJ_TREND, 0, time_60, a_price_20, datetime_64, a_price_32);
ObjectSetInteger(0, a_name_0, OBJPROP_STYLE, a_style_40);
if (a_style_40 == STYLE_SOLID) ObjectSetInteger(0, a_name_0, OBJPROP_WIDTH, a_width_44);
ObjectSetInteger(0, a_name_0, OBJPROP_COLOR, a_color_48);
ObjectSetInteger(0, a_name_0, OBJPROP_BACK, a_bool_52);
ObjectSetInteger(0, a_name_0, OBJPROP_RAY_RIGHT, a_bool_56);

string name_84 = a_name_0 + "_Lab";
switch (gi_260) {
case 0: return;
case 1:
datetime_64 = iTime(_Symbol, _Period, ai_16);
break;
case 2:
ai_16 /= 2;
datetime_64 = iTime(_Symbol, _Period, ai_16);
break;
case 3:
datetime_64 = time0 + 6 * PeriodSeconds(_Period);
}

if (as_8 == "ADR High" || as_8 == "ADR Low") {
datetime_64 = time0 + PeriodSeconds(_Period) * li_80;
if (g_FontSize < 9) width_76 = 1;
else width_76 = 2;
ObjectDelete(0, name_84);
ObjectCreate(0, name_84, OBJ_ARROW, 0, datetime_64, a_price_20);
ObjectSetInteger(0, name_84, OBJPROP_COLOR, a_color_48);
ObjectSetInteger(0, name_84, OBJPROP_ARROWCODE, OBJ_ARROW_RIGHT_PRICE);
ObjectSetInteger(0, name_84, OBJPROP_WIDTH, width_76);
return;
}

ObjectDelete(0, name_84);
ObjectCreate(0, name_84, OBJ_TEXT, 0, datetime_64, a_price_20);
string str_concat_68 = DoubleToString(a_price_20, _Digits) + " " + as_8;
ObjectSetString(0, name_84, OBJPROP_TEXT, str_concat_68);
ObjectSetInteger(0, name_84, OBJPROP_FONTSIZE, g_FontSize);
ObjectSetString(0, name_84, OBJPROP_FONT, "Tahoma");
ObjectSetInteger(0, name_84, OBJPROP_COLOR, a_color_48);
}

void updateText() {
string names[] = {"TextPlace_davgTxt", "TextPlace_D1Txt", "TextPlace_D5Txt", "TextPlace_DyTxt", "TextPlace_DzTxt", "TextPlace_thigh", "TextPlace_tlow", "TextPlace_roomup", "TextPlace_roomdn", "TextPlace_adrhigh", "TextPlace_adrlow", "TextPlace_aroomup", "TextPlace_aroomdn"};
string texts[] = {g_dbl2str_368, g_dbl2str_376, g_dbl2str_384, g_dbl2str_392, g_dbl2str_400, g_dbl2str_480, g_dbl2str_488, g_dbl2str_504, g_dbl2str_520, g_dbl2str_472, g_dbl2str_496, g_dbl2str_512, g_dbl2str_528};

for(int i=0; i<13; i++) {
ObjectSetString(0, names[i], OBJPROP_TEXT, texts[i]);
ObjectSetInteger(0, names[i], OBJPROP_FONTSIZE, g_FontSize);
ObjectSetString(0, names[i], OBJPROP_FONT, "Tahoma");
ObjectSetInteger(0, names[i], OBJPROP_COLOR, ADR_Color);
}
}

void createLabelObjects() {
myObjCreate("TextPlace_Head1", gia_248[0][0], gia_248[0][1], gs_304);
myObjCreate("TextPlace_Name", gia_248[1][0], gia_248[1][1], gs_536);
myObjCreate("TextPlace_Head2", gia_248[2][0], gia_248[2][1], gs_296);
myObjCreate("TextPlace_ADRhead", gia_248[3][0], gia_248[3][1], gs_312);
myObjCreate("TextPlace_dayLbl", gia_248[4][0], gia_248[4][1], gs_320);
myObjCreate("TextPlace_yesTxt", gia_248[5][0], gia_248[5][1], gs_328);
myObjCreate("TextPlace_wkTxt", gia_248[6][0], gia_248[6][1], gs_336);
myObjCreate("TextPlace_mnTxt", gia_248[7][0], gia_248[7][1], gs_344);
myObjCreate("TextPlace_lstTxt", gia_248[8][0], gia_248[8][1], gs_352);
myObjCreate("TextPlace_PIPhead", gia_248[9][0], gia_248[9][1], gs_360);
myObjCreate("TextPlace_davgTxt", gia_248[10][0], gia_248[10][1], g_dbl2str_368);
myObjCreate("TextPlace_D1Txt", gia_248[11][0], gia_248[11][1], g_dbl2str_376);
myObjCreate("TextPlace_D5Txt", gia_248[12][0], gia_248[12][1], g_dbl2str_384);
myObjCreate("TextPlace_DyTxt", gia_248[13][0], gia_248[13][1], g_dbl2str_392);
myObjCreate("TextPlace_DzTxt", gia_248[14][0], gia_248[14][1], g_dbl2str_400);
myObjCreate("TextPlace_Head3", gia_248[15][0], gia_248[15][1], gs_296);
myObjCreate("TextPlace_tHighLbl", gia_248[16][0], gia_248[16][1], gs_408);
myObjCreate("TextPlace_thigh", gia_248[17][0], gia_248[17][1], g_dbl2str_480);
myObjCreate("TextPlace_aHighLbl", gia_248[18][0], gia_248[18][1], gs_416);
myObjCreate("TextPlace_adrhigh", gia_248[19][0], gia_248[19][1], g_dbl2str_472);
myObjCreate("TextPlace_tLowLbl", gia_248[20][0], gia_248[20][1], gs_424);
myObjCreate("TextPlace_tlow", gia_248[21][0], gia_248[21][1], g_dbl2str_488);
myObjCreate("TextPlace_aLowLbl", gia_248[22][0], gia_248[22][1], gs_432);
myObjCreate("TextPlace_adrlow", gia_248[23][0], gia_248[23][1], g_dbl2str_496);
myObjCreate("TextPlace_ptthLbl", gia_248[24][0], gia_248[24][1], gs_440);
myObjCreate("TextPlace_roomup", gia_248[25][0], gia_248[25][1], g_dbl2str_504);
myObjCreate("TextPlace_ptahLbl", gia_248[26][0], gia_248[26][1], gs_448);
myObjCreate("TextPlace_aroomup", gia_248[27][0], gia_248[27][1], g_dbl2str_512);
myObjCreate("TextPlace_pttlLbl", gia_248[28][0], gia_248[28][1], gs_456);
myObjCreate("TextPlace_roomdn", gia_248[29][0], gia_248[29][1], g_dbl2str_520);
myObjCreate("TextPlace_ptalLbl", gia_248[30][0], gia_248[30][1], gs_464);
myObjCreate("TextPlace_aroomdn", gia_248[31][0], gia_248[31][1], g_dbl2str_528);
}

void myObjCreate(string a_name_0, int a_x_8, int a_y_12, string a_text_16) {
ObjectCreate(0, a_name_0, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, a_name_0, OBJPROP_XDISTANCE, a_x_8);
ObjectSetInteger(0, a_name_0, OBJPROP_YDISTANCE, a_y_12);

ENUM_BASE_CORNER corner_enum = CORNER_LEFT_UPPER;
if(g_Corner == 1) corner_enum = CORNER_RIGHT_UPPER;
else if(g_Corner == 2) corner_enum = CORNER_LEFT_LOWER;
else if(g_Corner == 3) corner_enum = CORNER_RIGHT_LOWER;
ObjectSetInteger(0, a_name_0, OBJPROP_CORNER, corner_enum);

ObjectSetString(0, a_name_0, OBJPROP_TEXT, a_text_16);
ObjectSetInteger(0, a_name_0, OBJPROP_FONTSIZE, g_FontSize);
ObjectSetString(0, a_name_0, OBJPROP_FONT, "Tahoma");
ObjectSetInteger(0, a_name_0, OBJPROP_COLOR, ADR_Color);
}

string Decrypt(string as_0) {
int li_16;
int str_len_8 = StringLen(as_0);
for (int li_12 = 0; li_12 < str_len_8; li_12++) {
li_16 = StringGetCharacter(as_0, li_12);
li_16 -= 5;
StringSetCharacter(as_0, li_12, (ushort)li_16);
}
return (as_0);
}

void SetTextData() {
int index_0 = 0;
int li_8 = 0; // 初始化防止警告
string ls_16;
int li_44 = 0; // 初始化防止警告
bool li_12 = true;

if (g_FontSize < 6) g_FontSize = 6;
else if (g_FontSize > 14) g_FontSize = 14;

if (g_Corner == 0 || g_Corner == 2) li_12 = true;
else li_12 = false;

switch (g_FontSize) {
case 6: gd_280 = 0.8; gd_288 = 0.8; li_8 = 5; if (li_12) ls_16 = "========"; else ls_16 = "======="; break;
case 7: gd_280 = 0.9; gd_288 = 0.84; li_8 = 3; if (li_12) ls_16 = "======="; else ls_16 = "======"; break;
case 8: gd_280 = 0.99; gd_288 = 1.0; li_8 = 0; if (li_12) ls_16 = "=========="; else ls_16 = "=========="; break;
case 9: gd_280 = 1.3; gd_288 = 1.0; li_8 = 0; if (li_12) ls_16 = "==========="; else ls_16 = "=========="; break;
case 10: gd_280 = 1.3; gd_288 = 1.05; li_8 = 0; if (li_12) ls_16 = "==========="; else ls_16 = "=========="; break;
case 11: gd_280 = 1.52; gd_288 = 1.2; li_8 = 0; if (li_12) ls_16 = "============="; else ls_16 = "============"; break;
case 12: gd_280 = 1.64; gd_288 = 1.4; li_8 = 0; if (li_12) ls_16 = "========="; else ls_16 = "========"; break;
case 13: gd_280 = 1.73; gd_288 = 1.5; li_8 = 0; if (li_12) ls_16 = "==========="; else ls_16 = "=========="; break;
case 14: gd_280 = 1.77; gd_288 = 1.6; li_8 = 0; if (li_12) ls_16 = "=========="; else ls_16 = "========"; break;
default: gd_280 = 0.99; gd_288 = 1.0; li_8 = 0; ls_16 = "=========="; break;
}

gs_296 = "==============================" + ls_16;

if (g_Corner == 0) {
int lia_28[34][2] = { {5, 14}, {5, 27}, {5, 36}, {5, 46}, {49, 46}, {94, 46}, {153, 46}, {198, 46}, {247, 46}, {5, 58}, {49, 58}, {94, 58}, {153, 58}, {198, 58}, {247, 58}, {5, 69}, {5, 80}, {113, 80}, {158, 80}, {257, 80}, {5, 92}, {113, 92}, {158, 92}, {257, 92}, {5, 103}, {113, 103}, {158, 103}, {257, 103}, {5, 115}, {113, 115}, {158, 115}, {257, 115}, {0, 0} };
index_0 = 0;
for (int li_4 = Vertical_Spacing_Adjustment; lia_28[index_0][1] > 0; index_0++) {
gia_248[index_0][0] = (int)(lia_28[index_0][0] * gd_280);
gia_248[index_0][1] = (int)(lia_28[index_0][1] * gd_288 + li_4 + li_8);
if (lia_28[index_0][1] != lia_28[index_0 + 1][1]) li_4 += Vertical_Spacing_Adjustment;
}
} else {
if (g_Corner == 1) {
int lia_32[34][2] = { {10, 14}, {9, 27}, {9, 36}, {265, 46}, {217, 46}, {158, 46}, {113, 46}, {64, 46}, {9, 46}, {265, 58}, {217, 58}, {158, 58}, {113, 58}, {64, 58}, {9, 58}, {9, 69}, {232, 80}, {153, 80}, {94, 80}, {9, 80}, {232, 92}, {153, 92}, {94, 92}, {9, 92}, {198, 103}, {153, 103}, {61, 103}, {9, 103}, {198, 115}, {153, 115}, {61, 115}, {9, 115}, {0, 0} };
index_0 = 0;
for (int li_4 = Vertical_Spacing_Adjustment; lia_32[index_0][1] > 0; index_0++) {
gia_248[index_0][0] = (int)(lia_32[index_0][0] * gd_280);
gia_248[index_0][1] = (int)(lia_32[index_0][1] * gd_288 + li_4 + li_8);
if (lia_32[index_0][1] != lia_32[index_0 + 1][1]) li_4 += Vertical_Spacing_Adjustment;
}
} else {
if (g_Corner == 2) {
int lia_36[34][2] = { {5, 103}, {5, 91}, {5, 80}, {5, 70}, {49, 70}, {94, 70}, {153, 70}, {198, 70}, {247, 70}, {5, 58}, {49, 58}, {94, 58}, {153, 58}, {198, 58}, {247, 58}, {5, 47}, {5, 37}, {113, 37}, {158, 37}, {257, 37}, {5, 25}, {113, 25}, {158, 25}, {257, 25}, {5, 13}, {113, 13}, {158, 13}, {257, 13}, {5, 1}, {113, 1}, {158, 1}, {257, 1}, {0, 0} };
for (index_0 = 0; lia_36[index_0][1] > 0; index_0++) {
gia_248[index_0][0] = (int)(lia_36[index_0][0] * gd_280);
gia_248[index_0][1] = (int)(lia_36[index_0][1] * gd_288);
}
int li_4 = 0;
for (index_0 -= 4; index_0 >= 0; index_0--) {
gia_248[index_0][1] += li_4;
if (lia_36[index_0][1] != lia_36[index_0 + 1][1]) li_4 += Vertical_Spacing_Adjustment;
}
} else {
if (g_Corner == 3) {
index_0 = 0;
int lia_40[34][2] = { {10, 103}, {9, 91}, {9, 80}, {265, 70}, {217, 70}, {158, 70}, {113, 70}, {64, 70}, {9, 70}, {265, 58}, {217, 58}, {158, 58}, {113, 58}, {64, 58}, {9, 58}, {9, 47}, {232, 37}, {153, 37}, {94, 37}, {9, 37}, {232, 25}, {153, 25}, {94, 25}, {9, 25}, {198, 13}, {153, 13}, {61, 13}, {9, 13}, {198, 1}, {153, 1}, {61, 1}, {9, 1}, {0, 0} };
for (index_0 = 0; lia_40[index_0][1] > 0; index_0++) {
gia_248[index_0][0] = (int)(lia_40[index_0][0] * gd_280);
gia_248[index_0][1] = (int)(lia_40[index_0][1] * gd_288);
}
int li_4 = 0;
for (index_0--; index_0 >= 0; index_0--) {
gia_248[index_0][1] += li_4;
if (lia_40[index_0][1] != lia_40[index_0 + 1][1]) li_4 += Vertical_Spacing_Adjustment;
}
}
}
}
}

if (g_Corner > 1) {
if (g_FontSize < 8) li_44 = 3;
else li_44 = 1;
int li_4 = ArrayRange(gia_248, 0);
for (index_0 = 0; index_0 < li_4; index_0++) gia_248[index_0][1] += li_44;
}

if (!li_12) {
if (g_FontSize == 9) {
gia_248[9][0] += 2; gia_248[16][0] += 5; gia_248[18][0] += 4; gia_248[24][0] += 5; gia_248[26][0] += 5; gia_248[28][0] += 2; gia_248[30][0] += 2;
} else if (g_FontSize == 10) {
gia_248[9][0] += 0; gia_248[16][0] += 3; gia_248[18][0] += 2; gia_248[24][0] += 3; gia_248[26][0] += 3; gia_248[28][0]++; gia_248[30][0]++;
} else if (g_FontSize == 11) {
gia_248[9][0] += 3; gia_248[16][0] += 3; gia_248[18][0] += 2; gia_248[24][0] += 9; gia_248[26][0] += 7; gia_248[28][0] += 7; gia_248[30][0] += 5;
} else if (g_FontSize == 12) {
gia_248[9][0] += 2; gia_248[16][0] += 2; gia_248[18][0] += 2; gia_248[24][0] += 3; gia_248[26][0] += 2; gia_248[28][0]++; gia_248[30][0] += 0;
} else if (g_FontSize == 13) {
gia_248[9][0] += 2; gia_248[16][0] += 5; gia_248[18][0] += 2; gia_248[24][0] += 7; gia_248[26][0] += 2; gia_248[28][0] += 5; gia_248[30][0] += 0; gia_248[20][0] += 3;
} else if (g_FontSize == 14) {
gia_248[9][0] += 2; gia_248[16][0] += 0; gia_248[18][0] += 2; gia_248[24][0] += 0; gia_248[26][0] += 0; gia_248[28][0] -= 2; gia_248[30][0] -= 2; gia_248[20][0] -= 2;
}
}

if (_Digits == 5 || _Digits == 3) ls_16 = ls_16 + "=";
gs_304 = "";
gs_312 = "ADR:";
gs_328 = "Yesterday";
gs_336 = "Weekly";
gs_344 = "Monthly";
gs_352 = "180 Days";
gs_360 = "Pips:";
gs_408 = "Today High:";
gs_416 = "ADR High:";
gs_424 = "Today Low: ";
gs_432 = "ADR Low: ";
gs_440 = "Pips to Today High:";
gs_448 = "Pips to ADR High:";
gs_456 = "Pips to Today Low: ";
gs_464 = "Pips to ADR Low: ";

// 规范字符串拼接
gs_320 = IntegerToString(Day_x) + " days";
}

void DeleteObjs() {
int objs_total_8;
string name_16;
int count_4 = 1;
for (int li_12 = 6; li_12 > 0; li_12--) {
objs_total_8 = ObjectsTotal(0);
count_4 = 0;
for (int li_0 = 0; li_0 < objs_total_8; li_0++) {
name_16 = ObjectName(0, li_0);
if (StringSubstr(name_16, 0, 10) == "TextPlace_")
if (ObjectDelete(0, name_16)) count_4++;
}
if (count_4 == 0) break;
}
}

string ToCaps(string as_0) {
int li_16;
int str_len_8 = StringLen(as_0);
for (int li_12 = 0; li_12 < str_len_8; li_12++) {
li_16 = StringGetCharacter(as_0, li_12);
if (li_16 >= 'a' && li_16 <= 'z') {
StringSetCharacter(as_0, li_12, (ushort)(li_16 - 32));
}
}
return (as_0);
}

int IsYes(string as_0) {
as_0 = ToCaps(as_0);
if (StringFind(as_0, "Y") > -1) return (1);
return (0);
}
//+------------------------------------------------------------------+

本文由 汇有钱途 作者:admin 发表,其版权均为 汇有钱途 所有,文章内容系作者个人观点,不代表 汇有钱途 对观点赞同或支持。如需转载,请注明文章来源。

发表评论