BreakOut Space Center Projection

Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Miscellaneous
It issuies visual alerts to the screenIt sends emails
0 Views
0 Downloads
0 Favorites
BreakOut Space Center Projection
ÿþ//+------------------------------------------------------------------+

//|                       Break_Out_Projection_and_trend_cast_v1.mq4 |

//|                                               Vladimir Smolnikov |

//|                            https://www.mql5.com/ru/users/melvill |

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

#property copyright "Author: Dmitri Nepo Copyright https://www.mql5.com/ru/users/dimanep"

#property link      "https://www.mql5.com/ru/users/dimanep"

#property version   "1.00"

#property strict

#property indicator_chart_window





input int     numberBarsAnalysis      = 1; // Number Bars Analysis

extern int    barsToProcess           = 10000; // Bars to Show BreakOut Spaces

extern string _Signal                 = "Signals";

input int     minimumBreakoutSpace    = 100; // Minimum Points new BreakOut Space

input bool    signalAlert             = true; // Terminal Window

input bool    signalMobileTerminal    = true; // Mobile

input bool    signalMail              = true; // E-Mail

extern string _Color                  = "Indicator Colors";

input color   colorTopLine            = clrBlue; // Top Fractal Line

input color   colorCenterLine         = clrGold; // Center Line

input color   colorBottomLine         = clrRed; // Bottom Fractal Line

input color   colorStartDashHover     = clrRed; // Start Line Dash

input color   colorStartDash          = clrGold; // Start Line Dash Hover

input color   colorFinishDash         = clrMediumSpringGreen; // Continue Line Dash

input color   colorButtonProjection   = clrYellow; // Buttons

input color   colorText               = clrWhite; // Delete Button text

input color   colorButtonDel          = clrGreen; // Button Delete Line



bool     layingThreeLines = false; // 5A;8 70D8:A8@>20=0 ?5@20O B>G:0 =0 3@0D8:5, 7=0G8B ?@>;06820NBAO 2A5 2>7<>6=K5 20@80=BK B@5=4>2KE ;8=89

bool     fixationCentrLine = false; // 5A;8 70D8:A8@>20=0 F5=B@0;L=0O ;8=8O fixationCentrLine AB05B true

bool     buttomDelete = false; // 4;O C40;5=8O :=>?:8 Delete

bool     fix3Line = false;     // ?0@0<5B5@ 4;O B>3> GB>1K ;8=88 =5 D8:A8@>20;8AL ?@8 ?5@2>< =060B88 =0 10@

bool     newEvent;             // 5A;8 =0ABC?8;> =>2>5 A>1KB85 newEvent ?@8@02=8205BAO : sparam 8 >68405BAO >?OBL =>2>5 A>1KB85

datetime timeFirstDot;         // 2@5<O ?5@2>9 B>G:8 ;8=89 B@5=40

datetime prevtime = 0;

double   priceFirstDot;        // F5=0 ?5@2>9 B>G:8 ;8=89 B@5=40

string   newSparam;

string   nameDeleteLine;       // 8<O ;8=88 :>B>@CN =C6=> C40;8BL

string   g_nameStartLine;       // ?5@5<5==0O 4;O E@0=5=8O 8<5=8 >1J5:B0 =0 :>B>@>< ?@>87>H;> =060B85



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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   //--- 2:;NG5=85 A>>1I5=89 > ?5@5<5I5=88 <KH8 ?> >:=C G0@B0

   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,1);

   //--- =>?:0

   ButtonCreate(0, "breakButton", 0, 650, 30, 72, 30, CORNER_LEFT_LOWER, "Projection", "Arial", 10, clrBlack, colorButtonProjection, clrNONE, false, false, false, true, 0);

   ButtonCreate(0, "breakDelAllLines", 0, 10, 30, 98, 30, CORNER_LEFT_LOWER, "Delete All Lines", "Arial", 10, clrBlack, colorButtonProjection, clrNONE, false, false, false, true, 0);

   prevtime = iTime(_Symbol, _Period, 0);

   ChartShowObjectDescriptionSet(false, 0);

//---

   return(INIT_SUCCEEDED);

  }



void OnDeinit(const int reason)

  {

   ObjectsDeleteAll(0, "breakRectangle", 0);

   ObjectsDeleteAll(0, "break", 0);

  }

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

