BreakOut Space Center Fixation

Price Data Components
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screenIt sends emails
0 Views
0 Downloads
0 Favorites
BreakOut Space Center Fixation
ÿþ//+------------------------------------------------------------------+

//|                                  BreakOut Space Fixation.mq4     |

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

#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

#property indicator_buffers 2        // :>;8G5AB2> 1CD5@>2

#property indicator_color1 Red       // &25B 1CD5@0 =><5@ 0

#property indicator_color2 Blue      // &25B 1CD5@0 =><5@ 1

#property indicator_width1 2

#property indicator_width2 2





input int minimumPointsNewBreakOut    = 10;

input int bufferSignalRollBackDisable = 100;

input color breakUpColor              = clrTeal;

input color breakDownColor            = clrCrimson;

input color breakUpArrowColor         = clrLightSeaGreen;

input color breakDownArrowColor       = clrMediumVioletRed;

input int   shiftSignalBar            = 0;

input bool  signals                   = true;

input bool  breakOut                  = true;

input bool  arrow                     = true;





double bufferBuy[];

double bufferSell[];



double presenceArrowBuy, presenceArrowSell; // 4;O A83=0;>2

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

  //--- 4;O 1CD5@0 =0 ?>:C?:C

   SetIndexBuffer(0, bufferBuy);  // A2O7K205B 1CD5B 0 A <0AA82>< bufferBuy

   SetIndexStyle(0, DRAW_ARROW, EMPTY, EMPTY, breakUpArrowColor);  // CAB0=02;8205B B8? "AB@5;:0" 4;O 1CD5@0 0

   SetIndexArrow(0, 225);         // B8? AB@5;:8 



  

  

  //--- 4;O 1CD5@0 =0 ?@>406C

   SetIndexBuffer(1, bufferSell);

   SetIndexStyle(1, DRAW_ARROW, EMPTY, EMPTY, breakDownArrowColor);

   SetIndexArrow(1, 226);



   return(INIT_SUCCEEDED);

  }

  

void OnDeinit(const int reason)

  {

   ObjectsDeleteAll(0, "breakRectangle", 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[])

  {

   

   int bars=Bars(Symbol(),0); 

   Print("Bars = ",bars,", rates_total = ",rates_total,", prev_calculated = ",prev_calculated); 

   Print("time[0] = ",time[0]," time[rates_total-1] = ",time[rates_total-1]); 

   

   datetime t1, t2;

   int i, limit = prev_calculated == 0 ? rates_total-3 : rates_total-prev_calculated;

   double dotLeftBar, dotRightBar;

   //ArrayResize(bufferBuy, limit);

   



   for (i = limit; i >= 0; i--)

     {

     //--- B@5=4 225@E

      

      bufferBuy[i] = EMPTY_VALUE;

      

      if(breakOut)

         RectangleDelete(0, "breakRectangle" + (string)Time[i]); // C40;5=85 ?@O<>C3>;L=8:0 =0 :064>< 10@5 8 ?>AB@>5=85 5A;8 MB> =C6=>

      

      if(High[i+2] < Low[i])       // 5A;8 B@5=4 225@E

        {

         dotLeftBar = High[i+2];   // 25@E ;52>9 A25G8

         dotRightBar = Low[i];     // =87 ?@02>9 A25G8

         t1 = Time[i+2];           // 2@5<O ;52>9 A25G8

         t2 = Time[i];             // 2@5<O ?@02>9 A25G8

         

         if(breakOut)

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

         

         // 0?8AL 7=0G5=8O AB@5;:8 2 1CD5@ =0 109

         if(dotRightBar - dotLeftBar > minimumPointsNewBreakOut*Point && arrow)

           {

            bufferBuy[i] = Low[i] - 30*Point;

           }

        }

        

     //--- B@5=4 2=87

     

      bufferSell[i] = EMPTY_VALUE;

      

      if(High[i] < Low[i+2])       // 5A;8 B@5=4 225@E

        {

         dotLeftBar = Low[i+2];   // 25@E ;52>9 A25G8

         dotRightBar = High[i];     // =87 ?@02>9 A25G8

         t1 = Time[i+2];           // 2@5<O ;52>9 A25G8

         t2 = Time[i];             // 2@5<O ?@02>9 A25G8

         

         if(breakOut)

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

         

         // 0?8AL 7=0G5=8O AB@5;:8 2 1CD5@ =0 109

         if(dotLeftBar - dotRightBar > minimumPointsNewBreakOut*Point && arrow)

            bufferSell[i] = High[i] + 30*Point;

        }

     }

  // !83=0; ?@8 ?>O2;5=88 AB@5;:8

   if((presenceArrowBuy ==EMPTY_VALUE && bufferBuy[shiftSignalBar] != EMPTY_VALUE) || (presenceArrowBuy != EMPTY_VALUE && bufferBuy[shiftSignalBar] == EMPTY_VALUE))

     {

      presenceArrowBuy = bufferBuy[shiftSignalBar];

      if(presenceArrowBuy != EMPTY_VALUE && signals)

         signal("formed UP arrow"+"  "+_Symbol);

     }

     

   if((presenceArrowSell ==EMPTY_VALUE && bufferSell[shiftSignalBar] != EMPTY_VALUE) || (presenceArrowSell != EMPTY_VALUE && bufferSell[shiftSignalBar] == EMPTY_VALUE))

     {

      presenceArrowSell = bufferSell[shiftSignalBar];

      if(presenceArrowSell != EMPTY_VALUE && signals)

         signal("formed DOWN arrow"+"  "+_Symbol);

     }

   

   

   return(rates_total);

  }

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



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

//| 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); 

  } 



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

//| #40;O5B ?@O<>C3>;L=8:                                            | 

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

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

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

  { 

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

   ResetLastError(); 

//--- C40;8< ?@O<>C3>;L=8: 

   if(ObjectFind(chart_ID, name) != -1)

   if(!ObjectDelete(chart_ID,name)) 

     { 

      Print(__FUNCTION__, 

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

      return(false); 

     } 

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

   return(true); 

  }

  



void signal(string text)

  {

   SendNotification(text);

   Alert(text);

   SendMail(text, text);

  }

Comments