Karthiks Options Trading Strategy

Hi Prakash,
Thanks for your effort.:) I feel some difference and triggers are not captured and one more thing if CCI is > 200 that should not give trigger. Please go through the first two pages to digest the concept.
_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 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("WMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( WMA( H, 5 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("WMA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( WMA( L, 5 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();


a=WMA(H,5);
b=WMA(L,5);

Buy=Ref(C,-1)>Ref(a,-1) AND Ref(L,-1)>Ref(b,-1) AND C>Ref(H,-1) AND CCI(14)>50 AND CCI(14)<200;
Sell=Ref(H,-1)<Ref(a,-1) AND Ref(C,-1)<Ref(b,-1) AND C<Ref(L,-1) AND CCI(14)<-50 AND CCI(14)>-200;

Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell,Buy);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorGreen, 0,L, Offset=-20);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-20);

for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy Above\n@" + H[i-1], i, L[ i ]-35, colorGreen );
if( Sell ) PlotText( "Sell Below\n@" + L[i-1], i, H[ i ]+35, colorRed );
}


Rectified... Pls check again, Dear Karthick
 

karthik_sri

Well-Known Member
_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 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("WMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( WMA( H, 5 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("WMA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( WMA( L, 5 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();


a=WMA(H,5);
b=WMA(L,5);

Buy=Ref(C,-1)>Ref(a,-1) AND Ref(L,-1)>Ref(b,-1) AND C>Ref(H,-1) AND CCI(14)>50 AND CCI(14)<200;
Sell=Ref(H,-1)<Ref(a,-1) AND Ref(C,-1)<Ref(b,-1) AND C<Ref(L,-1) AND CCI(14)<-50 AND CCI(14)>-200;

Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell,Buy);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorGreen, 0,L, Offset=-20);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-20);

for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy Above\n@" + H[i-1], i, L[ i ]-35, colorGreen );
if( Sell ) PlotText( "Sell Below\n@" + L[i-1], i, H[ i ]+35, colorRed );
}


Rectified... Pls check again, Dear Karthick


Bro still I find some gap...some triggers were missed. CCI error rectified..:)
 
_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 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("WMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( WMA( H, 5 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("WMA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( WMA( L, 5 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();


a=WMA(H,5);
b=WMA(L,5);


PREV_Buy=Ref(C,-2)>Ref(a,-2) AND Ref(L,-2)>Ref(b,-2) AND C>Ref(H,-2) AND CCI(14)>50 AND CCI(14)<200;
PREV_Sell=Ref(H,-2)<Ref(a,-2) AND Ref(C,-2)<Ref(b,-2) AND C<Ref(L,-2) AND CCI(14)<-50 AND CCI(14)>-200;

Buy=Ref(C,-1)>Ref(a,-1) AND Ref(L,-1)>Ref(b,-1) AND C>Ref(H,-1) AND CCI(14)>50 AND CCI(14)<200 AND NOT(PREV_Buy);
Sell=Ref(H,-1)<Ref(a,-1) AND Ref(C,-1)<Ref(b,-1) AND C<Ref(L,-1) AND CCI(14)<-50 AND CCI(14)>-200 AND NOT(PREV_Sell);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorGreen, 0,L, Offset=-20);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-20);

for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy Above\n@" + H[i-1], i, L[ i ]-35, colorGreen );
if( Sell ) PlotText( "Sell Below\n@" + L[i-1], i, H[ i ]+35, colorRed );
}

Dear Karthick,
Can you spare sometime and check the corrected code. In case of error, kindly specify it... so that i shall solve it...
 
Karthik (GURUJI) and all other TJ friends....

AFL implementing this strategy by KARTHIK is attached here
 
Last edited:
Karthik (GURUJI) and all other TJ friends....

AFL implementing this strategy by KARTHIK is attached here

AFL Implements

Rule 1). We look for the 15 or 30 Min candle to close above High of WMA5
Rule 2). CCI Reading > 50
Rule 3). Don't consider the setup when CCI Reading is >=200
Rule 4). 15 or 30 Min candle should not touch High & Low of WMA5

Rule 5). Handle Setup collision (Added by me)
Rule 6). Suppress Trade Collision. Added by me)

Stop Loss Rule. Set at Low of the trigger candle
Exit Rule. Controlled by a parameter tuple. It can be either set as fixed point (10, 20) or a percentage that is to be added to entry price. Percentage tends to be better in lower priced options (< 100) whereas fixed price seems to work better with more expensive options.

USAGE PRECONDITIONS #1
For you to use it, you will have to either create a new market and Move all Option's scrips present in your Ami Broker to the new market or amend the AFL to correctly reflect the market's name of your amibroker in first code line of AFL. This is done to prevent from accidentally running this AFL on a non-option scrip. Until you do this correctly, AFL will show nothing substantial.

USAGE PRECONDITIONS #2
Similarly time frames must be set correctly for AFL to work. it will not work on any other time-frames. DO NOT CHANGE THEM

