Statistics | Charts | Trades | Formula | Settings | Symbols | Monte Carlo

Formula
// Proprietery of Marketcalls Finanical Services Pvt Ltd 
// K Lintra - Positional Trading Strategy Version 5 
// Copyright 2019 
// TradeStudio Plugin Developed by Rajandran R Founder - Marketcalls 
// Website - www.marketcalls.in 
 
 
 
 
 
_SECTION_BEGIN("K-LinTra v5"); 
 
 
GraphXSpace = Param("GraphXSpace", 10, -50, 150); 
SetBarsRequired( -2, -2 );  
SetChartoptions( 0, chartShowArrows | chartShowDates ); 
 
// KAMA  
 
OptimizerSetEngine("spso"); 
OptimizerSetOption("Runs", 3 ); 
OptimizerSetOption("MaxEval", 5000 ); 
 
Periods = Optimize("Periods", 3, 2, 20 ,1);  
Pds = Periods + 1;  
FastSC = 2 / ( 2 + 1 );  
SlowSC = 2 / ( 30 + 1 );  
 
Direction = Abs( Close - Ref( Close, -periods ) );  
Volatility = Sum( Abs( Close - Ref( Close, -1 ) ), periods );  
ER = Direction / Volatility;  
SSC = ER * ( FastSC - SlowSC ) + SlowSC;  
Constant = SSC * SSC;  
 
KAMA = AMA( Close, Constant );  
 
 
//Position Size 
//SetPositionSize(1000,spsShares); 
SetPositionSize(1*RoundLotSize,spsShares); 
//SetPositionSize(200000,spsValue); 
//SetPositionSize(15,spsPercentOfEquity); 
 
 
 
SetTradeDelays(0,0,0,0); 
 
Title = ""; 
 
marketstarttime = 091500; 
Bars_so_far_today = 1 + BarsSince( Day() != Ref(Day(), -1)); 
StartBar = ValueWhen(TimeNum() == marketstarttime , BarIndex()); 
TodayVolume = iif(Sum(V,Bars_so_far_today)<=0,1,Sum(V,Bars_so_far_today)); 
average = (H+L+C)/3; 
IIf (BarIndex() >= StartBar, VWAP = Sum (average * V, Bars_so_far_today  ) / TodayVolume,0); 
 
 
newday = Ref(Day(),-1) != Day(); 
 
yVWAP = ValueWhen(newday, Ref(VWAP,-1) ,1); 
 
 
 
klinput(); 
 
 
 
 
 
 
tf = inHourly; 
 
 
 
periods = Optimize( "ATR Periods", 80, 70, 85, 5 ); 
len1 = Optimize("Len1",125,100,150,25); 
len2 = Optimize("Len2",150,100,150,25); 
len3 = Optimize("Len3",150,50,150,25); 
len4 = Optimize("Len4",150,50,150,25); 
 
 
 
 
//creates a state stream of 1 and -1 from Daily Timeframe 
TimeFrameSet(tf); 
PRBATR=PercentRank(LinearReg(ATR(periods),periods),periods); 
state = IIf(PRBATR > Ref(PRBATR,-1) OR PRBATR == 100,1,-1); 
TimeFrameRestore(); 
 
istate = TimeFrameExpand(state,tf); 
iPRBATR = TimeFrameExpand(PRBATR,tf); 
 
newmonth = month() != Ref(month(),-1); 
 
 
 
len = IIf(istate == -1 AND iPRBATR == 0 , len1, IIf(istate == -1 AND iPRBATR != 0,len2, IIf(istate == 1 AND iPRBATR == 100 , len3 , len4))); 
 
lvwap = LinearReg(KAMA,len); 
 
vwapLintra(O,H,L,C,lvwap); 
 
 
 
  
 
 
 
	upper = Ref(upper,-1); 
	lower = Ref(lower,-1); 
 
	color=IIf(BarsSince(Cross(Lower,Low)) > BarsSince(Cross(C,Upper)), barup,bardown);  
	iBuy = IIf(BarsSince(Cross(Lower,Low)) > BarsSince(Cross(C,Upper)), 1, 0); 
	iShort = IIf(BarsSince(Cross(Lower,Low)) > BarsSince(Cross(C,Upper)), 0, 1); 
	iBuyPos = Flip(iBuy, iShort); 
	iShortPos = Flip(iShort, iBuy); 
	iBuy2 = Ref(iShortPos, -1) AND iBuyPos; 
	iShort2 = Ref(iBuyPos, -1) AND iShortPos; 
	iBuy2High = IIf(newday,Max(Open,ValueWhen(iBuy2, H)),ValueWhen(iBuy2, H)); 
	iShort2Low = IIf(newday,Min(Open,ValueWhen(iShort2, L)),ValueWhen(iShort2, L)); 
 
	Buy = iBuyPos AND H > iBuy2High ; 
	Short = iShortPos AND L < iShort2Low ; 
	 
	Sell = Short; 
	Cover = Buy; 
 
	Buy = ExRem(Buy, Sell); 
	Sell = ExRem(Sell, Buy); 
	Short = ExRem(Short, Cover); 
	Cover = ExRem(Cover, Short); 
	 
	BuyPrice = ValueWhen(Buy, iBuy2High); 
	ShortPrice = ValueWhen(Short, iShort2Low); 
 
	 
 
	SellPrice = ShortPrice ; 
	CoverPrice = BuyPrice ; 
 
 
	Buy = ExRem(Buy, Sell); 
	Sell = ExRem(Sell, Buy); 
	Short = ExRem(Short, Cover); 
	Cover = ExRem(Cover, Short); 
 
 
 
 
 
 
//BuyPrice = ValueWhen(Buy, Close); 
//ShortPrice = ValueWhen(Short, Close); 
 
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40); 
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                       
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);  
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40); 
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                       
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45); 
 
PlotShapes(Sell * shapestar, colorBrightGreen, 0, High, 12); 
PlotShapes(Cover * shapestar, colorRed, 0, Low, -12); 
 
Plot(C,"",color,64); //# 
  
  
  
//WriteIf(s,"EXIT all Short positions\nif trading long positions, enter long Now-\nOR at the market price on tomorrow's Open with stop="+EncodeColor(4)+WriteVal(L+.75*ATR(5),1.4)+" ,",""); 
//WriteIf(ss,"exit all long positions today with a Market On Close (MOC) order\nOR at the market price on tomorrow's Open with stop="+EncodeColor(4)+WriteVal(Ref(H+.75*ATR(5), -1),1.4)+",",""); 
//WriteIf( sss ,"No trading signals today.","") ; 
  
  
 _SECTION_END(); 
 
_SECTION_BEGIN("Dashboard"); 
 
if ( showMsgBoard == 1 ) 
{ 
Long=Flip(Buy,Sell);  
Shrt=Flip(Short,Cover);  
Relax = NOT Long AND NOT Buy AND NOT shrt AND NOT Short AND NOT Sell AND NOT Cover; 
BarsSinciBuy = BarsSince( Buy );  
BarsSinciShort = BarsSince( Short );  
LastSignal = IIf( BarsSinciBuy < BarsSinciShort, 1, -1 );  
 
GfxSelectFont( "BOOK ANTIQUA", 12, 100 ); 
GfxSetBkMode( 1 );  
GfxSetTextColor( colorWhite );  
 
//if ( SelectedValue( LastSignal ) == 1 ) 
if ( SelectedValue( Long ) == 1 )  
{  
	GfxSelectSolidBrush( colorDarkGreen );  
}  
else if ( SelectedValue( Shrt ) == 1 ) 
{  
	GfxSelectSolidBrush( colorDarkRed );  
}  
else 
{  
	GfxSelectSolidBrush( colorDarkGrey );  
}  
 
pxHeight = Status( "pxchartheight" ) ;  
xx = Status( "pxchartwidth");  
Left = 1100;  
width = 310;  
x = 5;  
x2 = 265;  
y = pxHeight;  
y2 = y; 
 
GfxSelectPen( colorWhite, 1); // border color  
GfxRoundRect( x, y - 98, x2, y , 7, 7 ) ;  
 
SysType = 1; 
Lkgfx5(SysType,y); 
 
 
 
y2 = y2-70; 
GfxTextOut( ("" + WriteIf(Buy, "Buy @ "+ BuyPrice, "")), 13, y2);  
GfxTextOut( ("" + WriteIf(Short, "Short @ "+ ShortPrice,"")), 13, y2);  
GfxTextOut( ("" + WriteIf (Long AND NOT Buy, "Long @ "+(BuyPrice),"")), 13, y2);  
GfxTextOut( ("" + WriteIf (shrt AND NOT Short, "Short @ "+(ShortPrice),"")), 13, y2);  
GfxTextOut( ("" + WriteIf (Relax, "No Trade Zone - Wait!","")), 13, y2);  
 
 
 
GfxTextOut( ("" + WriteIf ( iBuyPos AND NOT LONG AND NOT Sell , "Get Ready to Buy Above - " + iBuy2High,"")), 13, y2+45); 
GfxTextOut( ("" + WriteIf ( iShortPos AND NOT Shrt AND NOT Cover , "Get Ready to Short Below - " + iShort2Low,"")), 13, y2+45); 
 
 
y2 = y2+20; 
GfxTextOut( ("" + WriteIf (Long AND NOT Buy, "Current P/L: "+NumToStr((C-BuyPrice),1.2)+" Points","")), 13, y2);  
GfxTextOut( ("" + WriteIf (shrt AND NOT Short, "Current P/L: "+NumToStr((ShortPrice-C),1.2)+" Points","")), 13, y2);  
 
y2 = y2-20; 
GfxTextOut( ("" + WriteIf (Sell AND NOT Short, "Exit Long @ "+ SellPrice ,"")), 13, y2); 
GfxTextOut( ("" + WriteIf (Cover AND NOT Buy, "Exit Short @ "+ CoverPrice,"")), 13, y2); 
 
y2 = y2+20; 
GfxTextOut( ("" + WriteIf (Sell AND NOT Short, "P/L : "+NumToStr((SellPrice-BuyPrice),1.2)+" Points","")), 13, y2);  
GfxTextOut( ("" + WriteIf (Cover AND NOT Buy, "P/L : "+NumToStr((ShortPrice-CoverPrice),1.2)+" Points","")), 13, y2);  
} 
_SECTION_END(); 
   
