Download MetaTrader 5

A question about Indicator Lines displaying

To add comments, please log in or register
Saji
162
Saji  

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
157
peter.MT4Web  

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
Moderator
2318
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.

whroeder1
16108
whroeder1  
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
162
Saji  
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
1399
SYED NAUFAL GADDAFI  
Most probably will repaint when the value changes.
To add comments, please log in or register