//| Custom indicator iteration function                              |

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

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[])

  {

  

   double dotLeftBar = 0, dotRightBar = 0;

   datetime t1 = 0, t2 = 0;



   int counted_bars = IndicatorCounted(),

       limit;

 

   if(counted_bars > 0)

      counted_bars --;



   limit = Bars - counted_bars;

  

   if(limit>barsToProcess)

      limit=barsToProcess;

    if(counted_bars == 0)

      limit = limit - 1;

   

   for(int i=1; i<limit; i++)

     {

      if(ObjectFind("breakRectangle" + (string)Time[i]) >= 0)

            ObjectDelete("breakRectangle" + (string)Time[i]);

      if(iHigh(_Symbol, Period(), i+1) < iLow (_Symbol, Period(), i-1))  // 5A;8 B@5=4 225@E

        {

         if(MathAbs((i+1) - (i-1))>2)continue;

         dotLeftBar = iHigh(_Symbol, Period(), i+1);   // 25@E ;52>9 A25G8

         dotRightBar = iLow (_Symbol, Period(), i-1);  // =87 ?@02>9 A25G8

         t1 = iTime(_Symbol, Period(), i+1);

         t2 = iTime(_Symbol, Period(), i-1);

         RectangleCreate(0, "breakRectangle" + (string)Time[i], 0, t1, dotLeftBar, t2, dotRightBar, clrBrown, STYLE_SOLID, 1, true, true, false, false, 0);

        }

      if(iHigh(_Symbol, Period(), i-1) < iLow (_Symbol, Period(), i+1))

        {

         if(MathAbs((i+1) - (i-1))>2)continue;

         dotLeftBar = iLow (_Symbol, Period(), i+1);   // =87 ;52>9 A25G8

         dotRightBar = iHigh(_Symbol, Period(), i-1);  // 25@E ?@02>9 A25G8

         t1 = iTime(_Symbol, Period(), i+1);

         t2 = iTime(_Symbol, Period(), i-1);

         RectangleCreate(0, "breakRectangle" + (string)Time[i], 0, t1, dotLeftBar, t2, dotRightBar, clrBrown, STYLE_SOLID, 1, true, true, false, false, 0);

        }

     }

   

   if(iTime(_Symbol, _Period, 0) == prevtime) return(rates_total);

   prevtime = iTime(_Symbol, _Period, 0);

   

   if(iHigh(_Symbol, _Period, 2+1) < iLow (_Symbol, _Period, 2-1) || iHigh(_Symbol, _Period, 2-1) < iLow (_Symbol, _Period, 2+1))

     {

      if(iLow (_Symbol, _Period, 2-1) - iHigh(_Symbol, _Period, 2+1) > minimumBreakoutSpace*Point || iLow (_Symbol, _Period, 2+1) - iHigh(_Symbol, _Period, 2-1) > minimumBreakoutSpace*Point)

        {

         string text_space = " - new breakout space detected";

         signal(text_space);

        }

     }

   return(rates_total);

  }

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



