//Created by Aditya Saraf
//THIS IS NOT A SYSTEM AS SUCH, JUST THE RESULT OF SOME TRIAL AND ERROR, AND I HAVE NOT DONE ANY
//SORT OF MANNUAL TESTING TILL Now.
//The system is self made and considers Moving Average and RSI to enter and exit the positions.
//The parameters include three types of Averaging: Simple MA, Exponential MA and Wilders.
//In the system which was tested, we used SMA as Averaging Type over 16-period. Thus, we use
//MA(16) AND RSI(16), to enter AND exit.
//Entries: (We enter only stocks which are the part of S&P CNX Nifty EXCLUDING ADAG COMPANIES -
//RPOWER,RNRL,RELCAP,RCOM,RELINFRA,RELMEDIA)
// We enter when all the following conditions are satisfied:
//1. Close > MA(16)
//2. RSI(16) > 55
//3. Volume is greater than yesterday's volume and whose EMA(Volume,16) > 400000.
// We exit when all the following conditions are satisfied:
//1. Close Crosses below EMA(16)
//2. RSI(16) < 50
//We take the maximum loss of 12%. For this please open the Automatic Analysis Window >> click on Settings >>
//Go to the Stops Tab and Enable Maximum Loss Stop as 12%. Also select "Exit Next Bar at Trade Price"
//Go to the Trades Tab and Select "Average" for both "Buy Price" and "Sell Price".
//Position Sizing: At max, we have 5 open positions at any given time. Initial Equity has been set at 100000.
//We place equal bets on all the trades. Thus, <=20% of Capital available.
//Position Score has been set such that Stocks which have lower RSI(16) is entered in case of multiple entry
//signals.
_SECTION_BEGIN( "Price" );
SetChartOptions( 2, chartShowArrows | chartShowDates | chartWrapTitle | chartLogarithmic );
_N( Title = StrFormat( "{{NAME}} - {{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", colorBlack ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
if ( ParamToggle( "Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip = StrFormat( "Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: " + NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
}
_SECTION_END();
_SECTION_BEGIN( "MA" );
P = ParamField( "Price field", -1 );
Periods = Param( "Periods", 20, 2, 200, 1 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorTan ), ParamStyle( "Style", styleThick ) | styleNoRescale );
_SECTION_END();
_SECTION_BEGIN( "Mid MA" );
P = ParamField( "Price field", -1 );
Periods = Param( "Periods", 50, 2, 300, 1 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorRed ), ParamStyle( "Style", styleThick ) | styleNoRescale );
_SECTION_END();
_SECTION_BEGIN( "Long MA" );
P = ParamField( "Price field", -1 );
Periods = Param( "Periods", 100, 2, 400, 1 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorGreen ), ParamStyle( "Style", styleThick ) | styleNoRescale );
_SECTION_END();
_SECTION_BEGIN( "BBands" );
P = ParamField( "Price field", -1 );
Periods = Param( "Periods", 20, 2, 100, 1 );
Width = Param( "Width", 2, 0, 10, 0.05 );
Color = ParamColor( "Color", colorLightGrey );
Style = ParamStyle( "Style" ) | styleNoRescale;;
Plot( bbt = BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style );
Plot( bbb = BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style );
PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, colorWhite, 0.9 ), styleCloud | styleNoRescale, Null, Null, Null, -1 );
_SECTION_END();
_SECTION_BEGIN( "Volume" );
Plot( Volume, _DEFAULT_NAME(), ParamColor( "Color", colorLavender ), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick | styleNoLabel, maskHistogram ), 2 );
_SECTION_END();
_SECTION_BEGIN( "Aditya" );
SetOption( "InitialEquity", 100000 ); //Initial Capital is set at 100000
SetOption( "AllowPositionShrinking", True );
SetOption( "ActivateStopsImmediately", True );
SetOption( "InterestRate", 3.5 ); //Remaining Cash earns Savings Bank Interest @ 3.5%
SetOption( "MinShares", 1 );
SetOption( "MinPosValue", 5000 );
SetOption( "HoldMinBars", 3 ); //Minimum Holding Period in order to avoid Auction
SetTradeDelays( 1, 1, 1, 1 ); //Both Entry and Exit are performed on the next day of signal
RoundLotSize = 1;
posqty = 5; // to optimize >>>> posqty = Optimize("PosQty", 5, 1, 20, 1 )
SetOption( "MaxOpenPositions", posqty ); //Max. Open Positions at any given time has been set at 5
// desired position size is 100% portfolio equity
// divided by PosQty positions
PositionSize = -100 / posqty; //We take equal bets
Type = ParamList( "Average Type", "SMA,EMA,Wilders" );
P = Optimize( "Averaging Period", Param( "Averaging Period", 16, 3, 100, 1 ), 8, 80, 1 );
if ( Type == "SMA" )
A = MA( C, P );
if ( Type == "EMA" )
A = EMA( C, P );
if ( Type == "Wilders" )
A = Wilders( C, P );
Cond1 = C > A;
Cond2 = RSI( P ) > 55;
Cond3 = Volume > Ref( Volume, -1 ) AND EMA( Volume, P ) > 400000;
Buy = Cond1 AND Cond2 AND Cond3;
Sell = Cross( C, A ) AND RSI( P ) < 50;
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorGreen, 0, L, Offset = -20 );
PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorLime, 0, L, Offset = -30 );
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorWhite, 0, L, Offset = -25 );
PlotShapes( IIf( Sell, shapeSquare, shapeNone ), colorRed, 0, H, Offset = 20 );
PlotShapes( IIf( Sell, shapeSquare, shapeNone ), colorOrange, 0, H, Offset = 30 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorWhite, 0, H, Offset = -25 );
//PlotShapes( shapeUpArrow * Buy + shapeDownArrow * Sell, IIf( Buy, colorGreen, colorRed ) );
// now additional score
// that is used to rank equities
// when there are more ENTRY signals than available
// positions/cash
PositionScore = 100 - RSI( P ); // prefer stocks that have low RSI;
//for exploration
Filter = Buy;
AddColumn( Close, "Close", 1.2 );
_SECTION_END();