dibujando la línea H en el máximo de los últimos 36 máximos

 

Hola

he intentado escribir en código esto

cuando la línea K% del estocástico(80,30,30) > 75, mira hacia atrás 36 barras (34,shift 2) y dibuja una línea H "tomate" desde el máximo más alto hasta la barra actual.

cuando la línea K% del estocástico(80,30,30) < 25, mira hacia atrás 36 barras (34,shift 2) y dibuja una línea H "oliva" desde el mínimo más bajo hasta la barra actual.

int start()
  {

double stoch;
stoch=iStochastic(NULL,0,Kperiod,Dperiod,Stochshift,MODE_SMA,1,MODE_MAIN,0);

double high_price,low_price;
int high_nr,low_nr;
high_nr=iHighest(NULL,0,MODE_HIGH,34,2);
high_price=High[high_nr];
low_nr=iLowest(NULL,0,MODE_LOW,34,2);
low_price=Low[low_nr];

/////////////////////////////////////////////////////////////////////////////////
for(high_nr=2;high_nr<36;high_nr++)
{

   if(Bid<high_price && stoch>75)
     {
      ObjectCreate("tomato",OBJ_TREND,0,Time[high_nr],high_price,Time[0],high_price);
      ObjectSet("tomato",OBJPROP_COLOR,Tomato);
      Print ("tomato ON"+high_price);
     }
       
}
///////////////////////////////////////////////////////////////////////////////
for(low_nr=2;low_nr<36;low_nr++)
{
if(Bid>low_price && stoch<25)
   {
   ObjectCreate("olive",OBJ_TREND,0,Time[low_nr],low_price,Time[0],low_price);
   ObjectSet("olive",OBJPROP_COLOR,Olive);
   Print ("olive ON"+low_price);
   }
}   
   
   
//----
   
//----
   return(0);
  }

cuando ejecuto esto obtengo la primera configuración para tomate y para oliva ok, entonces aunque en diario obtengo "tomate ON" diferente lvl de precio, no obtengo nueva línea de tomate en el gráfico. lo mismo para oliva.

la idea del ea es usar estas lineas para abrir operaciones. asi que lo que quiero finalmente es tener esto:

cuando K%>75

dibujar la linea o mas alta (pasadas 36 barras).

si la linea ON, no dibujar mas lineas, hasta que la linea sea borrada.

si hay una operación abierta, borrar la línea

si no hay ninguna operación abierta y han pasado 24 barras desde la barra que determinó k%>75 también borrar la línea

:)

como es mi primer código que escribo en mi vida de hoy, pls enseñarme cómo mirar el problema.

gracias

 

necesito un nombre diferente

      ObjectCreate("tomato " + high_nr,OBJ_TREND,0,Time[high_nr],high_price,Time[0],high_price);
      ObjectSet("tomato " + high_nr,OBJPROP_COLOR,Tomato);
 

después de

   ObjectCreate("olive"+low_nr,OBJ_TREND,0,Time[low_nr],low_price,Time[0],low_price);
   ObjectSet("olive"+low_nr,OBJPROP_COLOR,Olive);

el codigo pone 25 lineas, sobre el mismo precio, pero empezando no desde la vela low_nr (que siempre es 10, no importa cual es el numero real despues de stoch <25), sino desde la vela 35.

lo mismo para el tomate.

:(

 

Una vez que se ha creado un objeto, no se puede crear otro con el mismo nombre.

Por eso funciona bien la primera vez, pero no después (en tu código original)

Si sólo quiere que se muestre la última línea que cumple los criterios en su gráfico, cree la línea en init y luego use ObjectMove para mover el objeto a sus nuevas coordenadas.

Si quiere que se muestren todas las líneas anteriores,

ObjectCreate("tomato " + high_nr,OBJ_TREND,0,Time[high_nr],high_price,Time[0],high_price);

Como high_nr es el desplazamiento de la barra, es probable que se replique en un momento posterior, por lo que no funcionará correctamente. Utilice la fecha en el nombre y entonces será único

 
¿puede especificar lo que está tratando de lograr?
 
cichichan:

Hola

he intentado escribir en código esto

cuando la línea K% del estocástico(80,30,30) > 75, mira hacia atrás 36 barras (34,shift 2) y dibuja una línea H "tomate" desde el máximo más alto hasta la barra actual.

cuando la línea K% del estocástico(80,30,30) < 25, mira hacia atrás 36 barras (34,shift 2) y dibuja una línea H "oliva" desde el mínimo más bajo hasta la barra actual.

cuando ejecuto esto obtengo la primera configuración para tomate y para oliva ok, entonces aunque en el diario obtengo "tomate ON" diferente lvl de precio, no obtengo nueva línea de tomate en el gráfico. lo mismo para oliva.

la idea del ea es usar estas lineas para abrir operaciones. asi que lo que quiero finalmente es tener esto:

cuando K%>75

dibujar la linea o mas alta (pasadas 36 barras).

si la linea ON, no dibujar mas lineas, hasta que la linea sea borrada.

si hay una operación abierta, borrar la línea

si no hay ninguna operación abierta y han pasado 24 barras desde la barra que determinó k%>75 también borrar la línea

:)