void OnChartEvent(const int id,

                  const long &lparam,

                  const double &dparam,

                  const string &sparam)

  {

   if(newSparam != sparam){

         newSparam = sparam;

         newEvent = true;}

   

   //--- A;8 MB> A>1KB85 =060B8O =0 >1J5:B

   if(id==CHARTEVENT_OBJECT_CLICK)

     {

      g_nameStartLine = sparam;     // D8:A0F8O =0720=8O >1J5:B0 =0 :>B>@>< ?@>87>H;> =060B85 <KH8

      fixLine(sparam);

      if(sparam == "breakButton" && ObjectGetInteger(0, "breakButton", OBJPROP_STATE) == false)

        {

         fixationCentrLine = false;

         layingThreeLines = false;

         newEvent = false;

         fix3Line = false;

         if(ObjectFind("breakEndTrend")>=0)

            ObjectDelete(0, "breakEndTrend");

         if(ObjectFind("breakTopTrend")>=0)

            ObjectDelete(0, "breakTopTrend");

         if(ObjectFind("breakBottomTrend")>=0)

            ObjectDelete(0, "breakBottomTrend");

         if(ObjectFind("linefixStartTrend")>=0)

            ObjectDelete(0, "linefixStartTrend");

        }

       deleteLine(sparam, (int)lparam, (int) dparam);

       deleteAllLine(sparam);



      return;

     }

   

   

   // #40;5=85 :=>?:8 Delete ?@8 =060B88 :=>?:8 <KH8 =0 ;N1>5 4@C3>5 <5AB> :@><5 :=>?:8

   if(id==CHARTEVENT_CLICK)

     {

      if(buttomDelete == true)

      if(ObjectFind("breakDelLine") >= 0 && ObjectGetInteger(0, "breakDelLine", OBJPROP_STATE) == false)

        {

         ObjectDelete(0, "breakDelLine");

        }

      buttomDelete = true;

     }



//--- 5A;8 MB> A>1KB8O ?5@5<5I5=85 <KH8 8 =060B85 :=>?>: <KH8

   if(id==CHARTEVENT_MOUSE_MOVE)

     {

      string sp = sparam;

      //--- ?>43>B>28< ?5@5<5==K5

      int      x     =(int)lparam;

      int      y     =(int)dparam;

      datetime dt    =0;

      double   price =0;

      int      window=0;

      

      int      startingBarNumber = -1;

      //--- ?@5>1@07C5< :>>@48=0BK X 8 Y  2 B5@<8=0E 40B0/2@5<O

      if(ChartXYToTimePrice(0,x,y,window,dt,price))

        {



         if(ChartTimePriceToXY(0,window,dt,price,x,y))

            PrintFormat("Time=%s  Price=%G  =>  X=%d  Y=%d",TimeToString(dt),price,x,y);

                  

         // A;8 =060B0 :=>?:0, B>340 @8AC5BAO ?5@20O B>G:0 B@5=4>2KE ;8=89

         if(ObjectGetInteger(0, "breakButton", OBJPROP_STATE) && layingThreeLines == false)

           {

            string nameStartTrend = "breakStartTrend";

            string nameStartUpFractal = "breakStartUpFractal";

            string nameStartBottFractal = "breakStartBottFractal";

            double dotLeftBar = 0, dotRightBar = 0, center = 0;

            double upperFractal = 0, bottomFractal = 0;

            

            startingBarNumber = iBarShift(_Symbol, _Period, dt, true);  // =><5@ 10@0 =0 :>B>@>3> =0E>48BAO :C@A>@ <KH8

            if(startingBarNumber == -1) return;

            if(iHigh(_Symbol, _Period, startingBarNumber+1) < iLow (_Symbol, _Period, startingBarNumber-1))  // 5A;8 B@5=4 225@E

              {

               dotLeftBar = iHigh(_Symbol, _Period, startingBarNumber+1);   // 25@E ;52>9 A25G8

               dotRightBar = iLow (_Symbol, _Period, startingBarNumber-1);  // =87 ?@02>9 A25G8

              }

            if(iHigh(_Symbol, _Period, startingBarNumber-1) < iLow (_Symbol, _Period, startingBarNumber+1))

              {

               dotLeftBar = iLow (_Symbol, _Period, startingBarNumber+1);   // =87 ;52>9 A25G8

               dotRightBar = iHigh(_Symbol, _Period, startingBarNumber-1);  // 25@E ?@02>9 A25G8

              }

            center = (dotLeftBar+dotRightBar)/2;                           // F5=B@ ?CAB>BK A25G8

            

          //?@545;5=85 25@E=8E 8 =86=8E D@0:B0;>2

            //5@E=89 D@0:B0;

            if(startingBarNumber > 0)

            if(iHigh(_Symbol, _Period, startingBarNumber+1) < iHigh(_Symbol, _Period, startingBarNumber) && 

               iHigh(_Symbol, _Period, startingBarNumber-1) < iHigh(_Symbol, _Period, startingBarNumber))

              {

               upperFractal = (MathMax(iHigh(_Symbol, _Period, startingBarNumber+1), iHigh(_Symbol, _Period, startingBarNumber-1))+iHigh(_Symbol, _Period, startingBarNumber))/2;

              }

            // 86=89 D@0:B0;

            if(iLow(_Symbol, _Period, startingBarNumber+1) > iLow(_Symbol, _Period, startingBarNumber) && 

               iLow(_Symbol, _Period, startingBarNumber-1) > iLow(_Symbol, _Period, startingBarNumber))

              {

               bottomFractal = (MathMin(iLow(_Symbol, _Period, startingBarNumber+1), iLow(_Symbol, _Period, startingBarNumber-1))+iLow(_Symbol, _Period, startingBarNumber))/2;

              }

              

            

            if(center == 0)

              {

               if(ObjectFind(nameStartTrend)>=0)

               ObjectDelete(0, nameStartTrend);

               //return;

              }

            

            color colStDash = colorStartDash;

            // A;8 =060B0 ;520O :=>?:0 <KH8, B>340 ?5@20O B>G:0 D8:A8@C5BAO

            /*if(sp == "1") 

              {

               layingThreeLines = true;

               fixationCentrLine = false;

               nameStartTrend = "fixstart" + (string)GetTickCount();

               timeFirstDot = iTime(_Symbol, _Period, startingBarNumber);

               priceFirstDot = center;

               newEvent = false;

               colStDash = colorStartDashHover;

              }*/

              

              

            // A;8 ?@>87>H;> =060B85 =0 ;8=8N >=0 4>;6=0 70D8:A8@>20BLAO

            datetime t1 = iTime(_Symbol, _Period, startingBarNumber+1); // 2@5<O ?5@2>9 B>G:8 ;8=88 =0 AB0@B>2>< 10@5

            datetime t2 = iTime(_Symbol, _Period, startingBarNumber-1); // 2@5<O ?5@2>9 B>G:8 ;8=88 =0 AB0@B>2>< 10@5



            if(g_nameStartLine == nameStartTrend || g_nameStartLine == nameStartUpFractal || g_nameStartLine == nameStartBottFractal)

              {

               layingThreeLines = true;

               fixationCentrLine = false;

               timeFirstDot = iTime(_Symbol, _Period, startingBarNumber);

               newEvent = false;

               colStDash = colorStartDashHover;

               f_DelStartLine(nameStartTrend, nameStartUpFractal, nameStartBottFractal);

               

               if(g_nameStartLine == nameStartTrend)

                 {

                  nameStartTrend = "fixstart" + (string)GetTickCount();

                  priceFirstDot = center;

                  TrendCreate(0, nameStartTrend, 0, t1, center, t2, center, colStDash, STYLE_SOLID, 2, false, false, false, false, 0);

                 }

               if(g_nameStartLine == nameStartUpFractal)

                 {

                  nameStartTrend = "fixstart" + (string)GetTickCount();

                  priceFirstDot = upperFractal;

                  TrendCreate(0, nameStartTrend, 0, t1, upperFractal, t2, upperFractal, colStDash, STYLE_SOLID, 2, false, false, false, false, 0);

                 }

               if(g_nameStartLine == nameStartBottFractal)

                 {

                  nameStartTrend = "fixstart" + (string)GetTickCount();

                  priceFirstDot = bottomFractal;

                  TrendCreate(0, nameStartTrend, 0, t1, bottomFractal, t2, bottomFractal, colStDash, STYLE_SOLID, 2, false, false, false, false, 0);

                 }

               return;

              }



            

            

          

          //#40;5=85 AB0@KE =0G0;L=KE B>G5: ?5@54 ?>AB@>5=85< =>2KE

            f_DelStartLine(nameStartTrend, nameStartUpFractal, nameStartBottFractal);

          

          //!>740=85 =>2KE =0G0;L=KE B>G5:

            if(dotLeftBar != 0 && dotRightBar != 0 && center != 0)

               TrendCreate(0, nameStartTrend, 0, t1, center, t2, center, colStDash, STYLE_SOLID, 2, false, false, false, false, 0);

            if(upperFractal != 0)

              {

               TrendCreate(0, nameStartUpFractal, 0, t1, upperFractal, t2, upperFractal, colStDash, STYLE_SOLID, 2, false, false, false, false, 0);

              }

            if(bottomFractal != 0)

              {

               TrendCreate(0, nameStartBottFractal, 0, t1, bottomFractal, t2, bottomFractal, colStDash, STYLE_SOLID, 2, false, false, false, false, 0);

              }

           }

           

//--- A;8 ?5@20O B>G:0 70D8:A8@>20;0AL @8ACNBAO <0:A8<C< 3 ;8=88

         string nameCenterTrend = "breakEndTrend", nameTopTrend = "breakTopTrend", nameBottomTrend = "breakBottomTrend";

         if(layingThreeLines == true && fixationCentrLine == false)

           {

            double dotLeftBar = 0, dotRightBar = 0, center = 0, TOP_LINE = 0, BOTTOM_LINE = 0;

            datetime t_c = 0, t_t = 0, t_b = 0;

            int numBar = -1;



            //--- KG8A;5=85 F5=B@0 ?CAB>BK

            startingBarNumber = iBarShift(_Symbol, _Period, dt, true);  // =><5@ 10@0 =0 :>B>@>3> =0E>48BAO :C@A>@ <KH8

            

            if(timeFirstDot == iTime(_Symbol, _Period, startingBarNumber)){

            return;

            }

            if(startingBarNumber == -1) return;

         // 5A;8 B@5=4 225@E

            if(iHigh(_Symbol, _Period, startingBarNumber+1) < iLow (_Symbol, _Period, startingBarNumber-1))  

              {

              //--- !@54=OO ;8=8O

               dotLeftBar = iHigh(_Symbol, _Period, startingBarNumber+1);   // 25@E ;52>9 A25G8

               dotRightBar = iLow (_Symbol, _Period, startingBarNumber-1);  // =87 ?@02>9 A25G8

               t_c = iTime(_Symbol, _Period, startingBarNumber); // 2@5<O =0 2B>@>9 B>G:5 4;O F5=B@0;L=>9 ;8=88

              }

         //--- A;8 B@5=4 2=87

            if(iHigh(_Symbol, _Period, startingBarNumber-1) < iLow (_Symbol, _Period, startingBarNumber+1))

              {

               //--- !@54=OO ;8=8O

               dotLeftBar = iLow (_Symbol, _Period, startingBarNumber+1);   // =87 ;52>9 A25G8

               dotRightBar = iHigh(_Symbol, _Period, startingBarNumber-1);  // 25@E ?@02>9 A25G8

               t_c = iTime(_Symbol, _Period, startingBarNumber); // 2@5<O =0 2B>@>9 B>G:5 4;O F5=B@0;L=>9 ;8=88

              }

              

           //--- 5@E=OO ;8=8O

           int maxBar, minBar;

           extremumBars(maxBar, minBar, startingBarNumber);

           

            if(maxBar >= 0)

              {

               TOP_LINE = (iHigh(_Symbol, _Period, maxBar) + MathMax(iHigh(_Symbol, _Period, maxBar-1), iHigh(_Symbol, _Period, maxBar+1)))/2;

              }

            else TOP_LINE = 0;

            t_t = iTime(_Symbol, _Period, maxBar); // 2@5<O =0 2B>@>9 B>G:5 4;O 25@E=59 ;8=88

           

           //--- 86=OO ;8=8O

            if(minBar >= 0)

              {

               BOTTOM_LINE = (iLow(_Symbol, _Period, minBar) + MathMin(iLow(_Symbol, _Period, minBar+1), iLow(_Symbol, _Period, minBar-1)))/2;

              }

            else BOTTOM_LINE = 0;

            t_b = iTime(_Symbol, _Period, minBar); // 2@5<O =0 2B>@>9 B>G:5 4;O =86=59 ;8=88 

            

            center = (dotLeftBar+dotRightBar)/2;                           // F5=B@ ?CAB>BK A25G8

            

            //-------------------------------------------------------------------------

            //-------------------------------------------------------------------------

            

            if(ObjectFind(nameCenterTrend)>=0)

               ObjectDelete(0, nameCenterTrend);

            if(ObjectFind(nameTopTrend)>=0)

               ObjectDelete(0, nameTopTrend);

            if(ObjectFind(nameBottomTrend)>=0)

               ObjectDelete(0, nameBottomTrend);

               

            if(dotLeftBar != 0 && dotRightBar != 0 && center != 0)

               TrendCreate(0, nameCenterTrend, 0, timeFirstDot, priceFirstDot, t_c, center, colorCenterLine, STYLE_DASH, 1, false, false, true, false, 0);

            

            if(TOP_LINE != 0)

               TrendCreate(0, nameTopTrend, 0, timeFirstDot, priceFirstDot, t_t, TOP_LINE, colorTopLine, STYLE_DASH, 1, false, false, true, false, 0);

            if(BOTTOM_LINE != 0)

               TrendCreate(0, nameBottomTrend, 0, timeFirstDot, priceFirstDot, t_b, BOTTOM_LINE, colorBottomLine, STYLE_DASH, 1, false, false, true, false, 0);

            

            // A;8 ?@>8AE>48B :;8: ;52>9 :=>?:>9 <KH8 F5=B@0;L=0O ;8=8O D8:A8@C5BAO, 8 ?5@5@8A>2K205BAO 2 A?;>H=CN

            // >AB0;L=K5 ;8=8 >AB0NBAO ?C=:B8@=K<8, => D8:A8@CNBAO 8 =5 C40;ONBAO ?@8 ?5@5<5H5=88 <KH8 2;52>-2?@02>

            

            if(sp == "1")

              {

               fixationCentrLine = true;  // A;8 70D8:A8@>20;0AL A@54=OO ;8=8O

               newEvent = false;

               return;

              }

            newEvent = false;

           }

         ChartRedraw(0);

        }

     }

  }



void fixLine(string sparam)

  {

   string nameCenterTrend = "breakEndTrend", nameTopTrend = "breakTopTrend", nameBottomTrend = "breakBottomTrend";

   string nameLinePressed = sparam;

   if(nameLinePressed == nameTopTrend || nameLinePressed == nameCenterTrend || nameLinePressed == nameBottomTrend)

     {

      if(fixationCentrLine == true && fix3Line == true)

        {

         if(newEvent == true)

           {

            datetime t_t, t_b, t_c;

            double TOP_LINE, BOTTOM_LINE, center;

   

            if( nameLinePressed == nameTopTrend )

              {

               t_t = (datetime)ObjectGet(nameTopTrend, OBJPROP_TIME2);

               TOP_LINE = ObjectGet(nameTopTrend, OBJPROP_PRICE2);

               if(ObjectFind(nameTopTrend)>=0)

                 {

                  ObjectDelete(0, nameTopTrend);

                  TrendCreate(0, "linefixT"+(string)GetTickCount(), 0, timeFirstDot, priceFirstDot, t_t, TOP_LINE, colorTopLine, STYLE_SOLID, 1, false, false, true, false, 0);

                  TrendCreate(0, "linefixT2Dot"+(string)GetTickCount(), 0, iTime(_Symbol, _Period, iBarShift(_Symbol, _Period, t_t)+1), TOP_LINE, iTime(_Symbol, _Period, iBarShift(_Symbol, _Period, t_t)-1), TOP_LINE, colorFinishDash, STYLE_SOLID, 2, false, false, false, false, 0);

                 }

               newEvent = false;

               releaseButton(nameTopTrend, nameCenterTrend, nameBottomTrend);

               return;

              }

              

            if( nameLinePressed == nameCenterTrend )

              {

               t_c = (datetime)ObjectGet(nameCenterTrend, OBJPROP_TIME2);

               center = ObjectGet(nameCenterTrend, OBJPROP_PRICE2);

               if(ObjectFind(nameCenterTrend)>=0)

                 {

                  ObjectDelete(0, nameCenterTrend);

                  TrendCreate(0, "linefixTC"+(string)GetTickCount(), 0, timeFirstDot, priceFirstDot, t_c, center, colorCenterLine, STYLE_SOLID, 1, false, false, true, false, 0);

                  TrendCreate(0, "linefixC2Dot"+(string)GetTickCount(), 0, iTime(_Symbol, _Period, iBarShift(_Symbol, _Period, t_c)+1), center, iTime(_Symbol, _Period, iBarShift(_Symbol, _Period, t_c)-1), center, colorFinishDash, STYLE_SOLID, 2, false, false, false, false, 0);

                 }

               newEvent = false;

               releaseButton(nameTopTrend, nameCenterTrend, nameBottomTrend);

               return;

              }

              

            if( nameLinePressed == nameBottomTrend )

              {

               t_b = (datetime) ObjectGet(nameBottomTrend, OBJPROP_TIME2);

               BOTTOM_LINE = ObjectGet(nameBottomTrend, OBJPROP_PRICE2);

               if(ObjectFind(nameBottomTrend)>=0)

                 {

                  ObjectDelete(0, nameBottomTrend);

                  TrendCreate(0, "linefixB"+(string)GetTickCount(), 0, timeFirstDot, priceFirstDot, t_b, BOTTOM_LINE, colorBottomLine, STYLE_SOLID, 1, false, false, true, false, 0);

                  TrendCreate(0, "linefixB2Dot"+(string)GetTickCount(), 0, iTime(_Symbol, _Period, iBarShift(_Symbol, _Period, t_b)+1), BOTTOM_LINE, iTime(_Symbol, _Period, iBarShift(_Symbol, _Period, t_b)-1), BOTTOM_LINE, colorFinishDash, STYLE_SOLID, 2, false, false, false, false, 0);

                 }

               newEvent = false;

               releaseButton(nameTopTrend, nameCenterTrend, nameBottomTrend);

               return;

              }

           }

        }

      fix3Line = true;

      }

  }

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

//| !>7405B ;8=8N B@5=40 ?> 7040==K< :>>@48=0B0<                     | 

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

bool TrendCreate(const long            chart_ID=0,        // ID 3@0D8:0 

                 const string          name="TrendLine",  // 8<O ;8=88 

                 const int             sub_window=0,      // =><5@ ?>4>:=0 

                 datetime              time1=0,           // 2@5<O ?5@2>9 B>G:8 

                 double                price1=0,          // F5=0 ?5@2>9 B>G:8 

                 datetime              time2=0,           // 2@5<O 2B>@>9 B>G:8 

                 double                price2=0,          // F5=0 2B>@>9 B>G:8 

                 const color           clr=clrRed,        // F25B ;8=88 

                 const ENUM_LINE_STYLE style=STYLE_SOLID, // AB8;L ;8=88 

                 const int             width=1,           // B>;I8=0 ;8=88 

                 const bool            back=false,        // =0 704=5< ?;0=5 

                 const bool            selection=true,    // 2K45;8BL 4;O ?5@5<5I5=89 

                 const bool            ray_right=false,   // ?@>4>;65=85 ;8=88 2?@02> 

                 const bool            hidden=true,       // A:@KB 2 A?8A:5 >1J5:B>2 

                 const long            z_order=0)         // ?@8>@8B5B =0 =060B85 <KHLN 

  { 

//--- CAB0=>28< :>>@48=0BK B>G5: ?@82O7:8, 5A;8 >=8 =5 7040=K 

   ChangeTrendEmptyPoints(time1,price1,time2,price2); 

//--- A1@>A8< 7=0G5=85 >H81:8 

   ResetLastError(); 

//--- A>74048< B@5=4>2CN ;8=8N ?> 7040==K< :>>@48=0B0< 

   if(!ObjectCreate(chart_ID,name,OBJ_TREND,sub_window,time1,price1,time2,price2)) 

     { 

      Print(__FUNCTION__, 

            ": =5 C40;>AL A>740BL ;8=8N B@5=40! >4 >H81:8 = ",GetLastError()); 

      return(false); 

     } 

//--- CAB0=>28< F25B ;8=88 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 

//--- CAB0=>28< AB8;L >B>1@065=8O ;8=88 

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 

//--- CAB0=>28< B>;I8=C ;8=88 

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); 

