cm SignalLines L

Author: Copyright © 2020, Vladimir Hlystov
Orders Execution
Checks for the total of open orders
0 Views
0 Downloads
0 Favorites
cm SignalLines L
ÿþ//+------------------------------------------------------------------+

//|                                                 signallength.mq4 |

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

#property copyright "Copyright © 2020, Vladimir Hlystov"

#property link      "Amillion@narod.ru"

#property strict

extern color colorfon = clrNONE;

extern color Color_resistance = clrOrange;

extern color Color_resistance_Fon = clrBisque;

extern color Color_support     = clrAqua;

extern color Color_support_Fon = clrLightCyan;

extern color Color_orders      = clrLime;

extern int Set=10;

int per;

#property indicator_chart_window

//color colorfon;

int nnn=0;

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

int OnInit(void)

{

   if (colorfon != clrNONE) ChartSetInteger(0,CHART_COLOR_BACKGROUND,colorfon);

   colorfon=(color)ChartGetInteger(0,CHART_COLOR_BACKGROUND);

   per=Period();

   return(INIT_SUCCEEDED);

}

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

void OnDeinit(const int reason)

{

   if (reason!=REASON_PARAMETERS && reason!=REASON_CHARTCHANGE && reason!=REASON_RECOMPILE)

   {

      ObjectDelete("border R line");

      ObjectDelete("border S line");

   }

}

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

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 i,nn=0;

   for (i=0; i<OrdersTotal(); i++)

      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

         if (OrderSymbol()==Symbol()) nn++;

   if (nn>0) ChartSetInteger(0,CHART_COLOR_BACKGROUND,Color_orders);

   else      ChartSetInteger(0,CHART_COLOR_BACKGROUND,colorfon);

   

   //---

   

   if (ObjectFind("border R line")==-1)

   {

      draw_borders("border R line",Color_resistance,Time[0],Ask+Set*20*Point,Time[0]+per*600,Ask+Set*20*Point);

   }

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

   if (ObjectFind("border S line")==-1)

   {

      draw_borders("border S line",Color_support,Time[0],Bid-Set*20*Point,Time[0]+per*600,Bid-Set*20*Point);

   }

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

   datetime X_1,X_2,X3d;

   double Y_1,Y_2,Y3d;

   color COLOR;

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

   {

      string Name=ObjectName(n);

      if (StringFind(Name,"border",0)!=-1 && ObjectType(Name)==OBJ_TREND)

      {

         X_1 = (datetime)ObjectGet(Name, OBJPROP_TIME1); 

         X_2 = (datetime)ObjectGet(Name, OBJPROP_TIME2); 

         if (X_1==X_2) {ObjectDelete(Name);continue;}

         Y_1 = ObjectGet(Name, OBJPROP_PRICE1);

         Y_2 = ObjectGet(Name, OBJPROP_PRICE2);

         COLOR= (color)ObjectGet(Name, OBJPROP_COLOR);

         if (X_1<=Time[0] && X_2>=Time[0])

         {

            X3d=Time[0];

            Y3d=ObjectGetValueByShift(Name,0);

            if (MathAbs(Y3d-Bid)/Point < Set)

            { 

              

               if (COLOR==Color_resistance)

                     {if (nn==0) ChartSetInteger(0,CHART_COLOR_BACKGROUND,Color_resistance_Fon);break;}

               else  {if (nn==0) ChartSetInteger(0,CHART_COLOR_BACKGROUND,Color_support_Fon);break;}

            }

         }

      }

   }

   return(rates_total);

}

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

void draw_borders(string Name, color COLOR,datetime X1,double Y1,datetime X2,double Y2)

{

   ObjectCreate(Name, OBJ_TREND, 0,X1,Y1,X2,Y2);

   ObjectSet   (Name, OBJPROP_COLOR, COLOR);

   ObjectSet   (Name, OBJPROP_STYLE, STYLE_SOLID);

   ObjectSet   (Name, OBJPROP_WIDTH, 4);

   ObjectSet   (Name, OBJPROP_BACK,  false);

   ObjectSet   (Name, OBJPROP_RAY,   false);

}

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



Comments