drawing H_line on highest high of last 36 highs

 

Hello

i've tried to write in code this:

when K% line of stochastic(80,30,30) > 75, look back 36 bars (34,shift 2) and draw a H_line "tomato" from the highest high to current bar.

when K% line of stochastic(80,30,30) < 25, look back 36 bars (34,shift 2) and draw a H_line "olive" from the lowest low to current bar.

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

when i run this i get the first setup for tomato and for olive ok, then even if in journal i get "tomato ON" different price lvl, i don't get new tomato line on the chart. same for olive.

the idea of the ea is to use this lines to open trades. so what i will finally want is to have this:

when K%>75

draw line o highest(past 36 bars).

if line ON, draw no more lines, until the line is deleted.

if a trade is open delete the line

if no trade is open and 24 bars past from the bar that determined k%>75 also delete the line

:)

as is my first code that i wrote in my hole life, pls teach me how to look at the problem.

thank you

 

need different name

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

after

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

the code puts 25 lines, on the same price, but starting not from candle low_nr (which is always 10, doesn't matter which is the real number after stoch <25), but from candle 35.

same for tomato.

:(

 

Once an object has been created, you cannot create another object with the same name.

That is why it works fine for the very first time, but not after that (in your original code)

If you only want to have the last line that meets criteria showing on your chart, create the line in init and then use ObjectMove to move the object to its new co-ordinates.

If you want all past lines to show,

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

As high_nr is the bar shift, it will likely be replicated at a later time, so will not work properly. Use the datetime in the name and then it will be unique

 
can u specify what u r trying to accomplish ?
 
cichichan:

Hello

i've tried to write in code this:

when K% line of stochastic(80,30,30) > 75, look back 36 bars (34,shift 2) and draw a H_line "tomato" from the highest high to current bar.

when K% line of stochastic(80,30,30) < 25, look back 36 bars (34,shift 2) and draw a H_line "olive" from the lowest low to current bar.

when i run this i get the first setup for tomato and for olive ok, then even if in journal i get "tomato ON" different price lvl, i don't get new tomato line on the chart. same for olive.

the idea of the ea is to use this lines to open trades. so what i will finally want is to have this:

when K%>75

draw line o highest(past 36 bars).

if line ON, draw no more lines, until the line is deleted.

if a trade is open delete the line

if no trade is open and 24 bars past from the bar that determined k%>75 also delete the line

:)

as is my first code that i wrote in my hole life, pls teach me how to look at the problem.

thank you

We start at beginning .....

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

At bar 0 stoch can get somewhere at bar 0 value > 75 and end with lower value

Has it to draw a line in that case ?? or is it just for close price stochastic ends ??

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];

ever used iHighest and/or iLowest ??? See how to do iHighest and 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);
     }
       
}

one time creating is enough .... the loop makes only repeating what is inside { }

so no loop needed for this ....

then before you create

  • check running trades
  • check if object with name starting "tomato" already exist and if it exist then check if you have to delete the old one

create a name moment you make it like

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

checking your objects can with

//----
   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 ")
         {
         //.....
         }
    }

Klick on the links and try to understand what happens

places with ....... inside the code you can try fill in yourself

 
qjol:
can u specify what u r trying to accomplish ?


the final idea:

Signal 1 = when K%>75 and high of bar[1] and current bar[0] smaller then the highest high from the last 36 bar(High_point)

draw tomato line on High_point

if tomato line already drawn, draw no more lines, until the line is deleted.

if a trade is open using tomato line delete the line

if no trade is open and 96 bars past from the bar that determined the High_point delete the line.

now, i get only one line on each Signal 1 (Print function sends 36 "tomato ON" each valid tick i guess), so i have to tell the code to stop the loop after it finds the tomato line. i go cook some spaghetti and think how i should write that... in my head this should be the next step.... hope i'm not missing something :)

am i on the right track ? thanks so much for your help and advice.

the code until now:

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

i posted in the same time with deVries post.

i go read :)

 
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 need a line to do it

 

The case your are talking about cichichan will rarely happen, so you have to use an index so you can see what you do :

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

The arrow_down don't show up, there is a bug some where ....

//+------------------------------------------------------------------+
//|                                                      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);
  }
 
ffoorr its n indicatornot n EA
Reason: