AutoTrenLine1.0

0 Views
0 Downloads
0 Favorites
AutoTrenLine1.0
ÿþ//+------------------------------------------------------------------+

//|AUTO TREND LINE                                                   |

//|Draw trend lines only mouse tick in grafic                        |

//|Autor: BailandoConHumo                                            |

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



input string                                 InpName="TrendLine"; // Name

input color                                  InpColor = clrBlue; // Line Color

input ENUM_LINE_STYLE                        InpStyle = STYLE_SOLID; // Line Style

input int                                    InpWidth = 1; // Line width

input bool                                   InpBack=false; // In Back

input bool                                   InpSelection=true; // Selection

input bool                                   InpRayLeft=true; // Ray Left

input bool                                   InpRayRight=true; // Ray Right

input bool                                   InpHidden = true; // Hidden

input long                                   InpZOrder = 0; // Z Order





long coorX;

double coorY;

long scape;

long pointX[2];

double pointY[2];

int contador=0;



int lineas;

string nombres[20]=

  {

   "linea1","linea2","linea3","linea4","linea5","linea6","linea7","linea8","linea9"

   "linea10","linea11","linea12","linea13","linea14","linea15","linea16","linea17",

   "linea18","linea19","linea20"

  };

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

//|Trend Create                                                      |

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

bool TrendCreate(const long                       chart_ID=0,

                 const string                     name="TrendLine",

                 const int                        sub_window=0,

                 datetime                         time1=0,

                 double                           price1= 0,

                 datetime                         time2 = 0,

                 double                           price2= 0,

                 const color                      clr=clrBlue,

                 const ENUM_LINE_STYLE            style = STYLE_SOLID,

                 const int                        width = 1,

                 const bool                       back=false,

                 const bool                       selection= true,

                 const bool                       ray_left = true,

                 const bool                       ray_right= true,

                 const bool                       hidden=false,

                 const long                       z_order=0)

  {

   ChangeTrendEmptyPoints(time1,price1,time2,price2);



   ResetLastError();



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

     {

      Print(__FUNCTION__,

            ": ¡Fallo al crear la linea de tendencia! Codigo del error: ",GetLastError());

      return(false);

     }

   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,coorX); //PAG 290    

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_LEFT,ray_left);

   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);



   return(true);

  }

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

//|Change trend points                                               |

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

void ChangeTrendEmptyPoints(datetime &time1,double &price1,

                            datetime &time2,double &price2)

  {



   if(!time1)

      time1=TimeCurrent();

   if(!price1)

      price1=SymbolInfoDouble(Symbol(),SYMBOL_BID);



   if(!time2)

     {

      datetime temp[10];

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

      time2=temp[0];

     }

   if(!price2)

      price2=price1;



  }

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

//| Trend start create                                               |

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

void TrendStartCreate()

  {

   if(!TrendCreate(0,nombres[lineas],0,pointX[0],pointY[0],pointX[1],pointY[1],InpColor,InpStyle,

      InpWidth,InpBack,InpSelection,InpRayLeft,InpRayRight,InpHidden,InpZOrder))

     {

      return;

     }

   ChartRedraw();

   Sleep(1000);

  }

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

//|On init                                                           |

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

int OnInit()

  {



   for(int i=0;i<2;i++)

     {

      pointX[i] = 0;

      pointY[i] = 0;

     }



   return(0);

  }

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

//|Mouse points parameters                                           |

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

void OnChartEvent(const int        id,

                  const long      &lparam,

                  const double    &dparam,

                  const string    &sparam)

  {

   if(id==CHARTEVENT_CLICK)

     {

      int x          =(int)lparam;

      int y          =(int)dparam;

      datetime dt    =0;

      double price   =0;

      int window     =0;



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

        {

         Print("X= ",x,"Y= ",y);

         pointX[contador] = dt;

         pointY[contador] = price;



         Print("Coordenadas del click del raton en x = ",lparam," y = ",dparam);



         contador++;

        }



     }



   for(int i=0;i<2;i++)

     {

      Print("PointX[",i,"] = ",pointX[i]);

      Print("PointY[",i,"] = ",pointY[i]);

     }

   if(contador==2)

     {

      TrendStartCreate();



      contador=0;

      lineas++;

     }



   if(id==CHARTEVENT_KEYDOWN)

     {

      scape=lparam;



      Print("Pulsada tecla ",lparam);

     }



  }                  

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

Comments