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
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