首页
学习
活动
专区
圈层
工具
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

MT4免费指标:5周高物线多空指标(源码分享)

量化团队将不定期的公布一些经典技术指标改版源码公式

获取方式:

1.直接复制下方代码进MQL4编译器保存

2.进企鹅群下载:567490800

实时监控市场无周内高低点变化,附带自动开关

#property copyright "公众号:量化分析院"#property link      "https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzA3Mjc2MDg2OA==&action=getalbum&album_id=1677133959354204165&sessionid=715373730&token=2043477756&lang=zh_CN&scene=21#wechat_redirect"

#property indicator_chart_window

extern color  High1_LineColor = clrLime;extern color  Low1_LineColor  = clrRed;extern color  High2_LineColor = clrDodgerBlue;extern color  Low2_LineColor  = clrFireBrick;extern color  High3_LineColor = clrCyan;extern color  Low3_LineColor  = clrOrange;extern color  High4_LineColor = clrGreen;extern color  Low4_LineColor  = clrMaroon;extern color  High5_LineColor = clrGreenYellow;extern color  Low5_LineColor  = clrCoral;

extern int    LineWidth       = 2;extern bool   ShowW1          = true;extern bool   ShowW2          = true;extern bool   ShowW3          = true;extern bool   ShowW4          = true;extern bool   ShowW5          = true;

//Forex-Station button template start41; copy and pasteextern string             button_note1          = "------------------------------";extern int                btn_Subwindow         = 0;                               // What window to put the button on.  If <0, the button will use the same sub-window as the indicator.extern ENUM_BASE_CORNER   btn_corner            = CORNER_LEFT_UPPER;               // button corner on chart for anchoringextern string             btn_text              = "5WeekHL";                       // a button nameextern string             btn_Font              = "Arial";                         // button font nameextern int                btn_FontSize          = 9;                               // button font size             extern color              btn_text_ON_color     = clrLime;                         // ON color when the button is turned onextern color              btn_text_OFF_color    = clrRed;                          // OFF color when the button is turned offextern color              btn_background_color  = clrDimGray;                      // background color of the buttonextern color              btn_border_color      = clrBlack;                        // border color the buttonextern int                button_x              = 20;                              // x coordinate of the button   extern int                button_y              = 25;                              // y coordinate of the button   extern int                btn_Width             = 80;                              // button widthextern int                btn_Height            = 20;                              // button heightextern string             UniqueButtonID        = "FiveWeekHL";                    // Unique ID for each button       extern string             button_note2          = "------------------------------";

bool show_data, recalc=false;string IndicatorObjPrefix, buttonId;//Forex-Station button template end41; copy and paste

string LabelID = "5WHL";double Poin, timeX = 0, range, targetline;//+------------------------------------------------------------------------------------------------------------------+//Forex-Station button template start42; copy and pasteint OnInit(){  IndicatorDigits(Digits);  IndicatorObjPrefix = "_" + btn_text + "_";

 // The leading "_" gives buttonId a *unique* prefix.  Furthermore, prepending the swin is usually unique unless >2+ of THIS indy are displayed in the SAME sub-window. (But, if >2 used, be sure to shift the buttonId position)  buttonId = "_" + IndicatorObjPrefix + UniqueButtonID + "_BT_";  if (ObjectFind(buttonId)<0)     createButton(buttonId, btn_text, btn_Width, btn_Height, btn_Font, btn_FontSize, btn_background_color, btn_border_color, btn_text_ON_color);  ObjectSetInteger(0, buttonId, OBJPROP_YDISTANCE, button_y);  ObjectSetInteger(0, buttonId, OBJPROP_XDISTANCE, button_x);

 init2();

 show_data = ObjectGetInteger(0, buttonId, OBJPROP_STATE);

 if (show_data) ObjectSetInteger(0,buttonId,OBJPROP_COLOR,btn_text_ON_color);  else ObjectSetInteger(0,buttonId,OBJPROP_COLOR,btn_text_OFF_color);  return(INIT_SUCCEEDED);}//+------------------------------------------------------------------------------------------------------------------+void createButton(string buttonID,string buttonText,int width2,int height,string font,int fontSize,color bgColor,color borderColor,color txtColor){     ObjectDelete    (0,buttonID);     ObjectCreate    (0,buttonID,OBJ_BUTTON,btn_Subwindow,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,width2);     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);     // Upon creation, set the initial state to "true" which is "on", so one will see the indicator by default     ObjectSetInteger(0, buttonId, OBJPROP_STATE, true);}//+------------------------------------------------------------------------------------------------------------------+void OnDeinit(const int reason){  // If just changing a TF', the button need not be deleted, therefore the 'OBJPROP_STATE' is also preserved.  if (reason != REASON_CHARTCHANGE)     {      ObjectDelete(buttonId);      deinit2();     }}//+------------------------------------------------------------------------------------------------------------------+void OnChartEvent(const int id, //don't change anything here                 const long &lparam,                 const double &dparam,                 const string &sparam){  // If another indy on the same chart has enabled events for create/delete/mouse-move, just skip this events up front because they aren't  //    needed, AND in the worst case, this indy might cause MT4 to hang!!  Skipping the events seems to help, along with other (major) changes to the code below.  if(id==CHARTEVENT_OBJECT_CREATE || id==CHARTEVENT_OBJECT_DELETE) return; // This appears to make this indy compatible with other programs that enabled CHART_EVENT_OBJECT_CREATE and/or CHART_EVENT_OBJECT_DELETE  if(id==CHARTEVENT_MOUSE_MOVE    || id==CHARTEVENT_MOUSE_WHEEL)   return; // If this, or another program, enabled mouse-events, these are not needed below, so skip it unless actually needed.//   if(id==CHARTEVENT_CHART_CHANGE) ScreenDrawing();

 if (id==CHARTEVENT_OBJECT_CLICK && sparam == buttonId)  {     show_data = ObjectGetInteger(0, buttonId, OBJPROP_STATE);

    if (show_data)     {        ObjectSetInteger(0,buttonId,OBJPROP_COLOR,btn_text_ON_color);        init2();        // Is it a problem to call 'start()' ??  Possibly it makes no difference, but now calling "mystart()" instead of "start()"; and "start()" simply runs "mystart()", so should be same as before.        recalc=true;        mystart();     }     else     {        ObjectSetInteger(0,buttonId,OBJPROP_COLOR,btn_text_OFF_color);        deinit2();     }  }}//Forex-Station button template end42; copy and paste//+------------------------------------------------------------------------------------------------------------------+//+------------------------------------------------------------------+//| Custom indicator initialization function                         |//+------------------------------------------------------------------+int init2(){   if (Point==0.00001) Poin=0.0001;  else {     if (Point==0.001) Poin=0.01;     else Poin=Point;  } //Print("I is ", i); if(Period()==1   )timeX=60;if(Period()==5    )timeX=300;if(Period()==15   )timeX=900; if(Period()==30  )timeX=1800;if(Period()==60   )timeX=3600;if(Period()==240  )timeX=14400; if(Period()==1440)timeX=86400;if(Period()==10080)timeX=604800;if(Period()==43200)timeX=2592000;

return(0);}//+------------------------------------------------------------------------------------------------------------------+//+------------------------------------------------------------------+//| Custor indicator deinitialization function                       |//+------------------------------------------------------------------+int deinit2(){  deleteObjects();

return(0);}//+------------------------------------------------------------------------------------------------------------------+void deleteObjects(){  string lookFor       = LabelID;  int    lookForLength = StringLen(lookFor);  for (int i=ObjectsTotal()-1; i>=0; i--)  {     string objectName = ObjectName(i);        if (StringSubstr(objectName,0,lookForLength) == lookFor) ObjectDelete(objectName);  }}//+------------------------------------------------------------------------------------------------------------------+/*//+------------------------------------------------------------------+//| ChartEvent function                                              |//+------------------------------------------------------------------+void OnChartEvent(const int id,                 const long &lparam,                 const double &dparam,                 const string &sparam) {//---   if(id==CHARTEVENT_CHART_CHANGE) ScreenDrawing();//---

}

*///+------------------------------------------------------------------------------------------------------------------+//+------------------------------------------------------------------+//| Custom indicator iteration function                              |//+------------------------------------------------------------------+int start() {return(mystart()); }//+------------------------------------------------------------------------------------------------------------------+int mystart() {  if (show_data)     {       if(recalc)       {          // If a button goes from off-to-on, everything must be recalculated.  The 'recalc' variable is used as a trigger to do this.          recalc=false;       }       RefreshRates();       ScreenDrawing();     } //if (show_data)  return (0);}//+------------------------------------------------------------------------------------------------------------------+void ScreenDrawing(){  MqlRates rates[];  ArraySetAsSeries(rates,true);  int copied = CopyRates(Symbol(),PERIOD_W1,0,5,rates);

 if ( copied > 0)  {     DrawVLine(LabelID + "d1openvline", rates[4].time,clrYellow,1,STYLE_DOT);

    int x,y;     if(ShowW1){     DrawLine(LabelID + "high1", rates[0].time,Time[0] + timeX*5, rates[0].high, rates[0].high,  High1_LineColor,LineWidth,STYLE_SOLID);     ChartTimePriceToXY(0, 0,Time[0] + timeX*5, rates[0].high, x, y);     x = x -50;     y = y + 0 ;     DrawLabel(LabelID + "high1text",x,y,"High Week 1 @ "+DoubleToStr(rates[0].high,Digits),8,"Arial",High1_LineColor,DoubleToStr(rates[0].high,Digits));

    DrawLine(LabelID + "low1", rates[0].time,Time[0] + timeX*5,rates[0].low,rates[0].low, Low1_LineColor,LineWidth,STYLE_SOLID);     ChartTimePriceToXY(0, 0,Time[0] + timeX*5, rates[0].low, x, y);     x = x -50;     y = y + 0 ;     DrawLabel(LabelID + "low1text",x,y,"Low Week 1 @ "+DoubleToStr(rates[0].low,Digits),8,"Arial",Low1_LineColor, DoubleToStr(rates[0].low,Digits));     }     //======     if(ShowW2){     DrawLine(LabelID + "high2", rates[1].time,Time[0] + timeX*5, rates[1].high, rates[1].high,  High2_LineColor,LineWidth,STYLE_SOLID);     ChartTimePriceToXY(0, 0,Time[0] + timeX*5, rates[1].high, x, y);     x = x -50;     y = y + 0;     DrawLabel(LabelID + "high2text",x,y,"High Week 2 @ "+DoubleToStr(rates[1].high,Digits),8,"Arial",High2_LineColor,DoubleToStr(rates[1].high,Digits));

    DrawLine(LabelID + "low2", rates[1].time,Time[0] + timeX*5,rates[1].low,rates[1].low, Low2_LineColor,LineWidth,STYLE_SOLID);     ChartTimePriceToXY(0, 0,Time[0] + timeX*5, rates[1].low, x, y);     x = x -50;     y = y + 0;     DrawLabel(LabelID + "low2text",x,y,"Low Week 2 @ "+DoubleToStr(rates[1].low,Digits),8,"Arial",Low2_LineColor, DoubleToStr(rates[1].low,Digits));      }      //======      if(ShowW3){     DrawLine(LabelID + "high3", rates[2].time,Time[0] + timeX*5, rates[2].high, rates[2].high,  High3_LineColor,LineWidth,STYLE_SOLID);     ChartTimePriceToXY(0, 0,Time[0] + timeX*5, rates[2].high, x, y);     x = x -150;     y = y + 0;     DrawLabel(LabelID + "high3text",x,y,"High Week 3 @ "+DoubleToStr(rates[2].high,Digits),8,"Arial",High3_LineColor, DoubleToStr(rates[2].high,Digits));

    DrawLine(LabelID + "low3", rates[2].time,Time[0] + timeX*5,rates[2].low,rates[2].low, Low3_LineColor,LineWidth,STYLE_SOLID);     ChartTimePriceToXY(0, 0,Time[0] + timeX*5, rates[2].low, x, y);     x = x -150;     y = y + 0;     DrawLabel(LabelID + "low3text",x,y,"Low Week 3 @ "+DoubleToStr(rates[2].low,Digits),8,"Arial",Low3_LineColor, DoubleToStr(rates[2].low,Digits));    }       //======       if(ShowW4){     DrawLine(LabelID + "high4", rates[3].time,Time[0] + timeX*5, rates[3].high, rates[3].high,  High4_LineColor,LineWidth,STYLE_SOLID);     ChartTimePriceToXY(0, 0,Time[0] + timeX*5, rates[3].high, x, y);     x = x -200;     y = y + 0;     DrawLabel(LabelID + "high4text",x,y,"High Week 4 @ "+DoubleToStr(rates[3].high,Digits),8,"Arial",High4_LineColor, DoubleToStr(rates[3].high,Digits));

    DrawLine(LabelID + "low4", rates[3].time,Time[0] + timeX*5,rates[3].low,rates[3].low, Low4_LineColor,LineWidth,STYLE_SOLID);     ChartTimePriceToXY(0, 0,Time[0] + timeX*5, rates[3].low, x, y);     x = x -200;     y = y + 0;     DrawLabel(LabelID + "low4text",x,y,"Low Week 4 @ "+DoubleToStr(rates[3].low,Digits),8,"Arial",Low4_LineColor, DoubleToStr(rates[3].low,Digits));    }     //======     if(ShowW5){     DrawLine(LabelID + "high5", rates[4].time,Time[0] + timeX*5, rates[4].high, rates[4].high,  High5_LineColor,LineWidth,STYLE_SOLID);     ChartTimePriceToXY(0, 0,Time[0] + timeX*5, rates[4].high, x, y);     x = x -250;     y = y + 0;     DrawLabel(LabelID + "high5text",x,y,"High Week 5 @ "+DoubleToStr(rates[4].high,Digits),8,"Arial",High5_LineColor, DoubleToStr(rates[4].high,Digits));

    DrawLine(LabelID + "low5", rates[4].time,Time[0] + timeX*5,rates[4].low,rates[4].low, Low5_LineColor,LineWidth,STYLE_SOLID);     ChartTimePriceToXY(0, 0,Time[0] + timeX*5, rates[4].low, x, y);     x = x -250;     y = y + 0;     DrawLabel(LabelID + "low5text",x,y,"Low Week 5 @ "+DoubleToStr(rates[4].low,Digits),8,"Arial",Low5_LineColor, DoubleToStr(rates[4].low,Digits));   } }    WindowRedraw();}//+------------------------------------------------------------------------------------------------------------------+void DrawPriceValues(string name, double price,color textcolor, int fontsize  ){

if (ObjectFind(name) ) ObjectDelete(name);

ObjectCreate(name, OBJ_TEXT, 0, Time[0],price); ObjectSet(name, OBJPROP_ANGLE, 0);

ObjectSetText(name,DoubleToStr(price,2) ,fontsize, "Corbel", textcolor);}//+------------------------------------------------------------------+//| Draws a pips distance for SL or TP.                              |//+------------------------------------------------------------------+void DrawPrice(string name, datetime time1, double price1, color col, int fontSize, string text){  int x, y;

// Needed only for y, x is derived from the chart width.  ChartTimePriceToXY(0, 0, time1, price1, x, y);  DrawLabel(name,x,y-10,text,fontSize,"Arial",col,DoubleToStr(price1,Digits));

}//+------------------------------------------------------------------------------------------------------------------+void DrawPipDiff(string name, datetime time1, double price1, color col, int fontSize, string text, int Yposition){  int x, y;

// Needed only for y, x is derived from the chart width.  ChartTimePriceToXY(0, 0, time1, price1, x, y);  DrawLabel(name,x,y-Yposition,text,fontSize,"Arial",col,DoubleToStr(price1,Digits));

}//+------------------------------------------------------------------------------------------------------------------+void DrawLabel(string name,int x,int y,string label,int size=9,string font="Arial",color clr=DimGray,string tooltip="") {  if (ObjectFind(name)) ObjectDelete(name);  ObjectCreate(name,OBJ_LABEL,0,0,0);  ObjectSetText(name,label,size,font,clr);  ObjectSet(name,OBJPROP_CORNER,0);  ObjectSet(name,OBJPROP_XDISTANCE,x);  ObjectSet(name,OBJPROP_YDISTANCE,y);  ObjectSetString(0,name,OBJPROP_TOOLTIP,tooltip);//--- justify text//ObjectSet(name, OBJPROP_ANCHOR, 0);//ObjectSetString(0, name, OBJPROP_TOOLTIP, tooltip);//ObjectSet(name, OBJPROP_SELECTABLE, 0);//--- }//+------------------------------------------------------------------------------------------------------------------+//+------------------------------------------------------------------+//|  Custom indicator initialization function                        |//+------------------------------------------------------------------+void DrawVLine(string name, datetime Time1, color lcolor, int lwidth,ENUM_LINE_STYLE linestyle){

 ObjectCreate   (name,            OBJ_VLINE, 0, Time1,0);//, dValue);  ObjectSet      (name,            OBJPROP_STYLE, linestyle);  ObjectSet      (name,            OBJPROP_COLOR, lcolor);}//+------------------------------------------------------------------------------------------------------------------+void DrawLine(string name, datetime Time1, datetime Time2, double Price1, double Price2,color lcolor, int lwidth,ENUM_LINE_STYLE linestyle){         ObjectDelete(name);         ObjectCreate(name,OBJ_TREND,0,Time1,0,Time2,0);                             ObjectSet(name,OBJPROP_COLOR,lcolor);         if (linestyle == STYLE_SOLID)         ObjectSet(name,OBJPROP_WIDTH,lwidth);                 ObjectSet(name,OBJPROP_STYLE,linestyle);               ObjectSet(name,OBJPROP_RAY,false);                     ObjectSet(name,OBJPROP_PRICE1,Price1);         ObjectSet(name,OBJPROP_PRICE2,Price2);                 } //+------------------------------------------------------------------------------------------------------------------+void DrawObjects(datetime dt, string no, string tb, string te) { datetime t1, t2; double   p1, p2; int      b1, b2;

t1=StrToTime(TimeToStr(dt, TIME_DATE)+" "+tb); t2=StrToTime(TimeToStr(dt, TIME_DATE)+" "+te); b1=iBarShift(NULL, 0, t1); b2=iBarShift(NULL, 0, t2); p1=High[Highest(NULL, 0, MODE_HIGH, b1-b2, b2)]; p2=Low [Lowest (NULL, 0, MODE_LOW , b1-b2, b2)]; ObjectSet(no, OBJPROP_TIME1 , t1); ObjectSet(no, OBJPROP_PRICE1, p1); ObjectSet(no, OBJPROP_TIME2 , t2); ObjectSet(no, OBJPROP_PRICE2, p2);}//+------------------------------------------------------------------------------------------------------------------+datetime decDateTradeDay (datetime dt) { int ty=TimeYear(dt); int tm=TimeMonth(dt); int td=TimeDay(dt); int th=TimeHour(dt); int ti=TimeMinute(dt);

td--; if (td==0) {   tm--;   if (tm==0) {     ty--;     tm=12;   }   if (tm==1 || tm==3 || tm==5 || tm==7 || tm==8 || tm==10 || tm==12) td=31;   if (tm==2) if (MathMod(ty, 4)==0) td=29; else td=28;   if (tm==4 || tm==6 || tm==9 || tm==11) td=30; } return(StrToTime(ty+"."+tm+"."+td+" "+th+":"+ti));}//+------------------------------------------------------------------------------------------------------------------+void CreateObjects(string no, color cl) { ObjectCreate(no, OBJ_RECTANGLE, 0, 0,0, 0,0); ObjectSet(no, OBJPROP_STYLE, STYLE_SOLID); ObjectSet(no, OBJPROP_COLOR, cl); ObjectSet(no, OBJPROP_BACK, True);}//+------------------------------------------------------------------------------------------------------------------+

  • 发表于:
  • 原文链接https://page.om.qq.com/page/OBRGypvHzD6kJaVp-Uxir26Q0
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券