kevanjj 发表于 2025-6-27 21:16:56

【时段箱体突破】指定时间段箱体突破

指标名称:时段箱体突破
版本:MT4ver. 2.01
时段箱体突破是一款用于MT4平台的交易辅助工具,通过识别特定时间窗口内的价格波动区间(箱体),自动计算突破后的潜在入场点、止损位及多级止盈目标。该指标适用于外汇、商品等市场的短线突破策略,帮助交易者快速识别关键价位。一、指标原理
[*]时间窗口设定
指标在用户指定的GMT时间范围内(如06:00-09:30)统计最高价与最低价,形成“价格箱体”。
[*]箱体动态调整

[*]若箱体幅度超出预设范围,可自动限制最大尺寸或吸附到最近的极值点。
[*]突破信号基于箱体边界外的入场偏移计算。
[*]多级目标与止损
根据箱体幅度按比例生成止损位(SL)及5个止盈目标(TP1-TP5),支持固定点数或动态比例两种模式。

二、使用指南1. 关键功能解读
[*]箱体显示

[*]蓝色:有效箱体(幅度在Min-Max之间)。
[*]红色:箱体过小(需谨慎交易)。
[*]橙色:箱体超限(被限制到Max值)。
[*]突破信号

[*]买入信号:价格上破箱顶+EntryFactor(入场偏移系数)偏移位(蓝色虚线)。
[*]卖出信号:价格下破箱底-EntryFactor(入场偏移系数)偏移位(红色虚线)。
[*]辅助线

[*]灰色虚线:止损位(SL)及各级止盈(TP1-TP5)。
[*]青色区域:突破后的预期盈利区间。
2. 交易策略建议
[*]入场条件
价格收盘突破Entry线后入场,止损设于SL线。
[*]止盈管理

[*]保守:TP1(1倍风险回报)。
[*]激进:分批平仓至TP3或TP5。
[*]过滤规则