_SECTION_BEGIN("Exploration"); 
 
Filter = Buy OR Short OR iBuy2 OR iShort2 ; 
 
eBs = WriteIf(iBuy2, "Get Ready to Buy", ""); 
eSs = WriteIf(iShort2, "Get Ready to Short", ""); 
Bs = WriteIf(Buy, "Buy Above", ""); 
Ss = WriteIf(Short, "Short Below", ""); 
 
finalText = Bs + " " + Ss + " " + eBs + " " + eSs; 
 
AddColumn(IIf(iBuy2, H, Null), "Get Ready to Buy", 1.2, colorWhite, colorGreen, 115); 
AddColumn(IIf(Buy, BuyPrice, Null), "Buy Above", 1.2, colorWhite, colorGreen, 115); 
AddColumn(IIf(iShort2, L, Null), "Get Ready to Short", 1.2, colorWhite, colorDarkRed, 115); 
AddColumn(IIf(Short, ShortPrice, Null), "Short Below", 1.2, colorWhite, colorDarkRed, 115); 
AddColumn(High, "High", 1.2, colorDefault, colorDefault, 75); 
AddColumn(Low, "Low", 1.2, colorDefault, colorDefault, 75); 
AddColumn(TimeFrameGetPrice("High", inDaily), "D'High", 1.2, colorDefault, colorDefault, 75); 
AddColumn(TimeFrameGetPrice("Low", inHourly), "D'Low", 1.2, colorDefault, colorDefault, 75); 
AddColumn(Close, "CMP", 1.2, colorDefault, colorDefault, 75); 
 
 _SECTION_END(); 
 
  
  
 
 
 
_SECTION_BEGIN("Dashboard"); 
 
X0 = 10; 
Y0 = 20; 
 
procedure DrawData (Text, x1, y1, x2, y2, colorFrom, colorTo) 
{ 
	GfxSetOverlayMode(0); 
	GfxSelectFont("Verdana", 8.5, 700); 
	GfxSetBkMode(1); 
	GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo); 
	GfxDrawText(Text, x1, y1, x2, y2, 32|1|4|16); 
} 
 
 
DrawData (Name(), X0, Y0, X0+150, Y0+20, colorGrey40, colorblack); 
//DrawData (Date(), X0+155, Y0, X0+320, Y0+20, colorGrey40, colorblack); 
DrawData ("Open : " + Open, X0+155, Y0, X0+320, Y0+20, colorGrey40, colorblack); 
DrawData ("Close : " + Close, X0+325, Y0, X0+450, Y0+20, colorGrey40, colorblack); 
DrawData ("High : " + High, X0+455, Y0, X0+580, Y0+20, colorGrey40, colorblack); 
DrawData ("Low : " + Low, X0+585, Y0, X0+710, Y0+20, colorGrey40, colorblack); 
//DrawData ("Timeframe : " + "5-Minute" , X0+845, Y0, X0+1050, Y0+20, colorGrey40, colorblack); 
//DrawData ("Smooth Osc : " + RSI(14), X0+1055, Y0, X0+1225, Y0+20, colorGrey40, colorblack); 
 
 
_SECTION_END(); 
 
 
_SECTION_END();