como es mi primer código que escribo en mi vida de hoy, pls enseñarme cómo mirar el problema.

gracias

Empezamos en el principio .....

double stoch=iStochastic(NULL,0,Kperiod,Dperiod,Stochshift,MODE_SMA,1,MODE_MAIN,0);

En la barra 0 stoch puede llegar a algún lugar en la barra 0 valor > 75 y terminar con el valor más bajo

¿tiene que dibujar una línea en ese caso? o es sólo para el precio de cierre estocástico termina?

double high_price,low_price;
int high_nr,low_nr;
high_nr=iHighest(NULL,0,MODE_HIGH,34,2);
high_price=High[high_nr];
low_nr=iLowest(NULL,0,MODE_LOW,34,2);
low_price=Low[low_nr];

¿ha utilizado alguna vez iHighest y/o iLowest? Ver cómo hacer iHighest y iLowest

if(stoch > 75) high_price = High[iHighest(NULL,0,MODE_HIGH,......

if(stoch < 25) low_price = Low[iLowest(........

//-----

for(high_nr=2;high_nr<36;high_nr++)   // why do you repeat this ??
{

   if(Bid<high_price && stoch>75)
     {
      ObjectCreate("tomato",OBJ_TREND,0,Time[high_nr],high_price,Time[0],high_price);
      ObjectSet("tomato",OBJPROP_COLOR,Tomato);
      Print ("tomato ON"+high_price);
     }
       
}

con crear una sola vez es suficiente .... el bucle hace que sólo se repita lo que está dentro de { }

así que no se necesita ningún bucle para esto ....

entonces antes de crear

  • comprobar la ejecución de las operaciones
  • comprueba si el objeto con nombre que empieza por "tomate" ya existe y si existe entonces comprueba si tienes que borrar el antiguo

crea un nombre en el momento en que lo haces como

linenamehigh =     "tomato  "+ TimeToStr(Time[0],TIME_DATE|TIME_MINUTES)

comprobar sus objetos puede con

//----
   int i, ot=ObjectsTotal()-1;
   string id;
//----
   for(i=ot;i>=0;i--)
    {id=ObjectName(i);
     if(StringSubstr(id,0,7)=="tomato ")
      {
      //check when created 
      if(StringSubstr(id,8,...)< TimeToStr(Time[24],........)){ObjectDelete(id);}
      }  
     if(StringSubstr(id,0,6)=="olive ")
         {
         //.....
         }
    }

Haga clic en los enlaces y trate de entender lo que sucede

los lugares con ....... dentro del código puedes intentar rellenarlos tú mismo

 
qjol:
¿puede especificar lo que está tratando de lograr?


la idea final:

Señal 1 = cuando K%>75 y el máximo de la barra[1] y la barra actual[0] son menores que el máximo de la última barra de 36 (Punto_alto)

dibujar una línea de tomate en el punto alto

si la línea tomate ya está dibujada, no dibujar más líneas, hasta que la línea sea eliminada.

si hay una operación abierta utilizando la línea tomate, elimine la línea

sino hay ninguna operación abierta y han pasado 96 barras desde la barra que determinó elpunto_alto , elimine la línea.

ahora, solo obtengo una linea en cada señal 1(la funcion de impresion envia 36 "tomate ON" cada tick valido supongo), asi que tengo que decirle al codigo que detenga el bucle despues de encontrar la linea tomate. voy a cocinar algunos espaguetis y pensar como deberia escribir eso... en mi cabeza este deberia ser el proximo paso.... espero no estar perdiendo algo :)

¿estoy en el camino correcto? muchas gracias por tu ayuda y consejo.

el código hasta ahora:

//+------------------------------------------------------------------+
//|                                                      1expert.mq4 |
//|                                                              ant |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "ant"
#property link      ""

#property indicator_chart_window

extern int Kperiod = 80;
extern int Dperiod = 30;
extern int Stochshift = 30;


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

double stoch;
stoch=iStochastic(NULL,0,Kperiod,Dperiod,Stochshift,MODE_SMA,1,MODE_MAIN,0);

double high_price,low_price;
int high_nr,low_nr;
high_nr=iHighest(NULL,0,MODE_HIGH,34,2);
high_price=High[high_nr];
low_nr=iLowest(NULL,0,MODE_LOW,34,2);
low_price=Low[low_nr];
datetime H=Time[high_nr];
datetime L=Time[low_nr];

/////////////////////////////////////////////////////////////////////////////////
for(high_nr=2;high_nr<36;high_nr++)
{

   if(Bid<high_price && High[0]<high_price && High[1]<high_price && stoch>75)
     {
      ObjectCreate("tomato"+H,OBJ_TREND,0,H,high_price,Time[0],high_price);
      ObjectSet("tomato"+H,OBJPROP_COLOR,Tomato);
      Print ("tomato ON"+H);
     }
       
}
///////////////////////////////////////////////////////////////////////////////
for(low_nr=2;low_nr<36;low_nr++)
{
if(Bid>low_price && Low[0]>low_price && Low[1]>low_price && stoch<25)
   {
   ObjectCreate("olive"+L,OBJ_TREND,0,L,low_price,Time[0],low_price);
   ObjectSet("olive"+L,OBJPROP_COLOR,Olive);
   Print ("olive ON"+low_price);
   }
}   
   
   
//----
   
//----
   return(0);
  }
 

he posteado al mismo tiempo con el post deVries.

voy a leer :)

 
double high_price,low_price;
int high_nr,low_nr;
high_nr=iHighest(NULL,0,MODE_HIGH,34,2);
high_price=High[high_nr];
low_nr=iLowest(NULL,0,MODE_LOW,34,2);
low_price=Low[low_nr];
datetime H=Time[high_nr];
datetime L=Time[low_nr];

if (stoch > 75 && High[1] < High[high_nr] && High[0] < High[high_nr])
   {
   ObjectCreate("tomato"+H,OBJ_TREND,0,Time[H],high_price,Time[0],High[0]);
   ObjectSet("tomato"+H,OBJPROP_COLOR,Tomato);
   Print ("tomato ON"+H);   
   }

B.T.W. no necesita una línea para hacerlo

 

El caso que comentas cichichan raramente se dará, por lo que hay que usar un índice para que se pueda ver lo que se hace :

http://charts.mql5.com/3/799/eurusd-h1-fxpro-financial-services.png

La flecha_abajo no aparece, hay un error en alguna parte ....

//+------------------------------------------------------------------+
//|                                                      lexpert.mq4 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "ant"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 8
#property  indicator_color1 YellowGreen  
#property  indicator_color2 Coral


extern int Kperiod = 80;
extern int Dperiod = 30;
extern int Stochshift = 30;

 double arrow_up[];
 double arrow_down[];
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   //-------- 
   SetIndexBuffer(0, arrow_up );
   SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID,2);
   SetIndexArrow(0,233);
   SetIndexEmptyValue(0,0.0);
