drawing H_line on highest high of last 36 highs - page 2

 

i dont care about stoch close so just current K% is enough.

code for check objects:

 int i, ot=ObjectsTotal()-1;
string id=ObjectName (i);

for (i=ot;i>=0;i--)
{
   if (StringSubstr(id,0,7)=="tomato ")
      {
      if (StringSubstr(id,7,16)<TimeToStr(Time[96],TIME_DATE|TIME_MINUTES))
         {
         ObjectDelete(id);
         }
      if (StringSubstr(id,7,16)>TimeToStr(Time[96],TIME_DATE|TIME_MINUTES))
      }
   if (StringSubstr(id,0,6)=="olive ")
      {
      if (StringSubstr(id,6,16)<TimeToStr(Time[96],TIME_DATE|TIME_MINUTES))
         {
         ObjectDelete(id);
         }
      }  
}

this deletes the id line after 96 candles. as i need

what i have to do now is to stop ea from drawing new tomato lines if one tomato line is already on chart.

i'm thinking adding

if (StringSubstr(id,7,16)>TimeToStr(Time[96],TIME_DATE|TIME_MINUTES))
         {
         ..............
         }

......... = stop and from the beginning (but still read the olive conditions)

code now:

int start()
  {
/////////// K% over >75 or under <25 (no waiting for close)
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];
string Hdate = TimeToStr(H,TIME_DATE|TIME_MINUTES);
datetime L=Time[low_nr];
string Ldate = TimeToStr(L,TIME_DATE|TIME_MINUTES);


/////////////////////////////////////////////////////////////////////////////////
//---
 int i, ot=ObjectsTotal()-1;
string id=ObjectName (i);

for (i=ot;i>=0;i--)
{
   if (StringSubstr(id,0,7)=="tomato ")
      {
      if (StringSubstr(id,7,16)<TimeToStr(Time[96],TIME_DATE|TIME_MINUTES))
         {
         ObjectDelete(id);
         }
      if (StringSubstr(id,7,16)>TimeToStr(Time[96],TIME_DATE|TIME_MINUTES))
      }
   if (StringSubstr(id,0,6)=="olive ")
      {
      if (StringSubstr(id,6,16)<TimeToStr(Time[96],TIME_DATE|TIME_MINUTES))
         {
         ObjectDelete(id);
         }
      }  
}
//---


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

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

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

if(Bid>low_price && Low[0]>low_price && Low[1]>low_price && stoch<25)
   {
   ObjectCreate("olive "+Ldate,OBJ_TREND,0,L,low_price,Time[0],low_price);
   ObjectSet("olive "+Ldate,OBJPROP_COLOR,Olive);
   //Print ("olive ON"+low_price);
   }
 
   
   
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

to rephrase:

i want on the chart to have maximum one tomato line.

if that line will be used for OrderSend, delete the line.

if it expires (96), delete the line.

same for olive.

so if tomato line already on chart, no more tomato lines until no tomato on chart

hoped rephrasing will help find the solution :)

 
cichichan:

to rephrase:

i want on the chart to have maximum one tomato line.

if that line will be used for OrderSend, delete the line.

if it expires (96), delete the line.

same for olive.

so if tomato line already on chart, no more tomato lines until no tomato on chart

hoped rephrasing will help find the solution :)


datetime L=Time[low_nr];
string Ldate = TimeToStr(L,TIME_DATE|TIME_MINUTES);

is that the time you create your line ??? how to do that ??

 int i, ot=ObjectsTotal()-1;
string id=ObjectName (i);

for (i=ot;i>=0;i--)
{
   if (StringSubstr(id,0,7)=="tomato ")
      {
       //  line found
      }
}

So how can you avoid drawing other lines....??

 

i was thinking in changing back the name of the object as initial to stop the script from drawing lines due to the same name limitation... but i no function for changing name.

hmm.... i dont get it.

my mind is stuck ! i feel stupid and frustrated

 
cichichan:

i was thinking in changing back the name of the object as initial to stop the script from drawing lines due to the same name limitation... but i no function for changing name.

hmm.... i dont get it.

my mind is stuck ! i feel stupid and frustrated

when do you create a new line ??

not at the time of the bar you find highest or lowest

and you have to create only if there is no line

so if you create a new line use time of Time[0]

if you find your object then what name has it ?? ==> string id=ObjectName (i);

so what do you need to do ?? get this name when its have StringSubstr(id,0,7)=="tomato "

 

