Can help me fix the candle color please. Thanks

Could you please fix the candle color, I have tried many times. But still not right. Thanks

_SECTION_BEGIN("Color HH n LL");
ColorMG= IIf(C==O,colorDefault,IIf(C>O,colorGreen,colorRed));

//isHigherHigh() => high>high[1] and high[1]>high[2] and close>close[1] and close[1]>close[2] and close>open and close[1]>open[1] and close[2]>open[2] and low>open[1] and low[1]>open[2] and (open+low)<(open+close)

isHH = high>high[1] and high[1]>high[2] and close>close[1] and close[1]>close[2] and close>open and close[1]>open[1] and 
close[2]>open[2] and low>open[1] and low[1]>open[2] and (open+low)<(open+close) ;

//barcolor = (isHH() Blue :na)
//barcolor(isHigherHigh()? blue :na, -1)
//barcolor((isHigherHigh() and close>open)? blue :na, -2)

isLL = low<low[1] and low[1]<low[2] and close<close[1] and close[1]<close[2] and close<open and close[1]<open[1] and 
close[2]<open[2] and high<open[1] and high[1]<open[2] ;

//barcolor(isLowerLow()? yellow :na)
//barcolor(isLowerLow()? yellow :na, -1)
//barcolor((isLowerLow() and close<open)? yellow :na, -2)

isHH1 = Ref (H,-1);
isHH2 = Ref (H,-2);

isLL1 = Ref (L,-1);
isLL2 = Ref (L,-2);

ColorHHnLL = 
IIf(isHH,ColorBlue,
//IIf(isHH1,ColorBlue, 
//IIf(isHH2,ColorBlue,
IIf(isLL,colorYellow,
//IIf(isLL1,colorYellow,
//IIf(isLL2,colorYellow,
colorMG));

Plot(C,"Close",ColorHHnLL,styleCandle );

_SECTION_END();

@Beuty - this might be what you are looking for?

https://www.amibroker.com/guide/afl/setbarfillcolor.html

No idea why the colours are not working, trying to read through your code to see if I can find anything, but what I do find is:

(open+low)<(open+close)

Does not matter much... but I think you do not need that part because of all the rules you have before that part. On any bar that will have a close > open this second rule will also always be true.

As said, does not matter much, just might make it easier to read.

Using SetBarFillColor will not solve your issue. It will still not color as expected.
Why?

Because this one

and this one

are improper AFL array coding.

That's the reason why you do not get proper coloring.
You have simply copied from Pinescript code most probably.
That's why you included subscripting calling elements of array and in addition it is looking ahead in array.

Instead it should be array processing only (without any subscripting).

isHH = Sum(H>Ref(H,-1) AND C>Ref(C,-1) AND L>Ref(O,-1),2) == 2 AND 
		Sum(C>O,3)==3 AND 
		(/*Open+*/ Low)<(/*Open+*/ Close);

isLL = Sum(L<Ref(L,-1) AND C<Ref(C,-1) AND H<Ref(O,-1),2) == 2 AND 
		Sum(C<O,3)==3;

So,

_SECTION_BEGIN("Color HH n LL");
ColorMG= IIf(C==O,colorDefault,IIf(C>O,colorGreen,colorRed));

//isHigherHigh() => high>high[1] and high[1]>high[2] and close>close[1] and close[1]>close[2] and close>open and close[1]>open[1] and close[2]>open[2] and low>open[1] and low[1]>open[2] and (open+low)<(open+close)

//barcolor = (isHH() Blue :na)
//barcolor(isHigherHigh()? blue :na, -1)
//barcolor((isHigherHigh() and close>open)? blue :na, -2)

isHH = Sum(H>Ref(H,-1) AND C>Ref(C,-1) AND L>Ref(O,-1),2) == 2 AND 
		Sum(C>O,3)==3 AND 
		(/*Open+*/ Low)<(/*Open+*/ Close);

isLL = Sum(L<Ref(L,-1) AND C<Ref(C,-1) AND H<Ref(O,-1),2) == 2 AND 
		Sum(C<O,3)==3;

//barcolor(isLowerLow()? yellow :na)
//barcolor(isLowerLow()? yellow :na, -1)
//barcolor((isLowerLow() and close<open)? yellow :na, -2)

isHH1 = Ref (H,-1);
isHH2 = Ref (H,-2);

isLL1 = Ref (L,-1);
isLL2 = Ref (L,-2);

ColorHHnLL = 
IIf(isHH,ColorBlue,
//IIf(isHH1,ColorBlue, 
//IIf(isHH2,ColorBlue,
IIf(isLL,colorYellow,
//IIf(isLL1,colorYellow,
//IIf(isLL2,colorYellow,
colorMG));

