Jim Berg amend AFL code

I am using the Jim Berg indicator with the following code

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - " +   FullName() +   " - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("Long MA 34 week");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
//SetChartBkColor(ParamColor("Outer panel color ",colorBlack)); // color of outer border
//SetChartBkGradientFill( ParamColor("Inner panel color upper half",colorWhite),ParamColor("Inner panel color lower half",colorWhite)); // color of inner panel

_SECTION_END();

_SECTION_BEGIN("jim berg volatility ATR STOP SYSTEM");
//AMIBROKER, VOLATILITY SYSTEM. Here is a sample AmiBroker chart
//demonstrating the techniques from Jim Berg's article in this issue.

//In "The Truth About Volatility," Jim Berg presents how to use several well-known volatility measures such as average True range (ATR) to calculate entry, trailing stop, AND profit-taking levels. Implementing techniques presented in the article is very simple using the AmiBroker Formula Language (Afl), AND takes just a few lines of code.
//Listing 1 shows the formula that the plots color-coded price chart, trailing stop, AND profit-taking lines, as well as a colored ribbon showing volatility-based entry AND exit signals. The relative strength index (RSI) used by Berg is a built-in indicator in AmiBroker, so no additional code is necessary. See Figure 3 for an example.

//LISTING 1
EntrySignal = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) );
ExitSignal = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) );
Color = IIf( EntrySignal, colorBlue, IIf( ExitSignal, colorRed, colorGrey50 ));
TrailStop = HHV( C - 2 * ATR(10), 15 ); // Denis - checked to stock doctor
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10); // Denis - checked to stock doctor

/* plot price chart and stops */
Plot( TrailStop, "Trailing stop", colorRed, styleThick | styleLine );
Plot( ProfitTaker, "Profit taker", colorGreen, styleThick );
Plot( C, "Price", Color, styleCandle | styleThick );
/* plot color ribbon */
Plot( 1, "", Color, styleArea | styleOwnScale | styleNoLabel, -.1, 50 );
Buy=EntrySignal;
Sell=ExitSignal ;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
PlotShapes(Buy * shapeUpArrow , colorGreen,0,L);
PlotShapes(Sell * shapeDownArrow , colorRed,0,H);



//--Tomasz Janeczko, AmiBroker.com
//http://www.traders.com/Documentation/FEEDbk_docs/Archive/022005/TradersTips/TradersTips.html
_SECTION_END();


I am looking to modify the code at this area

/* plot color ribbon */
Plot( 1, "", Color, styleArea | styleOwnScale | styleNoLabel, -.1, 50 );

What I want to do is to have an intermediate colour on the chart which is a green bar for when the closing price is greater than "Entry Signal" .

EntrySignal = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) );

but less than "Exit Signal"

ExitSignal = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) );

At the moment I am getting a Blue bar if the Entry Signal is met and a Red bar on a subsequent exit signal

This is how my Amibroker chart looks Jim%20Berg%20Amibroker

and this is what I am trying to emulate [i.e. re the green bar]

Jim%20Berg%20with%20alternate%20bar

Advice on how to modify the code

Color = IIf( EntrySignal, colorGreen, IIf( ExitSignal, colorRed, colorGrey50 ));

Hi Lennon,

Thanks for your help. Your code was noit 100% but close enough for me to get to what I needed. This is the code that got me the answer

Plot( 1, "", Color = IIf(EntrySignal AND ExitSignal, colorGreen, IIf (EntrySignal, colorBlue, IIf( ExitSignal, colorRed, colorGrey50 ))), styleArea | styleOwnScale | styleNoLabel, -.1, 50 );

Again thank you very much! It has been some time since I have written or amended codes, you saved me a lot of time!:smiley:

Hi Lennon, I just realised that I used your code differently to how you suggested - so I am not sure whether your solution worked or not as written :grinning: - as I have what I needed I have not gone back and rechecked. Thanks again