mn1_w1_levels

Author: © Tecciztecatl 2016
6 Views
0 Downloads
0 Favorites
mn1_w1_levels
ÿþ//+------------------------------------------------------------------+

//|                                                MN1_W1_Levels.mq4 |

//|                                                  © Tecciztecatl  |

//+------------------------------------------------------------------+

#property copyright     "© Tecciztecatl 2016"

#property link          "https://www.mql5.com/en/users/tecciztecatl"

#property version       "1.00"

#property description   "The script shows the highs and lows of weeks and months."

#property script_show_inputs

#property strict



input  int      days=200;                    //Number of days

extern string   comm0="";                    //-     -   -- ---- Weeks ---- --   -     -

extern color    W1_Color=LimeGreen;          //W1 Color of lines

input  int      W1_Width=3;                  //W1 Line Width

extern ENUM_LINE_STYLE W1_style=STYLE_SOLID; //W1 Style of lines 

extern string   comm1="";                    //-     -   -- ---- Months ---- --   -     -

extern color    MN1_Color=Orange;            //MN1 Color of lines

input  int      MN1_Width=3;                 //MN1 Line Width

extern ENUM_LINE_STYLE MN1_style=STYLE_SOLID;//MN1 Style of lines 



enum  choice0 {Trend_Line=0,Horizontal_Line=1};

input choice0 object=Trend_Line;             //Trend or Horizontal line

//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+

void OnStart()

  {

   DelObject();



   int weeks=(int)MathCeil(days/7)+1;

   if(weeks>iBars(_Symbol,PERIOD_W1)) weeks=iBars(_Symbol,PERIOD_W1)-1;

   if(weeks<0) {Alert("No historical data!"); return;}

   for(int i=weeks; i>=0; i--)

     {

      if(object==Trend_Line)

        {

         SetTrendLine("W1_High_"+(string)i+"_ln",

                      iTime(_Symbol,PERIOD_W1,i)+86400,

                      iHigh(_Symbol,PERIOD_W1,i),

                      iTime(_Symbol,PERIOD_W1,i)+7*86400,

                      W1_Color,

                      W1_Width,

                      W1_style,

                      0x007f);

         SetTrendLine("W1_Low_"+(string)i+"_ln",

                      iTime(_Symbol,PERIOD_W1,i)+86400,

                      iLow(_Symbol,PERIOD_W1,i),

                      iTime(_Symbol,PERIOD_W1,i)+7*86400,

                      W1_Color,

                      W1_Width,

                      W1_style,

                      0x007f);

        }

      else

        {

         SetHLine("ln_W1_High_"+(string)i+"_ln",

                  iHigh(_Symbol,PERIOD_W1,i),

                  W1_Color,

                  W1_Width,

                  W1_style);

         SetHLine("W1_Low_"+(string)i+"_ln",

                  iLow(_Symbol,PERIOD_W1,i),

                  W1_Color,

                  W1_Width,

                  W1_style);

        }

     }



   int month=(int)MathCeil((days-Day())/30)+1;

   if(month>iBars(_Symbol,PERIOD_MN1)) month=iBars(_Symbol,PERIOD_MN1)-1;

   if(month<0) {Alert("No historical data!"); return;}

   for(int i=month; i>=0; i--)

     {

      if(object==Trend_Line)

        {

         SetTrendLine("MN1_High_"+(string)i+"_ln",

                      iTime(_Symbol,PERIOD_MN1,i),

                      iHigh(_Symbol,PERIOD_MN1,i),

                      iTime(_Symbol,PERIOD_MN1,i)+DayMonth(TimeMonth(iTime(_Symbol,PERIOD_MN1,i)),iTime(_Symbol,PERIOD_MN1,i))*86400,

                      MN1_Color,

                      MN1_Width,

                      MN1_style,

                      0x00ff);

         SetTrendLine("MN1_Low_"+(string)i+"_ln",

                      iTime(_Symbol,PERIOD_MN1,i),

                      iLow(_Symbol,PERIOD_MN1,i),

                      iTime(_Symbol,PERIOD_MN1,i)+DayMonth(TimeMonth(iTime(_Symbol,PERIOD_MN1,i)),iTime(_Symbol,PERIOD_MN1,i))*86400,

                      MN1_Color,

                      MN1_Width,

                      MN1_style,

                      0x00ff);

        }

      else

        {

         SetHLine("MN1_High_"+(string)i+"_ln",

                  iHigh(_Symbol,PERIOD_MN1,i),

                  MN1_Color,

                  MN1_Width,

                  MN1_style);

         SetHLine("MN1_Low_"+(string)i+"_ln",

                  iLow(_Symbol,PERIOD_MN1,i),

                  MN1_Color,

                  MN1_Width,

                  MN1_style);

        }

     }

   WindowRedraw();

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int DayMonth(int mon,datetime time)

  {

   int leap_year;

   switch(mon)

     {

      case  1:

      case  3:

      case  5:

      case  7:

      case  8:

      case 10:

      case 12:

         return(31);

      case  2:

         leap_year=TimeYear(time);

         if(TimeYear(time)%100==0)

            leap_year/=100;

         return((leap_year%4==0)? 29 : 28);

      case  4:

      case  6:

      case  9:

      case 11:

         return(30);

     }

   return(0);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void SetTrendLine(

                  const string         name,

                  datetime             time1,

                  double               price1,

                  datetime             time2,

                  color                cvet,

                  int                  widthL,

                  ENUM_LINE_STYLE      styleL,

                  int                  hide_TF

                  )

  {

   if(ObjectFind(0,name)<0) ObjectCreate(0,name,OBJ_TREND,0,time1,price1,time2,price1);

   ObjectMove(0,name,0,time1,price1);

   ObjectMove(0,name,1,time2,price1);

   ObjectSetInteger(0,name,OBJPROP_COLOR,cvet);

   ObjectSetInteger(0,name,OBJPROP_STYLE,styleL);

   ObjectSetInteger(0,name,OBJPROP_WIDTH,widthL);

   ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);

   ObjectSetInteger(0,name,OBJPROP_SELECTED,false);

   ObjectSetInteger(0,name,OBJPROP_BACK,false);

   ObjectSetInteger(0,name,OBJPROP_ZORDER,1);

   ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,false);

   ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);

   ObjectSetInteger(0,name,OBJPROP_TIMEFRAMES,hide_TF);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void SetHLine(

              const string         name,

              double               price1,

              color                cvet,

              int                  widthL,

              ENUM_LINE_STYLE      styleL

              )

  {

   if(ObjectFind(0,name)<0) ObjectCreate(0,name,OBJ_HLINE,0,0,price1);

   ObjectSetDouble(0,name,OBJPROP_PRICE,price1);

   ObjectSetInteger(0,name,OBJPROP_COLOR,cvet);

   ObjectSetInteger(0,name,OBJPROP_STYLE,styleL);

   ObjectSetInteger(0,name,OBJPROP_WIDTH,widthL);

   ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);

   ObjectSetInteger(0,name,OBJPROP_SELECTED,false);

   ObjectSetInteger(0,name,OBJPROP_BACK,false);

   ObjectSetInteger(0,name,OBJPROP_ZORDER,1);

   ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,false);

   ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void DelObject()

  {

   for(int i=ObjectsTotal()-1;i>=0;i--)

     {

      string temp=ObjectName(i);

      if(StringFind(temp,"_ln",0)>=0)

         ObjectDelete(0,temp);

     }

  }

//+------------------------------------------------------------------+

Comments