//--- >B>1@078< =0 ?5@54=5< (false) 8;8 704=5< (true) ?;0=5 

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 

//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< ?5@5<5I5=8O ;8=88 <KHLN 

//--- ?@8 A>740=88 3@0D8G5A:>3> >1J5:B0 DC=:F859 ObjectCreate, ?> C<>;G0=8N >1J5:B 

//--- =5;L7O 2K45;8BL 8 ?5@5<5I0BL. =CB@8 65 MB>3> <5B>40 ?0@0<5B@ selection 

//--- ?> C<>;G0=8N @025= true, GB> ?>72>;O5B 2K45;OBL 8 ?5@5<5I0BL MB>B >1J5:B 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 

//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< ?@>4>;65=8O >B>1@065=8O ;8=88 2?@02> 

   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right); 

//--- A:@>5< (true) 8;8 >B>1@078< (false) 8<O 3@0D8G5A:>3> >1J5:B0 2 A?8A:5 >1J5:B>2 

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 

//--- CAB0=>28< ?@8>@8B5B =0 ?>;CG5=85 A>1KB8O =060B8O <KH8 =0 3@0D8:5 

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 

//--- CA?5H=>5 2K?>;=5=85 

   return(true); 

  } 

  

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

//| @>25@O5B 7=0G5=8O B>G5: ?@82O7:8 ;8=88 B@5=40 8 4;O ?CABKE      | 

//| 7=0G5=89 CAB0=02;8205B 7=0G5=8O ?> C<>;G0=8N                     | 

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

void ChangeTrendEmptyPoints(datetime &time1,double &price1, 

                            datetime &time2,double &price2) 

  { 

//--- 5A;8 2@5<O ?5@2>9 B>G:8 =5 7040=>, B> >=0 1C45B =0 B5:CI5< 10@5 

   if(!time1) 

      time1=TimeCurrent(); 

//--- 5A;8 F5=0 ?5@2>9 B>G:8 =5 7040=0, B> >=0 1C45B 8<5BL 7=0G5=85 Bid 

   if(!price1) 

      price1=SymbolInfoDouble(Symbol(),SYMBOL_BID); 

//--- 5A;8 2@5<O 2B>@>9 B>G:8 =5 7040=>, B> >=0 ;568B =0 9 10@>2 ;5255 2B>@>9 

   if(!time2) 

     { 

      //--- <0AA82 4;O ?@85<0 2@5<5=8 >B:@KB8O 10 ?>A;54=8E 10@>2 

      datetime temp[10]; 

      CopyTime(Symbol(),Period(),time1,10,temp); 

      //--- CAB0=>28< 2B>@CN B>G:C =0 9 10@>2 ;5255 ?5@2>9 

      time2=temp[0]; 

     } 

//--- 5A;8 F5=0 2B>@>9 B>G:8 =5 7040=0, B> >=0 A>2?0405B A F5=>9 ?5@2>9 B>G:8 

   if(!price2) 

      price2=price1; 

  }

  

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

//| !>7405B :=>?:C                                                   | 

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

bool ButtonCreate(const long              chart_ID=0,               // ID 3@0D8:0 

                  const string            name="Button",            // 8<O :=>?:8 

                  const int               sub_window=0,             // =><5@ ?>4>:=0 

                  const int               x=0,                      // :>>@48=0B0 ?> >A8 X 

                  const int               y=0,                      // :>>@48=0B0 ?> >A8 Y 

                  const int               width=50,                 // H8@8=0 :=>?:8 

                  const int               height=18,                // 2KA>B0 :=>?:8 

                  const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, // C3>; 3@0D8:0 4;O ?@82O7:8 

                  const string            text="Button",            // B5:AB 

                  const string            font="Arial",             // H@8DB 

                  const int               font_size=10,             // @07<5@ H@8DB0 

                  const color             clr=clrBlack,             // F25B B5:AB0 

                  const color             back_clr=C'236,233,216',  // F25B D>=0 

                  const color             border_clr=clrNONE,       // F25B 3@0=8FK 

                  const bool              state=false,              // =060B0/>B60B0 

                  const bool              back=false,               // =0 704=5< ?;0=5 

                  const bool              selection=false,          // 2K45;8BL 4;O ?5@5<5I5=89 

                  const bool              hidden=true,              // A:@KB 2 A?8A:5 >1J5:B>2 

                  const long              z_order=0)                // ?@8>@8B5B =0 =060B85 <KHLN 

  { 

//--- A1@>A8< 7=0G5=85 >H81:8 

   ResetLastError(); 

//--- A>74048< :=>?:C 

   if(!ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0)) 

     { 

      Print(__FUNCTION__, 

            ": =5 C40;>AL A>740BL :=>?:C! >4 >H81:8 = ",GetLastError()); 

      return(false); 

     } 

//--- CAB0=>28< :>>@48=0BK :=>?:8 

   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); 

   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y); 

//--- CAB0=>28< @07<5@ :=>?:8 

   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width); 

   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height); 

//--- CAB0=>28< C3>; 3@0D8:0, >B=>A8B5;L=> :>B>@>3> 1C4CB >?@545;OBLAO :>>@48=0BK B>G:8 

   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); 

//--- CAB0=>28< B5:AB 

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); 

//--- CAB0=>28< H@8DB B5:AB0 

   ObjectSetString(chart_ID,name,OBJPROP_FONT,font); 

//--- CAB0=>28< @07<5@ H@8DB0 

   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); 

//--- CAB0=>28< F25B B5:AB0 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 

//--- CAB0=>28< F25B D>=0 

   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr); 

//--- CAB0=>28< F25B 3@0=8FK 

   ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr); 

