Download MetaTrader 5
To add comments, please log in or register
Develop trading robots to order. Make profit with Freelance service!
Saji
153
Saji 2015.02.07 15:17 

Hello,All:

I just finish a trendline indicator. The logic is quite simple:

I make a judgement of the current market trendcondition( up or down ) ;

then if it's UP, the line value is current bar's LOW;

if it's DOWN, the  line value is current bar's HIGH;

AND i want to use different color for it's trendline display, just like the HMA line below:

hma

but what i got is below:

my  

You can see that the trendline is not continous when the trendcondition change!

the code for trendline value is below: 

      if(TrendCondition[shift] == 1)
      {
         HighBuffer[shift] = 0;
         LowBuffer[shift] = Low[shift];
      }
      else if(TrendCondition[shift] == 2)
      {
         HighBuffer[shift] = High[shift];
         LowBuffer[shift] = 0;
      }

And I have check the relevant code of HMA indicator, it use the same logic......

Can anyone help?

 saji 

peter.MT4Web
158
peter.MT4Web 2015.02.07 15:41  

Hi saji!


Your Indicator works as defined.

You want two lines. One with hights and one wits lows. Thats what you got.

You have to specify what shall be done, if the trend changes. And then implement it.


eddie

honest_knave
969
honest_knave 2015.02.07 16:04  

Hello saji,

Whenever you get a change in trend, both HighBuffer and LowBuffer will need the same value. That way you will have a continuous line.

whroeder1
13630
whroeder1 2015.02.07 19:40  
honest_knave: Whenever you get a change in trend, both HighBuffer and LowBuffer will need the same value. That way you will have a continuous line.
     if(TrendCondition[shift] == 1)
      {
         HighBuffer[shift] = 0;
         LowBuffer[shift] = Low[shift];
      }
     if(TrendCondition[shift] == 1)
      {
         HighBuffer[shift] = HighBuffer[shift+1] != 0 ? Low[shift] : 0;
         LowBuffer[shift] = Low[shift];
      }
Saji
153
Saji 2015.02.08 06:00  
honest_knave:

Hello saji,

Whenever you get a change in trend, both HighBuffer and LowBuffer will need the same value. That way you will have a continuous line.

WHRoeder:

thank you, guys

it's exactly what you say! After I change my code, i got the right result:

right 

the code is below:

      //------TrendLine Value Calculation
      if(TrendCondition[shift] == 1)
      {
         if(TrendCondition[shift+1] == 1)    //UpWard
         {
            HighBuffer[shift] = 0;
            LowBuffer[shift] = Low[shift];
         }
         else if(TrendCondition[shift+1] == 2)     //DownWard to UpWard
         {
            HighBuffer[shift] = Low[shift];
            LowBuffer[shift] = Low[shift];
         }
      }
      else if(TrendCondition[shift] == 2)
      {
         if(TrendCondition[shift+1] == 2)    //DownWard
         {
            HighBuffer[shift] = High[shift];
            LowBuffer[shift] = 0;
         }
         else if(TrendCondition[shift+1] == 1)     //UpWard to DownWard
         {
            HighBuffer[shift] = High[shift];
            LowBuffer[shift] = High[shift];
         }
      }      
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2015.02.08 06:26  
Most probably will repaint when the value changes.
/
To add comments, please log in or register