[*]避免交易红色警告箱体。
[*]超限箱体(橙色)仅当趋势强劲时考虑。
示例:欧元/美元 15分钟图设置
[*]
[*]
[*]
[*]
StartTime_GMT = "07:00";      // 对应本地时间10:00(GMT+3)EndTime_GMT = "10:00";      // 对应本地时间13:00MinBoxSizeInPips = 10;      // 最小10点波动才有效TP3Factor = 2.5;            // 第三止盈目标为箱体高度的2.5倍效果:识别上午10-13点的价格箱体,当突破时提供3个止盈目标参数:部分代码展示:
[*]
//+------------------------------------------------------------------+//|                                                    时段箱体突破.mq4 |//|                              Copyright © 2009-2024, www.QChaos.com |//|                                          https://www.qchaos.com/ |//+------------------------------------------------------------------+#property copyright "Copyright © 量化混沌, www.qchaos.com"#property link      "https://www.qchaos.com"#property version   "2.01"#property strict#property indicator_chart_window#define VERSION "时段箱体突破V_2.01"
//---- 输入参数(用户可配置)-----------------------------------------extern string Info                                 = VERSION;      // 版本信息extern string StartTime_GMT                        = "06:00";       // GMT时区箱体开始时间extern string EndTime_GMT                        = "09:30";       // GMT时区箱体结束时间extern string note1          = "-----定义突破时段----------";         // 时段说明1extern string note2          = "-----1,2,3=9点,4=10点,5=11点,6=伦敦时段--"; // 时段说明2extern string note3          = "-----1-2-3-4-5-6=亚洲时段----------";   // 时段说明3extern string adjust_GMT_time_offset_brocker_time= " 时区偏移(正数或负数)";extern int    adjust_GMT_time_offset__brocker_time = 3;             // 经纪商时间与GMT时差(小时)colorSessionColor                              = clrLinen;   // 时段背景颜色extern int    NumDays                              = 2;            // 回溯天数extern int    MinBoxSizeInPips                     = 5;            // 最小交易箱体点数extern int    MaxBoxSizeInPips                     = 300;          // 最大交易箱体点数extern bool   LimitBoxToMaxSize                  = false;      // 是否限制最大箱体尺寸extern bool   StickBoxToLatestExtreme            = false;      // 是否吸附到最新极值extern bool   StickBoxOusideSRlevels               = false;      // 是否吸附到支撑阻力外extern double EntryFactor                        = 0.15;         // 入场偏移系数
//---- 止盈参数 ----extern double TP1Factor                                  = 1.000;      // TP1系数extern double TP2Factor;                                                 // TP2系数(TP1和TP3中间值)extern double TP3Factor                                  = 3.0;          // TP3系数extern double TP4Factor;                                                 // TP4系数(TP3和TP5中间值)extern double TP5Factor                                  = 5.0;          // TP5系数(0=禁用TP4/TP5)extern string TP2_help                                 = "TP2是TP1和TP3中间值";extern string TP4_help                                 = "TP4是TP3和TP5中间值";
//---- 止损参数 ----extern double SLFactor                           = 0.65;         // 止损系数extern double LevelsResizeFactor                         = 1.0;          // 级别缩放系数
//---- 图形颜色设置 ----extern colorBoxColorOK                           = clrLightBlue; // 有效箱体颜色extern colorBoxColorNOK                        = clrRed;       // 无效箱体颜色extern colorBoxColorMAX                        = clrOrange;    // 超限箱体颜色extern colorLevelColor                           = clrDarkGray;// 水平线颜色extern bool   showProfitZone                     = true;         // 显示盈利区域extern colorProfitColor                        = clrMediumTurquoise;// 盈利区域颜色
//---- 图形对象设置 ----string objPrefix                            = "LB1-";       // 对象名前缀string button_note1          = "------------------------------";ENUM_BASE_CORNER   btn_corner            = CORNER_LEFT_UPPER; // 按钮位置string btn_text            = "QC";         // 按钮文字string btn_Font            = "Arial";       // 按钮字体int    btn_FontSize          = 7;             // 按钮字号colorbtn_text_color      = clrDarkGray;   // 按钮文字颜色colorbtn_background_color= clrWhite;      // 按钮背景色colorbtn_border_color      = clrBlack;      // 按钮边框色int    button_x            = 600;         // 按钮X坐标int    button_y            = 12;            // 按钮Y坐标int    btn_Width             = 20;            // 按钮宽度int    btn_Height            = 10;            // 按钮高度
//---- 全局变量 ----bool   show_data             = true;               // 是否显示数据string IndicatorName, IndicatorObjPrefix;            // 指标名称和前缀double pip;                                          // 点值int    digits, BarsBack;                           // 品种精度,回溯柱数
//---- 交易级别变量 ----double BuyEntry,BuyTP1,BuyTP2,BuyTP3,BuyTP4,BuyTP5,BuySL;// 多单各级别double SellEntry,SellTP1,SellTP2,SellTP3,SellTP4,SellTP5,SellSL; // 空单各级别int    SL_pips,TP1_pips,TP2_pips,TP3_pips,TP4_pips,TP5_pips;    // 点数形式参数double TP1FactorInput,TP2FactorInput,TP3FactorInput,TP4FactorInput,TP5FactorInput,SLFactorInput; // 输入参数备份//---- 箱体相关变量 ----datetime tBoxStart,tBoxEnd;                        // 箱体起止时间datetime tSessionStart,tSessionEnd;                  // 交易时段起止datetime tLastComputedSessionStart,tLastComputedSessionEnd; // 最后计算时段double boxHigh,boxLow,boxExtent,boxMedianPrice;      // 箱体最高价、最低价、幅度、中值
//---- 辅助变量 ----int StartShift,EndShift;               // 时段位移量datetime alreadyDrawn;                   // 已绘制标记
//+------------------------------------------------------------------+string GenerateIndicatorName(const string target) //don't change anything here          //no cambies nada aqui{   string name = target;   int try         = 2;   while(WindowFind(name) != -1)   {      name = target + " #" + IntegerToString(try                                                ++);   }   return name;}//+------------------------------------------------------------------+string buttonId;
//+------------------------------------------------------------------+//|                                                                  |//+------------------------------------------------------------------+int init(){   IndicatorName = GenerateIndicatorName(btn_text);   IndicatorObjPrefix = "__" + IndicatorName + "__";   IndicatorShortName(IndicatorName);   IndicatorDigits(Digits);
   double val;   if(GlobalVariableGet(IndicatorName + "_visibility", val))      show_data = val != 0;
// put init() here   RemoveObjects(objPrefix);   getpip();
   BarsBack = NumDays*(PERIOD_D1/Period());   alreadyDrawn = 0;
//save input Factors;   TP1FactorInput = TP1Factor;   TP3FactorInput = TP3Factor;   TP5FactorInput = TP5Factor;   SLFactorInput= SLFactor;
   TP2Factor = (TP1Factor+TP3Factor)/2;   TP4Factor = (TP3Factor+TP5Factor)/2;
// StickBoxOusideSRlevels mode requires LimitBoxToMaxSize and StickBoxToLatestExtreme options true   if(StickBoxOusideSRlevels==true)   {      LimitBoxToMaxSize = true;      StickBoxToLatestExtreme = true;   }
   ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, 1);   buttonId = IndicatorObjPrefix + "CloseButton";   createButton(buttonId, btn_text, btn_Width, btn_Height, btn_Font, btn_FontSize, btn_background_color, btn_border_color, btn_text_color);   ObjectSetInteger(0, buttonId, OBJPROP_YDISTANCE, button_y);   ObjectSetInteger(0, buttonId, OBJPROP_XDISTANCE, button_x);
   return 0;}//+------------------------------------------------------------------+//don't change anything herevoid createButton(string buttonID,string buttonText,int width,int height,string font,int fontSize,color bgColor,color borderColor,color txtColor){   ObjectDelete(0,buttonID);   ObjectCreate(0,buttonID,OBJ_BUTTON,0,0,0);   ObjectSetInteger(0,buttonID,OBJPROP_COLOR,txtColor);   ObjectSetInteger(0,buttonID,OBJPROP_BGCOLOR,bgColor);   ObjectSetInteger(0,buttonID,OBJPROP_BORDER_COLOR,borderColor);   ObjectSetInteger(0,buttonID,OBJPROP_BORDER_TYPE,BORDER_RAISED);   ObjectSetInteger(0,buttonID,OBJPROP_XSIZE,width);   ObjectSetInteger(0,buttonID,OBJPROP_YSIZE,height);   ObjectSetString(0,buttonID,OBJPROP_FONT,font);   ObjectSetString(0,buttonID,OBJPROP_TEXT,buttonText);   ObjectSetInteger(0,buttonID,OBJPROP_FONTSIZE,fontSize);   ObjectSetInteger(0,buttonID,OBJPROP_SELECTABLE,0);   ObjectSetInteger(0,buttonID,OBJPROP_CORNER,btn_corner);   ObjectSetInteger(0,buttonID,OBJPROP_HIDDEN,1);   ObjectSetInteger(0,buttonID,OBJPROP_XDISTANCE,9999);   ObjectSetInteger(0,buttonID,OBJPROP_YDISTANCE,9999);}//+------------------------------------------------------------------+int deinit(){   ObjectsDeleteAll(ChartID(), IndicatorObjPrefix);
//put deinit() here   RemoveObjects(objPrefix);
   return 0;}//+------------------------------------------------------------------+//don't change anything herebool recalc = true;
//+------------------------------------------------------------------+//|                                                                  |//+------------------------------------------------------------------+void handleButtonClicks(){   if(ObjectGetInteger(0, buttonId, OBJPROP_STATE))   {      ObjectSetInteger(0, buttonId, OBJPROP_STATE, false);      show_data = !show_data;      GlobalVariableSet(IndicatorName + "_visibility", show_data ? 1.0 : 0.0);      recalc = true;      start();   }}//+------------------------------------------------------------------+void OnChartEvent(const int id, //don't change anything here                  const long &lparam,                  const double &dparam,                  const string &sparam){   handleButtonClicks();}//+------------------------------------------------------------------+int start2(){   handleButtonClicks();   recalc = false;   int i, limit, counted_bars=IndicatorCounted();
   limit = MathMin(BarsBack,Bars);
   for(i=limit; i>=0; i--)   {      new_tick(i);   } // limit loop   return 0;}//+------------------------------------------------------------------+int start(){   handleButtonClicks();   recalc = false;   int i, limit, counted_bars=IndicatorCounted();
   limit = MathMin(BarsBack,Bars-counted_bars-1);
   for(i=limit; i>=0; i--)   {      new_tick(i);   } // limit loop
   if(show_data)   {      start2();   }   else   {      RemoveObjects(objPrefix);   }   return 0;}//+------------------------------------------------------------------+void new_tick(int i) // i = bar number: 0=current(last) bar//+------------------------------------------------------------------+{   datetime now = Time;
//determine box and session times   if(TimeDayOfWeek(now) == 1 || TimeDayOfWeek(now) == 2 || TimeDayOfWeek(now) == 3 || TimeDayOfWeek(now) == 4 || TimeDayOfWeek(now) == 5) //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////::   {
      // compute LEVELS values:      compute_LB_Indi_LEVELS(now);
      show_boxes(now);   }
}//new_tick()

tbh1314 发表于 2025-6-27 23:12:47

路过看看加收藏[微笑]

qtxh1008 发表于 2025-6-28 00:16:39

收藏收藏

jxj600 发表于 2025-6-28 04:36:10

可以可以的

崽崽0626 发表于 2025-6-28 05:38:36

若箱体幅度超出预设范围,可自动限制最大尺寸或吸附到最近的极值点?

1594135666 发表于 2025-6-28 06:06:46

谢谢分享[微笑]

123654789 发表于 2025-6-28 06:57:07

怎么用的

lilihuan 发表于 2025-6-28 07:00:38

我喜欢箱体突破

湘聚缘 发表于 2025-6-28 09:26:38

使用情况如何

sjwlyl 发表于 2025-6-28 11:57:49

看上去不怎么样

dayu1362007 发表于 2025-7-1 20:45:46

路过看看加收藏使用情况如何

minggege 发表于 2025-7-3 00:24:28

还可以,只是盈亏比小了点

btenns 发表于 2025-7-4 22:48:10

根本加载不了

dayu1362007 发表于 2025-7-4 22:52:15

路过看看加收藏只是盈亏比小了点

lijize2025 发表于 2025-11-14 19:28:17

有人用过没,效果如可

pppbbb123bn 发表于 2026-5-13 21:09:57

路过看看加收藏a
页: [1]
查看完整版本: 【时段箱体突破】指定时间段箱体突破