//--- >B>1@078< =0 ?5@54=5< (false) 8;8 704=5< (true) ?;0=5 

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 

//--- ?5@52545< :=>?:C 2 7040==>5 A>AB>O=85 

   ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state); 

//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< ?5@5<5I5=8O :=>?:8 <KHLN 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 

//--- A:@>5< (true) 8;8 >B>1@078< (false) 8<O 3@0D8G5A:>3> >1J5:B0 2 A?8A:5 >1J5:B>2 

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 

//--- CAB0=>28< ?@8>@8B5B =0 ?>;CG5=85 A>1KB8O =060B8O <KH8 =0 3@0D8:5 

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 

//--- CA?5H=>5 2K?>;=5=85 

   return(true); 

  } 



void extremumBars(int & maxBar, int & minBar, int startingBarNumber)

  {

   double maxHigh = -1, minLow = DBL_MAX;

   int startBar = startingBarNumber + numberBarsAnalysis;

   

   for(int i = 1; i <= (numberBarsAnalysis*2)-1; i ++)

     {

      if(startBar - i < 0) break;

      

      if(iHigh(_Symbol, _Period, startBar-i) > maxHigh)

        {

         maxHigh = iHigh(_Symbol, _Period, startBar-i);

         maxBar = startBar-i;

        }

      

      if(iLow(_Symbol, _Period, startBar-i) < minLow)

        {

         minLow = iLow(_Symbol, _Period, startBar-i);

         minBar = startBar-i;

        }

     }

   // "5?5@L <0:A8<0;L=K9 8 <8=8<0;L=K9 10@ ?@>25@O5BAO =0 D@0:B0;L=>ABL

   if(iHigh(_Symbol, _Period, maxBar+1) > iHigh(_Symbol, _Period, maxBar) || 

      iHigh(_Symbol, _Period, maxBar-1) > iHigh(_Symbol, _Period, maxBar))

      maxBar = -1;

   if(iLow(_Symbol, _Period, minBar+1) < iLow(_Symbol, _Period, minBar) || 

      iLow(_Symbol, _Period, minBar-1) < iLow(_Symbol, _Period, minBar))

      minBar = -1;

  }

  



void releaseButton(string nameTopTrend, string nameCenterTrend, string nameBottomTrend)

  {

   if(ObjectFind(nameTopTrend)<0 && ObjectFind(nameCenterTrend)<0 && ObjectFind(nameBottomTrend)<0)

     {

      ObjectSetInteger(0, "breakButton", OBJPROP_STATE, false);

      fixationCentrLine = false;

      layingThreeLines = false;

     }

  }

  

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

//| C>7405B ?@O<>C3>;L=8: ?> 7040==K< :>>@48=0B0<                    | 

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

bool RectangleCreate(const long            chart_ID=0,        // ID 3@0D8:0 

                     const string          name="Rectangle",  // 8<O ?@O<>C3>;L=8:0 

                     const int             sub_window=0,      // =><5@ ?>4>:=0  

                     datetime              time1=0,           // 2@5<O ?5@2>9 B>G:8 

                     double                price1=0,          // F5=0 ?5@2>9 B>G:8 

                     datetime              time2=0,           // 2@5<O 2B>@>9 B>G:8 

                     double                price2=0,          // F5=0 2B>@>9 B>G:8 

                     const color           clr=clrRed,        // F25B ?@O<>C3>;L=8:0 

                     const ENUM_LINE_STYLE style=STYLE_SOLID, // AB8;L ;8=89 ?@O<>C3>;L=8:0 

                     const int             width=1,           // B>;I8=0 ;8=89 ?@O<>C3>;L=8:0 

                     const bool            fill=false,        // 70;82:0 ?@O<>C3>;L=8:0 F25B>< 

                     const bool            back=false,        // =0 704=5< ?;0=5 

                     const bool            selection=true,    // 2K45;8BL 4;O ?5@5<5I5=89 

                     const bool            hidden=true,       // A:@KB 2 A?8A:5 >1J5:B>2 

                     const long            z_order=0)         // ?@8>@8B5B =0 =060B85 <KHLN 

  { 

//--- CAB0=>28< :>>@48=0BK B>G5: ?@82O7:8, 5A;8 >=8 =5 7040=K 

   ChangeRectangleEmptyPoints(time1,price1,time2,price2); 

//--- A1@>A8< 7=0G5=85 >H81:8 

   ResetLastError(); 

//--- A>74048< ?@O<>C3>;L=8: ?> 7040==K< :>>@48=0B0< 

   if(!ObjectCreate(chart_ID,name,OBJ_RECTANGLE,sub_window,time1,price1,time2,price2)) 

     { 

      Print(__FUNCTION__, 

            ": =5 C40;>AL A>740BL ?@O<>C3>;L=8:! >4 >H81:8 = ",GetLastError()); 

      return(false); 

     } 

//--- CAB0=>28< F25B ?@O<>C3>;L=8:0 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 

//--- CAB0=>28< AB8;L ;8=89 ?@O<>C3>;L=8:0 

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 

//--- CAB0=>28< B>;I8=C ;8=89 ?@O<>C3>;L=8:0 

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); 

//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< 70;82:8 ?@O<>C3>;L=8:0 

   ObjectSetInteger(chart_ID,name,OBJPROP_FILL,fill); 

//--- >B>1@078< =0 ?5@54=5< (false) 8;8 704=5< (true) ?;0=5 

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 

//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< 2K45;5=8O ?@O<>C3>;L=8:0 4;O ?5@5<5I5=89 

//--- ?@8 A>740=88 3@0D8G5A:>3> >1J5:B0 DC=:F859 ObjectCreate, ?> C<>;G0=8N >1J5:B 

