Unwanted commentary in Interpretation window

Hi,
I've written the following code and debugged it with the help of the wonderful users on this forum.
The code is meant for candlestick pattern exploration.
I'm having trouble with the interpretation window.
The printf(writif.....) function seems to be working fine and is displaying the correctly identified candlestick pattern in the last line of the interpretation.
However, the interpretation window is also displaying all the other possible candlestick patterns??!!
I've been going through this forum, the tutorial, the AFL function reference etc and simply cannot figure it out. I think it may have something to do with the AddMultiTextColumn??
Any help or insight would be greatly appreciated.

_SECTION_BEGIN("Definitions");

Green_Candle = C > O ;

Red_Candle = O > C ;

No_Upper_Shadow = (H - Max (O , C)) / Max (O , C) <= 0.001 ;

No_Lower_Shadow = ((Min (O , C) - L) / L ) <= 0.001 ;

Long_Lower_Shadow = (Min(O , C) - L) >= 2*(abs(O - C)) ;

Long_Upper_Shadow = (H - Max(O , C)) >= 2*(abs(O-C)) ;

Uptrend = H > Ref(H,-1) AND L > Ref(L,-1);

Downtrend = H < Ref(H,-1) AND L < Ref(L,-1);

Engulfing = Max(O,C) > Ref(Max(O,C),-1) AND Min(O,C) < Ref(Min(O,C),-1);

Doji = ((abs(O-C))/O) <= 0.001 ; 

Spinning_Top = ((abs(O-C))/O) <= 0.01 ;

_SECTION_END();


_SECTION_BEGIN("Candlestick Patterns");

Bullish_Marubozu = Green_Candle AND No_Upper_Shadow AND No_Lower_Shadow ;

Bearish_Marubozu = Red_Candle AND No_Upper_Shadow AND No_Lower_Shadow ;

Hammer = Downtrend AND No_Upper_Shadow AND Long_Lower_Shadow ;

Hanging_Man = Uptrend AND No_Upper_Shadow AND Long_Lower_Shadow ;

Shooting_Star = Uptrend AND No_Lower_Shadow AND Long_Upper_Shadow ;

Bullish_Engulfing = Ref(Downtrend,-1) AND Ref(Red_Candle,-1) AND Green_Candle AND Engulfing ;

Bearish_Engulfing = Ref(Uptrend,-1) AND Ref(Green_Candle, -1) AND Red_Candle AND Engulfing ;

Piercing = Ref(Downtrend,-1) AND Ref(Red_Candle,-1) AND Green_Candle AND C >= Ref((O-C)/2 , -1) AND C < Ref(O, -1) AND O < Ref(C, -1) ;

Dark_Cloud = Ref(Uptrend,-1) AND Ref(Green_Candle, -1) AND Red_Candle AND C <= Ref((C-O)/2, -1) ;

Bullish_Harami = Ref(Downtrend,-1) AND Ref(Red_Candle, -1) AND Green_Candle AND O > Ref (C, -1) AND C < Ref(O, -1) ;

Bearish_Harami = Ref(Uptrend,-1) AND Ref(Green_Candle, -1) AND Red_Candle AND C > Ref (O, -1) AND O < Ref(C, -1) ;

Morning_Star = Ref(Downtrend,-2) AND Ref(Red_Candle,-2) AND Ref(GapDown(),-1) AND Ref(Spinning_Top,-1) AND GapUp() AND Green_Candle AND 
C > Ref(O,-2) ;

Evening_Star = Ref(Uptrend,-2) AND Ref(Green_Candle,-2) AND Ref(GapUp(),-1) AND Ref(Spinning_Top,-1) AND GapDown() AND Red_Candle AND 
C < Ref(O,-2) ;

Morning_Doji_Star = Ref(Downtrend,-2) AND Ref(Red_Candle,-2) AND Ref(GapDown(),-1) AND Ref(Doji,-1) AND GapUp() AND Green_Candle AND 
C > Ref(O,-2) ;

Evening_Doji_Star = Ref(Uptrend,-2) AND Ref(Green_Candle,-2) AND Ref(GapUp(),-1) AND Ref(Doji,-1) AND GapDown() AND Red_Candle AND 
C < Ref(O,-2) ;

Candlestick = Bullish_Marubozu OR Bearish_Marubozu OR Hammer OR Hanging_Man OR Shooting_Star OR Bullish_Engulfing OR Bearish_Engulfing OR
Piercing OR Dark_Cloud OR Bullish_Harami OR Bearish_Harami OR Morning_Star OR Evening_Star OR Morning_Doji_Star OR Evening_Doji_Star ;

_SECTION_END();


_SECTION_BEGIN("Filters and Columns");

Cond1 = Candlestick == 1 ;
Cond2 = V > EMA (V,20) ;

Filter = Cond1 AND Cond2 ;

TextList = "None\nBullish_Marubozu\nBearish_Marubozu\nHammer\nHanging_Man\nShooting_Star\nBullish_Engulfing\nBearish_Engulfing\nPiercing
             \nDark_Cloud\nBullish_Harami\nBearish_Harami\nMorning_Star\nEvening_Star\nMorning_Doji_Star\nEvening_Doji_Star " ;


TextSelector = 1*Bullish_Marubozu + 2*Bearish_Marubozu + 3*Hammer + 4*Hanging_Man +5*Shooting_Star + 6*Bullish_Engulfing + 7*Bearish_Engulfing + 
				8*Piercing + 9*Dark_Cloud + 10*Bullish_Harami + 11*Bearish_Harami + 12*Morning_Star + 13*Evening_Star + 14*Morning_Doji_Star + 
				15*Evening_Doji_Star ;

AddMultiTextColumn (TextSelector, TextList, "CandleStick") ;

_SECTION_END () ;


_SECTION_BEGIN ("Debugging") ;

//This code has been addedd to check if multiple candlestick patterns are being returned

AddColumn (textselector,"textselector") ;
AddColumn (Bullish_Marubozu,"Bullish_Marubozu") ;
AddColumn (Bearish_Marubozu,"Bearish_Marubozu") ;
AddColumn (Hammer,"Hammer") ;
AddColumn (Hanging_Man,"Hanging_Man") ;
AddColumn (Shooting_Star,"Shooting_Star") ;
AddColumn (Bullish_Engulfing,"Bullish_Engulfing") ;
AddColumn (Bearish_Engulfing,"Bearish_Engulfing") ;
AddColumn (Piercing,"Piercing") ;
AddColumn (Dark_Cloud,"Dark_Cloud") ;
AddColumn (Bullish_Harami,"Bullish_Harami") ;
AddColumn (Bearish_Harami,"Bearish_Harami") ;
AddColumn (Morning_Star,"Morning_Star") ;
AddColumn (Evening_Star,"Evening_Star") ;
AddColumn (Morning_Doji_Star,"Morning_Doji_Star") ;
AddColumn (Evening_Doji_Star,"Evening_Doji_Star") ;

			
_SECTION_END();


_SECTION_BEGIN ("Plotting");

Plot(C,"Price",colorDefault,styleCandle);

SetChartOptions(0,chartShowArrows|chartShowDates);

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

EnableTextOutput(0) ; //added this based on https://forum.amibroker.com/t/unwanted-comments-in-interpretation-window/5178?u=srj_53. To eliminate unwanted content from Interpretation.

PlotShapes(IIf(Cond1, shapeSquare, shapeNone), colorBlue, 0, L) ;

printf(writeif(textselector==1,
"Bullish_Marubozu",
writeif(textselector==2,
"Bearish_Marubozu",
writeif(textselector==3,
"Hammer",
writeif(textselector==4,
"Hanging_Man",
writeif(textselector==5,
"Shooting_Star",
writeif(textselector==6,
"Bullish_Engulfing",
writeif(textselector==7,
"Bearish_Engulfing",
writeif(textselector==8,
"Piercing",
writeif(textselector==9,
"Dark_Cloud",
writeif(textselector==10,
"Bullish_Harami",
writeif(textselector==11,
"Bearish_Harami",
writeif(textselector==12,
"Morning_Star",
writeif(textselector==13,
"Evening_Star",
writeif(textselector==14,
"Morning_Doji_Star",
writeif(textselector==15,
"Evening_Doji_Star","None")))))))))))))))) ;


_SECTION_END();

@srj_53, try this (and review the EnableTextOutput() documentation):

  • 0 - disable output of string literals and assignment in interpretation/commentary
EnableTextOutput(0); 
TextList = "None\nBullish_Marubozu\nBearish_Marubozu\nHammer\nHanging_Man\nShooting_Star\nBullish_Engulfing\nBearish_Engulfing\nPiercing
             \nDark_Cloud\nBullish_Harami\nBearish_Harami\nMorning_Star\nEvening_Star\nMorning_Doji_Star\nEvening_Doji_Star " ;
EnableTextOutput(1); 

As you know from your previous post (it would have been better to continue that thread), the code you wrote doesn't properly handle the case where 2 or more patterns occur at the same time, but at the moment I think this is not critical for your needs.

4 Likes

That did the trick. Thank you :pray:

I did wonder if it would be better to continue the same thread but decided against it since it was a different problem. Will keep your suggestion in mind for the future.

The replies on the earlier post did help me to debug the code and correct it, so I no longer have multiple patterns occuring :slight_smile:

Or you can use _N:

_N( TextList = "This string will not appear in interpretation" );

http://www.amibroker.com/guide/afl/_n.html

2 Likes

Noted. Thank you.
Humbled and grateful for your personal involvement and support on this forum :pray:

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