Request help in inserting Buy/Sell signal

#1
Hi,

Please could you help me in inserting Buy and Sell signals in the below jim berg volatility ATR STOP SYSTEM formula. The conditions are as below

1)When the price goes up from below the trailing stop, it should give buy call. THE PRICE SHOULD CLOSE ABOVE THE TRAILING STOP. THE BUY SIGNAL SHOULD COME AT THE NEXT CANDLE AFTER THE CANDLE WHICH CROSSES THE TRAILING STOP.
2)When the price goes down from above the trailing stop, it should give sell call.THE PRICE SHOULD CLOSE BELOW THE TRAILING STOP.THE SELL SIGNAL SHOULD COME AT THE NEXT CANDLE AFTER THE CANDLE WHICH CROSSES THE TRAILING STOP.


_SECTION_BEGIN("Long MA 34 week");
P = ParamField("Price field",-1);
Periods = Param("Periods", 170, 2, 200, 1 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_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, colorOrange, colorGrey50 ));
TrailStop = HHV( C - 2 * ATR(10), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);

/* plot price chart and stops */
Plot( TrailStop, "Trailing stop", colorBrown, styleThick | styleLine );
Plot( ProfitTaker, "Profit taker", colorLime, styleThick );
Plot( C, "Price", Color, styleBar | styleThick );
/* plot color ribbon */
Plot( 1, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 50 );

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

function PlotGradientArea( array, caption, ColorTop, ColorBottom )
{
bkclr = GetChartBkColor();

HH = HighestVisibleValue( array );
if( NOT IsNull( hh ) ) SetChartBkGradientFill( ColorTop, ColorBottom, bkclr, Null, HH );
Plot( array, Caption, ColorBlend( ColorBottom, colorBlack ) );
PlotOHLC( HH, HH, array, HH, "", bkclr, styleNoLabel | styleNoTitle | styleCloud, Null, Null, 0, -10 );
}

_SECTION_BEGIN("Price");
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 ) ) ));
PlotGradientArea( C, "Close", ParamColor("Top", colorLightOrange), ParamColor("Bottom", colorPaleGreen ) );

_SECTION_END();

Thanking you in anticipation.

Regards
 

rvlv

Active Member
#2
hi

Here is a starting tip.may not be perfect.
you may get multiple arrows up or down. I have no idea on how to deal with it. Forum experts will help you.
HTML:
my comments
The code has its basis for entry & exit signals in lowest low or highest high of  past 20 bars & volatility from them.
1.The MA170 makes visibility poor on the chart.Price candles become too narrow & tighter.
2.we are better off without the color cloud on the bottom. blind or remove plot ohlc   line.then see
3.This system is basically daily-weekly based trading system and doesnt work well on intraday-so dont try on intraday.
4.The safe entry and exit signals are enter on breakout of first blue colored bar or breakdown of first orange colored bar.
5.Even the trailing stopline is a high power separator between bull & bear zones.it works well by itself.
add these lines to your code
HTML:
Buy = EntrySignal ;
Sell = ExitSignal ;
Buy =ExRem(Buy,Sell);
Sell =ExRem(Sell,Buy);

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );
 
Last edited:

Similar threads