Obtener valor de varias HLINE o OBJ_TREND

 

hola amigos, soy nuevo en la programacion, y e estado intentando obtener valor de un objeto grafico, para generar condiciones para señales, e intentado obtener valores de los objetos pero no e sido capaz de poner la condicion de cuando toque el objeto genere una flecha si alguien mas experto en el tema me puede orientar le agradeceria mucho ahy dejo mi codigo gracias buen dia

string SR;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {   

   IndicatorBuffers(2);

   SetIndexBuffer(0, Buffer1);

   PlotIndexSetInteger(0, PLOT_ARROW,234);

   SetIndexArrow(0, 234);

   SetIndexBuffer(1, Buffer2);

   PlotIndexSetInteger(1, PLOT_ARROW,233);

   SetIndexArrow(1, 233);

   //initialize myPoint

   

   SR = "nombre de objeto";

   ChartSetInteger(0, CHART_EVENT_OBJECT_DELETE, true);

   ChartSetInteger(0, CHART_EVENT_OBJECT_CREATE, true);

   

   myPoint = Point();

   if(Digits() == 5 || Digits() == 3)

     {

      myPoint *= 10;

     }

   return(INIT_SUCCEEDED);

  }



void OnDeinit(const int reason) {

 

}

void OnTick() {

 

}

void OnChartEvent(const int id,

                  const long &lparam,

                  const double &dparam,

                  const string &sparam) {

   // For the first situation I know a new arrow is created for a signal

   // Only react on new arrow

    

   // Only on object_create

   if (id==CHARTEVENT_OBJECT_CREATE) {

      NewObject(sparam);

      return;

   }

}



void  NewObject(string name) {

    

   // Only on name matching test_arrow_*

   if (StringSubstr(name, 0, StringLen(SR))!=SR) return;

   // Quick check that the object exists in the correct window

   //    I'm looking at window 0

   int sub_window = ObjectFind(0, name);

   if (sub_window!=0)   return;

    

   // Only buy arrows or sell arrows

   long type = ObjectGetInteger(0, name, OBJPROP_TYPE);

   if (type!=OBJ_HLINE && type!=OBJ_TREND) return;

   // Report the object found

   ReportObject("New", name);

    

}



void  ReportObject(string event, string name) {

    

   // Now I have an object, grab some properties but what you do depends on the strategy

   datetime object_time    =  (datetime)ObjectGetInteger(0, name, OBJPROP_TIME);

   ENUM_OBJECT object_type =  (ENUM_OBJECT)ObjectGetInteger(0, name, OBJPROP_TYPE);

   int      object_bar     =  iBarShift(Symbol(), Period(), object_time);

   double   object_price   =  ObjectGetDouble(0, name, OBJPROP_PRICE);

   double   bar_high       =  iHigh(Symbol(), Period(), object_bar);

   double   bar_low        =  iLow(Symbol(), Period(), object_bar);  

}

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

//| 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 limit = 1000;

   //--- counting from 0 to rates_total

   ArraySetAsSeries(Buffer1, true);

   ArraySetAsSeries(Buffer2, true);

   //--- initial zero

   if(prev_calculated < 1)

     {

      ArrayInitialize(Buffer1, 0);

      ArrayInitialize(Buffer2, 0);

     }

   else

      limit++;

   

   //--- main loop

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

     {

     testnew(i);

     }

   return(rates_total);

  }

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



void testnew(int i )

{



double SRf1 =  ObjectGetDouble(0,SR,OBJPROP_PRICE);

double SRf2 = ObjectGetDouble(0,SR,OBJPROP_PRICE2);



if

//lts

 (

High[i]<=SRf1 && High[i+1] >SRf1



)



{

Buffer1[0+i] = High[0+i]+10*Point;

}

else

{

Buffer1[0+i] = 0;

}









if



(

Low[i]>=SRf2 && Low[i+1]< SRf2

)



{

Buffer2[0+i] = Low[0+i]-10*Point;

}

else

{

Buffer2[0+i] = 0;

}

}
Documentación para MQL5: Indicadores personalizados / PlotIndexSetInteger
Documentación para MQL5: Indicadores personalizados / PlotIndexSetInteger
  • www.mql5.com
PlotIndexSetInteger - Indicadores personalizados - Manual de referencia de MQL5 - manual de usuario para el lenguaje del trading algorítmico/automático para MetaTrader 5