USAGE PRECONDITIONS #3
You will notice that AFL does not plot CCI chart. But it is computed and used the calculations. Its value is shown on Title. All we really need to do is compare it with 50 or 200, so there is no real need to plot. If you still want to see it, plot it separertely on lower pane. Similarly, if you want to hide WMAs, you can do so by commenting two plot lines.

USAGE PRECONDITIONS #4
Last, but not the least. If you find error in AFL or if you come up with an improvement, you must SHARE it here. There are no exceptions to this. Do not use this AFL if this rule is not agreeable to you.

Features

AFL is correctly indented. Those of you, who are programmers will like this.

Blue Hollow Circle indicates that a setup was created on a candle. Small Red dot indicates that the setup created on prior candle failed to trigger. Sometimes, you will see a Red dot inside a blue Hollow Circle, which means that new setup was created on candle and the same candle also caused the prior setup to fail.

Green up arrow means a trade was triggered and taken. Red Down arrow inside a hollow Red Circle means target was achieved. Red Down arrow inside a hollow square means stop loss was hit. Red Down arrow inside a Star means trade timed out.

Known problems
If Entry and Exit happens within same 15 or 30 minute time frame such that they overlap on same candle, AFL fails to plot exit on the same candle. It usually will show either target being hit on next candle or may even show stop loss getting hit.
If both profit as well as stop loss are hit on same candle, AFL will show both. There is no way to know what was hit first without checking contract notes.

Code:
_SECTION_BEGIN("Karthik Options ");
////////// http://www.traderji.com/technical-analysis/90669-karthiks-options-trading-strategy-36.html#post904681
// AFL for Karthiks Options Trading Strategy. Implemented by mastermind007. Traderji.
// All rights are Reserved by mastermind007. This notice on top must not be removed ever. 
// Disclaimer: Use this code at your risk. 
// It is ONLY meant for a bonafide personal non-commercial use for members of Traderji.
// You are not allowed to copy-paste this code on any other site under any circumstances

	// Move all Option's data in amibroke to a new market using its organizer and then set market's name here
	if (((Interval(0) == 900) OR (Interval(0) == 1800)) AND MarketID(1) == "Options")
	{
		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 ) ) ));

		// Replace this line to color the candles
		Plot( Close, "Prices", colorBlack, styleNoTitle | styleCandle );

		WMAPeriods = Param(" WMA Periods", 5, 2, 300, 1, 10 );
		CCIPeriods = Param(" CCI Periods", 14, 2, 300, 1, 10 );
		profitType = ParamToggle("Profit Target as ", "Fixed Value|Percentage", 0);
		profitValue = Param("Profit Target Parameter", 10, 1, 100, 1, 1);

		wmaHigh = WMA( High, WMAPeriods);
		wmaLow = WMA( Low, WMAPeriods);
		cciClose = CCI(CCIPeriods);

		Plot( wmaHigh, "WMA-H", colorBlue, styleDashed | styleNoLabel);
		Plot( wmaLow, "WMA-L", colorRed, styleDashed | styleNoLabel);
		Plot( cciClose, "CCI", colorBlack, styleOwnScale | styleNoLine | styleNoLabel );

		/////////////////////////////////////////////////////////////////
		//IMPLEMENTED Rule 1). We look for the 15 or 30 Min candle to close above High of WMA5
		//IMPLEMENTED Rule 2). CCI Reading > 50
		//IMPLEMENTED Rule 3). Don't consider the setup when CCI Reading is >=200
		//IMPLEMENTED Rule 4). 15 or 30 Min candle should not touch High & Low of WMA5
		//NOT IMPLEMENTED "As of now have not made that condition but the trigger can become void if Low of 5WMA touch by the subsequent candle Low. Let me analyse and post it here"
		/////////////////////////////////////////////////////////////////

		SetupRules = Close > wmaHigh AND cciClose > 50 AND cciClose < 200 AND L > wmaLow;

		// Normally trigger price and stop loss price set here is valid only for the next candle after the setup.
		// If next candle does not cause a trade to be triggered, setup is discarded
		// Problem occurs when two setups can occur one after another; This parameter toggle controls which setup takes precedence.
		// However do note that If you've set this parameter to "NO" AND more than 3 setups occur consecutively,
		// it will still only look back to one setup prior only.

		if (ParamToggle("Use Most Recent Setups", "Yes|No") == 1)
		{
			//PlotText("aaaaa", SelectedValue(BarIndex()), SelectedValue(Low - 10), colorBlack);
			triggerPriceOrig = IIf(Ref(SetupRules, -1) == 1, Ref(High, -1), IIf(SetupRules == 1, High, Null)); // Previous better than Current
			stopLossPriceOrig = IIf(Ref(SetupRules, -1) == 1, Ref(Low, -1), IIf(SetupRules == 1, Low, Null));  // Previous better than Current
		} else
		{
			triggerPriceOrig = IIf(SetupRules == 1, High, IIf(Ref(SetupRules, -1) == 1, Ref(High, -1), Null));   // Current better than Previous
			stopLossPriceOrig = IIf(SetupRules == 1, Low, IIf(Ref(SetupRules, -1) == 1, Ref(Low, -1), Null));    // Current better than Previous
		}

		targetPriceOrig = IIf(profitType == 0, triggerPriceOrig + profitValue, triggerPriceOrig * (1 + profitValue/ 100));

		// new Setup on current candle causes previous setup to be discarded

		/// ENTRY CONDITIONS
		/////////////////////////////////////////////////////////////////
		// Note that Buy will never trigger on a setup candle if current values are used because
		// trade will enter when high is breached and candle can never close above its own high.
		tradeTriggered = Ref(SetupRules, -1) == 1 AND Close > triggerPriceOrig;
		/////////////////////////////////////////////////////////////////

		// Normally, Trigger Price and Stop loss price set are valid only for the next candle after the setup.
		// When trade occurs, we need to retain them for display purposes.
		// If next candle does not cause a trade, setup is discarded
		triggerPrice = ValueWhen(tradeTriggered, triggerPriceOrig);
		stopLossPrice = ValueWhen(tradeTriggered, stopLossPriceOrig);
		targetPrice = ValueWhen(tradeTriggered, targetPriceOrig);
		/////////////////////////////////////////////////////////////////

		/// EXIT CONDITIONS
		targetAchived = High >= targetPrice;
		stopLossHit = Low <= stopLossPrice;
		timedOut = TimeNum() >= 153000;
		tradeClosed = targetAchived OR stopLossHit OR timedOut ;
		/////////////////////////////////////////////////////////////////

		/////////////////////////////////////////////////////////////////
		/// DISCARD EXCESS SIGNALS
		/////////////////////////////////////////////////////////////////
		Buy  = ExRem(tradeTriggered, tradeClosed);
		Sell = ExRem(tradeClosed, tradeTriggered);
		Short = Cover=Null;
		/////////////////////////////////////////////////////////////////

		/////////////////////////////////////////////////////////////////
		// DISPLAY DEPARTMENT

		//for( i = 0; i < BarCount; i++ )
		//{
			//// USE EITHER THIS
			//if( Buy[i] ) PlotText( "Entry @ " + NumToStr(triggerPrice[i]), i, L[ i ]-dist[i], colorGreen );
			//if( Sell[i] ) PlotText( "Exit @ " + NumToStr(targetPrice[i]), i, H[ i ]+dist[i],colorRed);
			//// OR THIS
			//if( Buy[i] ) PlotText( "Entry @ " + NumToStr(triggerPrice[i]) + NumToStr(targetPrice[i]), i, L[ i ]-dist[i], colorGreen );
		//}

		// Blue Circle indicates setup created
		PlotShapes(IIf(SetupRules, shapeHollowCircle, shapeNone),colorBlue, 0,L, Offset=-10);
		// Red dot indicates that the setup created on prior candle has failed
		// Sometimes, you will see red dot inside a blue candle. 
		// This means that new setup was created on candle that was actually being watched for entry
		PlotShapes(IIf(Ref(SetupRules,-1) AND NOT tradeTriggered, shapeSmallCircle, shapeNone),colorRed, 0,L, Offset=-10);

		PlotShapes(IIf(Buy , shapeUpArrow, shapeNone),colorGreen, 0,L, Offset=-25);

		// Down arrow inside a Circle means target was achieved
		PlotShapes(IIf(targetAchived AND Sell, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-15);
		PlotShapes(IIf(targetAchived AND Sell, shapeHollowCircle, shapeNone),colorRed, 0,H, Offset=10);

		// Down arrow inside a square means stop loss was hit
		PlotShapes(IIf(stopLossHit AND Sell, shapeDownArrow , shapeNone),colorRed, 0,H, Offset=-20);
		PlotShapes(IIf(stopLossHit AND Sell, shapeHollowSquare , shapeNone),colorRed, 0,H, Offset=15);
	} else
	{
		Title = "Sorry, This AFL is meant to work only for 15 or 30 minute time frame in Options Market Only";
	}
_SECTION_END();
 
Last edited:
Karthik,

I have a question. Nifty had a spectacular jump in first 45 minutes today, which went into sideways as we entered the trade. Only thing in our rule that prevented us from earlier entry was CCI < 200 rule. So, What is significance of CCI < 200 rule?

More specifically, In options, on first day, CCI for ITM is likely to be too high @ start if contracts are rolled over and non-existent if each month starts fresh

Chart of 15 min NIFTY CE 6200 26 Dec 2013 Series. Setup candle was 9:45-10:00 AM. Trade triggered in next candle 10-10:15. Target Hit @ 10:30-10:45.
Target is +8 (400 Rs). Pls Ignore minor typo on image.