// Proprietery of Marketcalls Finanical Services Pvt Ltd
// Lintra V3.2 - Intraday Trading Strategy Version 3.2
// Copyright 2021
// Plugin Developed by Rajandran R Founder - Marketcalls
// Website - www.marketcalls.in
//Dynamic Stops and Target
EnableTextOutput(False);
LintraFunc1();
if(Timeframe=="Hourly")
{
tf = inHourly;
}
if(Timeframe=="Daily")
{
tf = inDaily;
}
TimeFrameSet(tf);
LintraFunc2();
TimeFrameRestore();
var3 = TimeFrameExpand(var2,tf)*100/close;
stop = var3*risk;
target = var3*reward;
_SECTION_BEGIN("Layout & Position Size Settings");
GraphXSpace = Param("GraphXSpace", 10, -50, 150);
SetBarsRequired( 600, 0 );
SetChartOptions( 0, chartShowArrows | chartShowDates );
SetPositionSize(1*RoundLotSize,spsShares);
//SetPositionSize(1*RoundLotSize,spsShares);
SetTradeDelays(0,0,0,0);
_SECTION_END();
_SECTION_BEGIN("LinTra V3.2 - Linear Regression Based Intraday Trading System");
Title = "";
Lintra(O,H,L,C,length);
color=IIf(BarsSince(Cross(Lower,Low)) > BarsSince(Cross(C,Upper)), barup,bardown);
BeforeSignalTime = (DayOfWeek() ==1 AND Monday AND TimeNum()>=MarketStartTime AND TimeNum()<MondayStartTime)
OR (DayOfWeek() ==2 AND Tuesday AND TimeNum()>=MarketStartTime AND TimeNum()<TuesdayStartTime)
OR (DayOfWeek() ==3 AND Wednesday AND TimeNum()>=MarketStartTime AND TimeNum()<WednesdayStartTime)
OR (DayOfWeek() ==4 AND Thursday AND TimeNum()>=MarketStartTime AND TimeNum()<ThursdayStartTime)
OR (DayOfWeek() ==5 AND Friday AND TimeNum()>=MarketStartTime AND TimeNum()<FridayStartTime);
EntryTimeCondition = (DayOfWeek() ==1 AND Monday AND TimeNum()>=MondayStartTime AND TimeNum()<=MondayEndTime)
OR (DayOfWeek() ==2 AND Tuesday AND TimeNum()>=TuesdayStartTime AND TimeNum()<=TuesdayEndTime)
OR (DayOfWeek() ==3 AND Wednesday AND TimeNum()>=WednesdayStartTime AND TimeNum()<=WednesdayEndTime)
OR (DayOfWeek() ==4 AND Thursday AND TimeNum()>=ThursdayStartTime AND TimeNum()<=ThursdayEndTime)
OR (DayOfWeek() ==5 AND Friday AND TimeNum()>=FridayStartTime AND TimeNum()<=FridayEndTime);
ExitTimeCondition = (DayOfWeek() ==1 AND Monday AND TimeNum()>=MondaySqoffTime)
OR (DayOfWeek() ==2 AND Tuesday AND TimeNum()>=TuesdaySqoffTime)
OR (DayOfWeek() ==3 AND Wednesday AND TimeNum()>=WednesdaySqoffTime)
OR (DayOfWeek() ==4 AND Thursday AND TimeNum()>=ThursdaySqoffTime)
OR (DayOfWeek() ==5 AND Friday AND TimeNum()>=FridaySqoffTime);
BeforeExitTime = (DayOfWeek() ==1 AND Monday AND TimeNum()<MondaySqoffTime)
OR (DayOfWeek() ==2 AND Tuesday AND TimeNum()<TuesdaySqoffTime)
OR (DayOfWeek() ==3 AND Wednesday AND TimeNum()<WednesdaySqoffTime)
OR (DayOfWeek() ==4 AND Thursday AND TimeNum()<ThursdaySqoffTime)
OR (DayOfWeek() ==5 AND Friday AND TimeNum()<FridaySqoffTime);
iBuy = IIf(BarsSince(Cross(Lower,Low)) > BarsSince(Cross(C,Upper)), 1, 0) AND EntryTimeCondition;
iShort = IIf(BarsSince(Cross(Lower,Low)) > BarsSince(Cross(C,Upper)), 0, 1) AND EntryTimeCondition;
iBuyPos = Flip(iBuy, iShort);
iShortPos = Flip(iShort, iBuy);
iBuy2 = ( Ref(iShortPos, -1) OR BeforeSignalTime) AND iBuyPos;
iShort2 = ( Ref(iBuyPos, -1) OR BeforeSignalTime) AND iShortPos;
iBuy2High = ValueWhen(iBuy2, H);
iShort2Low = ValueWhen(iShort2, L);
Buy = iBuyPos AND H > Max(iBuy2High, H1) AND EntryTimeCondition;
Short = iShortPos AND L < Min(iShort2Low, L1) AND EntryTimeCondition;
iSell = iShortPos AND L < Min(iShort2Low, L1) OR ExitTimeCondition;
iCover = iBuyPos AND H > Max(iBuy2High, H1) OR ExitTimeCondition;
Buy = ExRem(Buy, iSell);
iSell = ExRem(iSell, Buy);
Short = ExRem(Short, iCover);
iCover = ExRem(iCover, Short);
Long = Flip(Buy, iSell);
Shrt = Flip(Short, iCover);
tempLong = Long;
tempShrt = Shrt;
BuyAt = 0;
ShortAt = 0;
if (SelectedValue(Buy) == 1 AND SelectedValue(Long) == 0)
{
BuyAt = Max(iBuy2High, H1) ;
}
else
{
BuyAt = iBuy2High ;
}
if (SelectedValue(Short) == 1 AND SelectedValue(Shrt) == 0)
{
ShortAt = Max(iShort2Low, L1) ;
}
else
{
ShortAt = iShort2Low ;
}
BuyPrice = ValueWhen(Buy,BuyAt);
ShortPrice = ValueWhen(Short,ShortAt);
BuyStop1 = (100-ValueWhen(Buy,stop))/100 * BuyPrice;
BuyTarget1 = (100+ValueWhen(Buy,target))/100 * BuyPrice;
BuyStop = TickSz * round( BuyStop1 / TickSz );
BuyTarget = TickSz * round( BuyTarget1 / TickSz );
//Exit the Longs if there is a touch of lower channel or if buy stop hits then exit or if buy target hits then also an exit
Sell = isell OR Cross(High,BuyTarget) OR Cross(Buystop,Low); //negative touch of the lower channel
//Remove Excessive Signals
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Buycontinue = Flip(Buy,Sell);
Plot(IIf(Buycontinue, BuyStop, Null),"BuyStops", colorRed, styleDashed);
Plot(IIf(Buycontinue, Buytarget, Null),"BuyTarget", colorGreen, styleDashed);
SellPrice = ValueWhen(Sell,IIf(isell AND !ExitTimeCondition, ShortPrice, IIf(isell AND ExitTimeCondition,Close, IIf(sell AND Cross(High,BuyTarget),
BuyTarget, IIf(sell AND Cross(Buystop,Low), Buystop, Close)))));
//Calculating the Short Stops and Short Targets
ShortStop1 = (100+ValueWhen(Short,stop))/100 * ShortPrice;
shorttarget1 = (100-ValueWhen(Short,target))/100 * ShortPrice;
ShortStop = TickSz * round( ShortStop1 / TickSz );
shorttarget = TickSz * round( shorttarget1 / TickSz );
Cover = iCover OR Cross(shortTarget,low) OR Cross(High,Shortstop);
CoverPrice = ValueWhen(Cover,IIf(icover AND !ExitTimeCondition, BuyPrice, IIf(icover AND ExitTimeCondition,Close,
IIf(Cover AND Cross(shorttarget,low),shorttarget, IIf(Cover AND Cross(High,Shortstop),Shortstop,close)))));
IsLong = Flip(Buy,Sell);
IsShort=Flip(Short,Cover);
NewDay = Day() != Ref(Day(),-1);
Buy = Buy AND Sum( Buy OR Short, BarsSince( NewDay ) + 1 ) <= NumberofTrades; //Limiting the number of signals per day
Short = Short AND Sum( Buy OR Short, BarsSince( NewDay ) + 1 ) <= NumberofTrades; //Limiting the number of signals per day
//Remove Excessive Signals
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);
ShortContinue = Flip(Short,Cover);
Plot(IIf(Shortcontinue, ShortStop, Null),"ShortStops", colorBlue, styleDashed);
Plot(IIf(Shortcontinue, Shorttarget, Null),"ShortTarget", colorYellow, styleDashed);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
Plot(C,"",color,64); //#
/* Plot Buy and Sell Signal Arrows */
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);
_SECTION_END();
_SECTION_BEGIN("Dashboard");
if ( showMsgBoard == 1 )
{
iLong=Flip(Buy,Sell);
iShrt=Flip(Short,Cover);
Relax = NOT iLong AND NOT Buy AND NOT iShrt AND NOT Short AND NOT Sell AND NOT Cover;
BarsSinceBuy = BarsSince( Buy );
BarsSinceShort = BarsSince( Short );
LastSignal = IIf( BarsSinceBuy < BarsSinceShort, 1, -1 );
GfxSelectFont( "BOOK ANTIQUA", 12, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
//if ( SelectedValue( LastSignal ) == 1 )
if ( SelectedValue( iLong ) == 1 )
{
GfxSelectSolidBrush( colorDarkGreen );
}
else if ( SelectedValue( iShrt ) == 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 ) ;
Lgfx3(1,y);
y2 = y2-70;
GfxTextOut( ("" + WriteIf(Buy, "Buy @ "+ BuyPrice, "")), 13, y2);
GfxTextOut( ("" + WriteIf(Short, "Short @ "+ ShortPrice,"")), 13, y2);
GfxTextOut( ("" + WriteIf (iLong AND NOT Buy, "Long @ "+(BuyPrice),"")), 13, y2);
GfxTextOut( ("" + WriteIf (ishrt AND NOT Short, "Short @ "+(ShortPrice),"")), 13, y2);
GfxTextOut( ("" + WriteIf (Relax, "No Trade Zone - Wait!","")), 13, y2);
y2 = y2+20;
GfxTextOut( ("" + WriteIf (iLong AND NOT Buy, "Current P/L: "+NumToStr((C-BuyPrice),1.2)+" Points","")), 13, y2);
GfxTextOut( ("" + WriteIf (ishrt 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 AND EntryTimeCondition ;
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", inDaily), "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 ("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);
_SECTION_END();