Buy and sell signals needed

#1
Hi experts
on this forum i think a lot of experts are ready to help newcomers. I would like to thank all of them in advance. In the past also i have received solution to may problems and hope that this time also i will get solutions.

I have a very popular afl which i have downloaded from a website. I want to get buy and sell signals as per following conditions.
when red candle appears i should get down signal and when blue signal appears i should get up signals.

This is the afl code :

_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") );
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 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);

/* plot price chart and stops */
Plot( TrailStop, "Trailing stop", colorWhite, styleThick | styleLine );
Plot( ProfitTaker, "Profit taker", colorWhite, styleThick );
Plot( C, "Price", Color, styleCandle | 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();
 

johnnypareek

Well-Known Member
#2
At your service sir :)

HTML:
_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") );
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 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);

/* plot price chart and stops */
Plot( TrailStop, "Trailing stop", colorWhite, styleThick | styleLine );
Plot( ProfitTaker, "Profit taker", colorWhite, styleThick );
Plot( C, "Price", Color, styleCandle | styleThick );
/* plot color ribbon */
Plot( 1, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.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();
 
#4
Would greatly appreciate it if somebody could add in columns so this works as a scan in addition to an indicator. Looking for help please as not able to write code yet. Thanks!!
 
#6
one query
actually i bought 1 nifty call strike:5600 at 54

and today nifty call is trading at 137 and it is still out-of-the-money... can i squaroff my position and book my profit?
 

DSM

Well-Known Member
#7
Yes, you can. Next time around you should atleast do some homework before you trade....

one query
actually i bought 1 nifty call strike:5600 at 54

and today nifty call is trading at 137 and it is still out-of-the-money... can i squaroff my position and book my profit?