Supertrend
Supertrend
Supertrend
/* Author of www.marketcalls.in */
/* Date : 05th Apr 2016 */
function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));
GfxSetBkMode(0);
GfxSetOverlayMode(1);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color",
colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
Plot(C,"\nPrice",IIf(C>O,ParamColor("Wick UP Color",
colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color",
colorDarkRed),colorLightGrey)),styleCandle | styleNoTitle);
// Initial Values overrides your backtesting settings
SetOption("AccountMargin",100);
SetOption("RefreshWhenCompleted",True);
SetTradeDelays(0,0,0,0);
SetPositionSize(300,spsshares);
shrink = 2^(-HalfLife);
shrink2 = 1 - shrink;
topChan[0] = High[0];
botChan[0] = Low[0];
HH = HHV(High, ChanLen);
LL = LLV(Low, Chanlen);
Up=topChan;
Dn=botChan;
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;
TrendUp[i] = Null;
TrendDown[i] = Null;
trend[i]=1;
if (Close[i]>Up[i-1]) {
trend[i]=1;
else if (Close[i]<Dn[i-1]) {
trend[i]=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
else if (trend[i-1]==1) {
trend[i]=1;
changeOfTrend = 0;
else if (trend[i-1]==-1) {
trend[i]=-1;
changeOfTrend = 0;
flag=1;
else {
flag=0;
flagh=1;
}
else {
flagh=0;
Dn[i]=Dn[i-1];
{ Up[i]=Up[i-1];
if (flag==1)
{ Up[i]=topchan[i];;
if (flagh==1)
{ Dn[i]=botChan[i];;
if (trend[i]==1) {
TrendUp[i]=Dn[i];
if (changeOfTrend == 1) {
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
else if (trend[i]==-1) {
TrendDown[i]=Up[i];
if (changeOfTrend == 1) {
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
Plot(TrendUp,"Trend",colorGreen,stylenotitle);
Plot(TrendDown,"Down",colorRed,stylenotitle);
Buy = trend==1;
Sell=trend==-1;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=Sell;
Cover=Buy;
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
EncodeColor(colorLime)+
duration = 10000000;
LastClose= Ref(C,-1); // if you like to add this popup will show you
if (Buy[BarCount-2]==true)
{
PopupWindowEx( "ID:1", "Get Ready to BUY \n"+Name() + " "+ Interval(2)+" : "+ "
Last ="+LastClose , "Buy Alert -", 1000, 100, 1 ) ;
}
if (short[BarCount-2]==true)
{
PopupWindowEx( "ID:2", "Get Ready to SHORT \n"+Name() + " "+ Interval(2) + " :
"+ " Last ="+LastClose , "Short Alert ", 1000, 1, 150 ) ;
}
TrendSL=IIf(trend==1,TrendUp,TrendDown);
for(i=BarCount-1;i>1;i--)
if(Buy[i] == 1)
entry = C[i];
sig = "BUY";
sl = TrendSL[i];
bars = i;
i = 0;
if(Sell[i] == 1)
sig = "SELL";
entry = C[i];
sl = TrendSL[i];
bars = i;
i = 0;
Offset = 20;
sl = ssl[BarCount-1];
/*
PlotText(""+sig+"@"+entry, BarCount-5,entry,Null,colorBlue);
PlotText("T1@"+tar1,BarCount-5,tar1,Null,Clr);PlotText("T2@"+tar2,BarCount-
5,tar2,Null,Clr);PlotText ("T3@"+tar3,BarCount-5,tar3,Null,Clr);
}*/
if (messageboard == 1 )
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
if ( sig =="BUY")
else
Left = 1100;
width = 310;
x = 5;
x2 = 290;
y = pxHeight;
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 +
" mins ago"), 13, y-80) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13,
y-60);
eq = Equity( 1, 0 );
//////////////////////////////////////////////////
// Calculate the Last Five Trades Profit/Losses //
//////////////////////////////////////////////////
tradesback = 5;
Signum = Cum( Buy ) + Cum( Short );
Signumstart1 = LastValue( SigNum ) - ( tradesback - 1 );
Signumstart2 = LastValue( SigNum ) - ( tradesback - 2 );
Signumstart3 = LastValue( SigNum ) - ( tradesback - 3 );
Signumstart4 = LastValue( SigNum ) - ( tradesback - 4 );
Signumstart5 = LastValue( SigNum ) - ( tradesback - 5 );
bi = BarIndex();
bistart = ValueWhen( signum == signumstart1, bi );
bicond = bi >= bistart AND bi <= LastValue( bi );
//Plot (SellPL,"Sell",colorGreen,styleHistogram,maskhistogram);
///Plot (CovPL,"Cover", colorRed,styleHistogram,maskhistogram);
vs= IIf(lsince==0,hsince,lsince);
//////////////////////////////////////////////////
// Plot the Last Five Trades Profit/Losses //
//////////////////////////////////////////////////
FS=Param("Font Size",30,11,100,1);
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorGreen) );
Hor=Param("Horizontal Position",940,1,1200,1);
Ver=Param("Vertical Position",12,1,830,1);
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSetBkMode( colorBlack );
GfxSetTextColor(ParamColor("Color",colorYellow) );
_SECTION_END();
_SECTION_BEGIN("Time Left");
RequestTimedRefresh( 1 );
TimeFrame = Interval();
SecNumber = GetSecondNum();
x=Param("xposn",50,0,1000,1);
y=Param("yposn",380,0,1000,1);
if ( NewPeriod )
GfxSelectSolidBrush( colorYellow );
GfxSelectPen( colorYellow, 2 );
Say( "New period" );
//GfxSetBkMode(1);
GfxSetTextColor( colorRed );
_SECTION_END();