Draw trend line with end - page 2

 
Seng Joo Thio:

This line:

should be:

But in fact this entire line is not necessary.

And instead of:

You could have:

So that your:

could be simplified into:

Thanks so much!!!! Problem solved changing it to p1! 
 
Seng Joo Thio:

This line:

should be:

But in fact this entire line is not necessary.

And instead of:

You could have:

So that your:

could be simplified into:

Well, i put it in a cycle to draw many lines and it didnt work...whats going on with this...same code, i see nothing wrong with the code but seems the ibarshift condition doesnt meets if i draw so many lines but if drawing one line it does meet...

 
Hgu Gh:

Well, i put it in a cycle to draw many lines and it didnt work...whats going on with this...same code, i see nothing wrong with the code but seems the ibarshift condition doesnt meets if i draw so many lines but if drawing one line it does meet...

I suppose you added an outer loop for 'a'?  You'll need to consider these:

(1) Since you're using 'a' to name your lines, then basically all your lines will move and change not only time2, but time1, price1 and price2 as well, as new bars are formed. If you don't want your lines to move, then consider adding time to the name of your lines.

(2) ObjectCreate() - should check if the lines already exist, and call ObjectSetInteger()/ObjectSetDouble() if necessary (i.e. if you don't add time into names).

(3) Loop for 'c' should best be reversed and a break put right after you change time2, for efficiency reason.

Show your latest code if you need more concrete advice.

 
Seng Joo Thio:

I suppose you added an outer loop for 'a'?  You'll need to consider these:

(1) Since you're using 'a' to name your lines, then basically all your lines will move and change not only time2, but time1, price1 and price2 as well, as new bars are formed. If you don't want your lines to move, then consider adding time to the name of your lines.

(2) ObjectCreate() - should check if the lines already exist, and call ObjectSetInteger()/ObjectSetDouble() if necessary (i.e. if you don't add time into names).

(3) Loop for 'c' should best be reversed and a break put right after you change time2, for efficiency reason.

Show your latest code if you need more concrete advice.

I svck xD

string rz= "RZ";

      for(int a= 0;a<Bars;a++)

         {

         string b = IntegerToString(a);

         {

            ObjectCreate(0,rz+b,OBJ_TREND,0,Time[a],Low[a],Time[0],Low[a]);

            ObjectSetInteger(0,rz+b,OBJPROP_SELECTABLE,0);

            ObjectSetInteger(0,rz+b,OBJPROP_RAY_RIGHT,0);

         }   

         }  

      for(int d= 0;d<Bars;d++)

         {        

      string b = IntegerToString(d);

      double p1= ObjectGetDouble(0,rz+b,OBJPROP_PRICE1); 

         if(p1 >= Low[d] && p1 <= High[d] && iBarShift(NULL,0,ObjectGetInteger(0,rz+b,OBJPROP_TIME)) > d ) 

         {   

            ObjectSet(rz+b,OBJPROP_PRICE2,p1);

            ObjectSet(rz+b,OBJPROP_TIME2,Time[d]);

         }

         }
 
Hgu Gh:

I svck xD

Based on your code, move your 'd' loop into 'a' loop (by shifting the last '}' before 'd' loop to after 'd' loop, and remove repeat declaration of 'b'. Then loop your 'd' to <'a'. You'll get:

I must say it is very inefficient. Look at my earlier comments and put in more effort, if you really want to learn.

 
Seng Joo Thio:

Based on your code, move your 'd' loop into 'a' loop (by shifting the last '}' before 'd' loop to after 'd' loop, and remove repeat declaration of 'b'. Then loop your 'd' to <'a'. You'll get:

I must say it is very inefficient. Look at my earlier comments and put in more effort, if you really want to learn.

Can you please post the code from that image? i did what you say but didnt get the same results it freezes...im trying guess im silly xD

 
Hgu Gh:

Can you please post the code from that image? i did what you say but didnt get the same results it freezes...im trying guess im silly xD

Should be this one:

string rz= "RZ";
      for(int a= 0;a<500;a++)
         {
         string b = IntegerToString(a);
         {
            ObjectCreate(0,rz+b,OBJ_TREND,0,Time[a],Low[a],Time[0],Low[a]);
            ObjectSetInteger(0,rz+b,OBJPROP_SELECTABLE,0);
            ObjectSetInteger(0,rz+b,OBJPROP_RAY_RIGHT,0);
         }   
      for(int d= 0;d<a;d++)
         {        
      //string b = IntegerToString(d);
      double p1= ObjectGetDouble(0,rz+b,OBJPROP_PRICE1); 
         if(p1 >= Low[d] && p1 <= High[d] && iBarShift(NULL,0,ObjectGetInteger(0,rz+b,OBJPROP_TIME)) > d ) 
         {   
            ObjectSet(rz+b,OBJPROP_PRICE2,p1);
            ObjectSet(rz+b,OBJPROP_TIME2,Time[d]);
         }
         }
         }  
 
Seng Joo Thio:

Should be this one:

ty, i see if the amount of bars for the first cycle is changed then it works but if i use all bars it wont work, why do it works using an x amount of bars but it wont work if i use Bars or all bars?

 
Hgu Gh:

ty, i see if the amount of bars for the first cycle is changed then it works but if i use all bars it wont work, why do it works using an x amount of bars but it wont work if i use Bars or all bars?

Will work, just takes veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrry long for slower pcs (after all your code is inefficient)... and it'll completely fill up your chart window with lines.

 
Hgu Gh:

I svck xD

Could you please write correct English...

What that means ?