指标名称:时段箱体突破[color=rgba(0, 0, 0, 0.9)]
版本:MT4 ver. 2.01
[size=16.002px]时段箱体突破是一款用于MT4平台的交易辅助工具,通过识别特定时间窗口内的价格波动区间(箱体),自动计算突破后的潜在入场点、止损位及多级止盈目标。该指标适用于外汇、商品等市场的短线突破策略,帮助交易者快速识别关键价位。
一、指标原理
二、使用指南1. 关键功能解读箱体显示
蓝色:有效箱体(幅度在Min-Max之间)。 红色:箱体过小(需谨慎交易)。 橙色:箱体超限(被限制到Max值)。
突破信号
辅助线
2. 交易策略建议
[size=16.002px]示例:欧元/美元 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时差(小时)color SessionColor = 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 color BoxColorOK = clrLightBlue; // 有效箱体颜色extern color BoxColorNOK = clrRed; // 无效箱体颜色extern color BoxColorMAX = clrOrange; // 超限箱体颜色extern color LevelColor = clrDarkGray; // 水平线颜色extern bool showProfitZone = true; // 显示盈利区域extern color ProfitColor = 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; // 按钮字号color btn_text_color = clrDarkGray; // 按钮文字颜色color btn_background_color = clrWhite; // 按钮背景色color btn_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()
-
复制代码
|