//-------- 
   SetIndexBuffer(1,arrow_down);
   SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID,2);
   SetIndexArrow(1,234 );
   SetIndexEmptyValue(1,0.0);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

   int    limit;
   int    counted_bars=IndicatorCounted();

   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   //---- macd counted in the 1-st additional buffer
   for(int i=limit; i>=0; i--)
      { 

double stoch_1, stoch_2;
stoch_2=iStochastic(NULL,0,Kperiod,Dperiod,Stochshift,MODE_SMA,1,MODE_MAIN,i+2);
stoch_1=iStochastic(NULL,0,Kperiod,Dperiod,Stochshift,MODE_SMA,1,MODE_MAIN,i+1);

double high_price,low_price;
int high_nr,low_nr;
high_nr=iHighest(NULL,0,MODE_HIGH,34,i+2);
high_price=High[high_nr];
low_nr=iLowest(NULL,0,MODE_LOW,34,i+2);
low_price=Low[low_nr];
datetime H=Time[high_nr];
datetime L=Time[low_nr];

/////////////////////////////////////////////////////////////////////////////////


   if(Bid<high_price && High[i]<high_price && High[i+1]<high_price && stoch_2<75 && stoch_1 >75)
     {
     arrow_down[i] =  High[i] + 5*iATR(NULL,0,200,i);
      ObjectCreate("tomato"+H,OBJ_TREND,0,H,high_price,Time[i],high_price);
      ObjectSet("tomato"+H,OBJPROP_RAY_RIGHT, false);
      ObjectSet("tomato"+H,OBJPROP_WIDTH,5 ); 
      ObjectSet("tomato"+H,OBJPROP_COLOR,Tomato);
      Print ("tomato ON"+H);
     }
    else    arrow_down[i] = 0.0;

///////////////////////////////////////////////////////////////////////////////

if(Bid>low_price && Low[i]>low_price && Low[i+1]>low_price &&  stoch_2>25 && stoch_1 < 25)
   {
   arrow_up[i] = Low[i] - 5*iATR(NULL,0,200,i);
   ObjectCreate("olive"+L,OBJ_TREND,0,L,low_price,Time[i],low_price);
   ObjectSet("olive"+L,OBJPROP_COLOR, Yellow );
   ObjectSet("olive"+L,OBJPROP_WIDTH,5 );
   ObjectSet("olive"+L,OBJPROP_RAY_RIGHT, false);
   Print ("olive ON"+low_price);
   }
   else  arrow_up[i] = 0.0;
   
//----
  } 
//----
   return(0);
  }
 
por su n indicador no n EA