SetBarFillColor(ColorHHnLL);

Plot(C,"Close",ColorHHnLL,styleCandle );

_SECTION_END();

36

BTW this one

Low < Close

will output the same as this one

(Open+Low)<(Open+Close)
2 Likes

Thanks Mr Fxhrat for the help. You are very experienced

Still different from the original, can you please fix it Mr Fxhrat. Thanks

Please stop wasting other peoples time!

The AFL code is doing exactly the same as the non AFL code.

E.g one condition for isHH is that current low has to be higher than previous open for two consecutive bars.

That is not the case for the coloring in your last non AB picture!
It is based on different rules.

1 Like

Maybe the problem is here, Sir, so that only 1 candel changes color. No 3 candles that turn yellow or blue . Thanks for Your help

//barcolor(isLowerLow()? yellow :na)
//barcolor(isLowerLow()? yellow :na, -1)
//barcolor((isLowerLow() and close<open)? yellow :na, -2)

I tried this, but it's still not quite right

isHH1 = Ref (isHH,-1);
isHH2 = Ref (isHH,-2);

isLL1 = Ref (isLL,-1);
isLL2 = Ref (isLL,-2);

ColorHHnLL = 
IIf(isHH,ColorBlue,
IIf(isHH1,ColorBlue, 
IIf(isHH2 AND Close > Open,  ColorBlue,
IIf(isLL,colorYellow,
IIf(isLL1,colorYellow,
IIf(isLL2 AND Close < Open ,colorYellow,
colorMG))))));

Can't the code on tv be implemented in Amibroker?. Whereas Amibroker is my Mainstay and Priority Chart. Thanks

@Beuty, for sure AmiBroker can do it but, sometimes, translating code from other platforms may be a bit confusing due to the way each script is implemented.

Caveat: keep in mind that I do not use PineScript... but, as far as I know, its paint logic is based on a forward loop bar by bar, so I think you should change the code you modified in this post, as follows:

// barcolor(isHigherHigh()? black :na)
// barcolor(isHigherHigh()? black :na, -1)
// barcolor((isHigherHigh() and close>open)? black :na, -2)

// barcolor(isLowerLow()? yellow :na)
// barcolor(isLowerLow()? yellow :na, -1)
// barcolor((isLowerLow() and close<open)? yellow :na, -2)

// Look ahead... 
isHH1 = Ref( isHH, 1 );
isHH2 = Ref( isHH, 2 ) AND Close > Open;

isLL1 = Ref( isLL, 1 );
isLL2 = Ref( isLL, 2 ) AND Close < Open;

// Reverse order to process the last original script condition as the one with highest priority
ColorHHnLL =
    IIf( isLL2, colorYellow,
         IIf( isLL1, colorYellow,
              IIf( isLL, colorYellow,
                   IIf( isHH2, colorBlue,
                        IIf( isHH1, colorBlue,
                             IIf( isHH, colorBlue,
                                  colorMG ) ) ) ) ) );

SetBarFillColor( ColorHHnLL );

Just give it a try.

"As far as I know"

You are off the track again.
If you would actually read instead of guessing you would know that it shifts either to left or right depending on set value.

And actually in original non-AFL code parts it was this (and commented... commented code is getting ignored)

So the code he copied (yes, he) it is apparently two different pinescript functions isHH and isHigherHigh. But what's the connection to AFL??

BTW,

there are just two IIf calls required not six.

ColorHHnLL = IIf(isLL2+isLL1+isLL, colorYellow, IIf(isHH2+isHH1+isHH,colorBlue, colorMG));

Once again @Beuty aka @Batupermata please stop wasting other peoples time with crippled information.
Provide detail. If you copy code then please post link to original source!

If you do not do then you get just what you asked based on lagging info in 1st post.

Your first post had asked for plotting with color based on isHH and isLL but not for isHH1 and isHH2 and not for isLL1 and isLL2.

Commented code is getting ignored. It is as simple as that.

There is zero connection between IsHH1 and isHH2 and isHH in first post!

It is really frustrating if you then come up with "still not doing".
Wrong!

According to your first post correction is doing exactly what was asked in post #1... plotting isHH and isLL translated to proper AFL array code making sense. Your isHH and isLL of 1st post are not proper array code in sense of making sense. It is simply copied pinescript (where positive subscript is looking backward).
And again commented lines are getting ignored. It is not guessing game.

As Tomasz often ask describe your goal IN DETAIL. And for translation please post original source link. Is that so hard??

What is the actual entire tv code and with what actual rules???

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.