//--- =5;L7O 2K45;8BL 8 ?5@5<5I0BL. =CB@8 65 MB>3> <5B>40 ?0@0<5B@ selection 

//--- ?> C<>;G0=8N @025= true, GB> ?>72>;O5B 2K45;OBL 8 ?5@5<5I0BL MB>B >1J5:B 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 

//--- A:@>5< (true) 8;8 >B>1@078< (false) 8<O 3@0D8G5A:>3> >1J5:B0 2 A?8A:5 >1J5:B>2 

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 

//--- CAB0=>28< ?@8>@8B5B =0 ?>;CG5=85 A>1KB8O =060B8O <KH8 =0 3@0D8:5 

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 

//--- CA?5H=>5 2K?>;=5=85 

   return(true); 

  }

  

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

//| @>25@O5B 7=0G5=8O B>G5: ?@82O7:8 ?@O<>C3>;L=8:0 8 4;O ?CABKE    | 

//| 7=0G5=89 CAB0=02;8205B 7=0G5=8O ?> C<>;G0=8N                     | 

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

void ChangeRectangleEmptyPoints(datetime &time1,double &price1, 

                                datetime &time2,double &price2) 

  { 

//--- 5A;8 2@5<O ?5@2>9 B>G:8 =5 7040=>, B> >=0 1C45B =0 B5:CI5< 10@5 

   if(!time1) 

      time1=TimeCurrent(); 

//--- 5A;8 F5=0 ?5@2>9 B>G:8 =5 7040=0, B> >=0 1C45B 8<5BL 7=0G5=85 Bid 

   if(!price1) 

      price1=SymbolInfoDouble(Symbol(),SYMBOL_BID); 

//--- 5A;8 2@5<O 2B>@>9 B>G:8 =5 7040=>, B> >=0 ;568B =0 9 10@>2 ;5255 2B>@>9 

   if(!time2) 

     { 

      //--- <0AA82 4;O ?@85<0 2@5<5=8 >B:@KB8O 10 ?>A;54=8E 10@>2 

      datetime temp[10]; 

      CopyTime(Symbol(),Period(),time1,10,temp); 

      //--- CAB0=>28< 2B>@CN B>G:C =0 9 10@>2 ;5255 ?5@2>9 

      time2=temp[0]; 

     } 

//--- 5A;8 F5=0 2B>@>9 B>G:8 =5 7040=0, A428=5< 55 =0 300 ?C=:B>2 =865 ?5@2>9 

   if(!price2) 

      price2=price1-300*SymbolInfoDouble(Symbol(),SYMBOL_POINT); 

  } 

  

void signal(string text)

  {

   text = _Symbol + text;

   if(signalMobileTerminal)

      SendNotification(text);

   if(signalAlert)

      Alert(text);

   if(signalMail)

      SendMail(text, text);

  }

  

void deleteLine(string sparam, int x, int y)

  {

   string nameLine = sparam;

   

   if(StringFind(nameLine, "linefix", 0) >= 0)  // 5A;8 =060;8 =0 D8:A8@>20=CN ;8=8N

     {

      if(ObjectFind("breakDelLine") >= 0)       // 5A;8 :=>?:0 C65 ACI5AB2C5B =04> 55 C40;8BL

         ObjectDelete(0, "breakDelLine");

         

      ButtonCreate(0, "breakDelLine", 0, x, y, 50, 18,   CORNER_LEFT_UPPER, "Delete",     "Arial", 10, colorText, colorButtonDel, clrNONE, false, false, false, true, 0);

      nameDeleteLine = nameLine;

      buttomDelete = false;

     }

   if(ObjectGetInteger(0, "breakDelLine", OBJPROP_STATE))   // 5A;8 :=>?:0 Delete =060B0, 7=0G8B C40;O5BAO ;8=8O 8 :=>?:0 STATE

     {

      ObjectDelete(0, "breakDelLine");

      ObjectDelete(0, nameDeleteLine);

     }

  }

  

void deleteAllLine(string sparam)

  {

   string nameObject = sparam;

   

   if(nameObject == "breakDelAllLines" && ObjectGetInteger(0, "breakDelAllLines", OBJPROP_STATE))

     {

      ObjectSetInteger(0, "breakDelAllLines", OBJPROP_STATE, false);

      ObjectsDeleteAll(0, "linefix", 0);

      ObjectsDeleteAll(0, "break", 0, OBJ_TREND);

      ObjectsDeleteAll(0, "fixstart", 0, OBJ_TREND);

     }

  }

  

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

//| $C=:F8O 2:;NG05B/2K:;NG05B @568< >B>1@065=8O 2A?;K20NI8E >?8A0=89|

//| 3@0D8G5A:8E >1J5:B>2 ?@8 =02545=85 =0 =8E <KHLN.                 |

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

bool ChartShowObjectDescriptionSet(const bool value,const long chart_ID=0)

  {

//--- A1@>A8< 7=0G5=85 >H81:8

   ResetLastError();

//--- CAB0=>28< 7=0G5=85 A2>9AB20

   if(!ChartSetInteger(chart_ID,CHART_SHOW_OBJECT_DESCR,0,value))

     {

      //--- 2K2545< A>>1I5=85 >1 >H81:5 2 6C@=0; "-:A?5@BK"

      Print(__FUNCTION__+", Error Code = ",GetLastError());

      return(false);

     }

//--- CA?5H=>5 2K?>;=5=85

   return(true);

  }

  

void f_DelStartLine(string line1, string line2, string line3)

  {

   if(ObjectFind(line1)>=0)

      ObjectDelete(0, line1);

   if(ObjectFind(line2)>=0)

      ObjectDelete(0, line2);

   if(ObjectFind(line3)>=0)

      ObjectDelete(0, line3);

  }

 

Comments