Come back to your first post :

"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."

You don't get a new line because the old one already exist. Delete it and a new one will be drawed.

 

for the moment i did it like this :

and it looks that works like it should, just one line, and after 96 bars delete, the redraw when condition reappear.

int start()
  {
/////////// K% over >75 or under <25 (no waiting for close)
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];
string Hdate = TimeToStr(H,TIME_DATE|TIME_MINUTES);
datetime L=Time[low_nr];
string Ldate = TimeToStr(L,TIME_DATE|TIME_MINUTES);


/////////////////////////////////////////////////////////////////////////////////
//---
int i, ot=ObjectsTotal()-1;
string id=ObjectName (i);

for (i=ot;i>=0;i--)
{
   if (StringSubstr(id,0,7)=="tomato ")
      {
      if (StringSubstr(id,7,16)<TimeToStr(Time[96],TIME_DATE|TIME_MINUTES))
         {
         ObjectDelete(id);
         }
      if (StringSubstr(id,7,16)>TimeToStr(Time[96],TIME_DATE|TIME_MINUTES))
         {
         Print ("tomato valid");
         break;
         }
      }
}

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


////////////////////////////////////////////////////////////////////////////////
for (i=ot;i>=0;i--)
{
 if (StringSubstr(id,0,6)=="olive ")
      {
      if (StringSubstr(id,6,16)<TimeToStr(Time[96],TIME_DATE|TIME_MINUTES))
         {
         ObjectDelete(id);
         }
      if (StringSubstr(id,6,16)>TimeToStr(Time[96],TIME_DATE|TIME_MINUTES))
         {
         Print ("olive valid");
         break;
         }   
      }  
 }      

///////////////////////////////////////////////////////////////////////////////
if (ot==-1)
{
if(Bid>low_price && Low[0]>low_price && Low[1]>low_price && stoch<25)
   {
   ObjectCreate("olive "+Ldate,OBJ_TREND,0,L,low_price,Time[0],low_price);
   ObjectSet("olive "+Ldate,OBJPROP_COLOR,Olive);
   //Print ("olive ON"+low_price);
   }
}
   
   
//----
   
//----
   return(0);
  }
 

does this work ?

if (StringSubstr(id,7,16)<TimeToStr(Time[96],TIME_DATE|TIME_MINUTES))

could strings be < or > to one another, that is a question, i don't know.

You are making it complicated, because giol tell you that if you want several line, you have to give the lines different name. And he was right at that time.

If he knew you want only one line, he won't have say that. The solution devries has given is very good in case one has several lines, thank's devries

But If you want only one line call it "tomato" or "olive", then does ObjectFind("tomato") ObjectDelete ("tomato"), solve the problems of time apart with Time[96] and Time[0] stored when the line is drawed.

The next problèm that will happen is that the condition stoch> 75 could last 20 Bars or 50 Bars, then, when you will delete your line, the condition to draw the line will still be valid and as soon as the line will have been deleted, or an order taken, a new line will be drawed. good luck, it's not so difficult.

 

hi

as the object thing seemed to complicated for my two weeks of reading code i decided to set Level price for sell and buy. in this process i encounter a problem:

void LevelSset()
{

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


high_bar=iHighest(NULL,0,MODE_HIGH,34,2);
string H=TimeToStr(Time[high_bar],TIME_DATE|TIME_MINUTES);
LSell=High[iHighest(NULL,0,MODE_HIGH,34,2)];


if(Bid<LSell && High[0]<LSell && High[1]<LSell && stoch>75 && LevelSset==false)
         {
         ObjectCreate("tomato "+H,OBJ_ARROW,0,Time[high_bar],LSell+Point*20);
         ObjectSet("tomato "+H,OBJPROP_ARROWCODE,242);
         ObjectSet("tomato "+H,OBJPROP_COLOR,Tomato);
         LevelSset=true;
         Print("LevelSset on "+LSell);
         }
if (Close[2]>LSell && Close[1]>LSell && LevelSset==true)
   {
      LSell=0;
      LevelSset=false;
      Print ("LSell"+LSell+"expired due to close");
   }
}

the "if (Close[2]>LSell && Close[1]>LSell && LevelSset==true) doesnt work.

if i remove the if (Close[2]>LSell && Close[1]>LSell) and leave (LevelSset==true), or if i change (Close[2]<LSell && Close[1]<1) the function seems to works properly.

thank you

 

some ideas, what is wrong... anyone ?

thank you

Reason: