Niludeepak : 15 Min Time Frame Trading in Nifty

sunilrhs

Well-Known Member
Hi Nilu,

Thanks for the great effort u are putting in....have gone through the method and the afl too. found it quite interesting if it can be used with some other indicators and I guess u are already working on them.

What i found is missing that you can not put this afl on auto scanning as it will auto scan the bars, everytime there is new higher high/lower low on last 8 bars. What i feel is, it should only scan the bars where the sell or buy signal has come and should ignore the rest of higher highs and lower lows...

EG:- if any stock is making higher high for last 15-20 bars then auto-scanner will show the same stock 10-12 times and thus create confusion, if it is put to scan , say, 100 stocks.

Can anyone provide this missing code?


it is very sorry on my part to not to be able to update my threads on regular basis, was busy in personal endeavours,

i m working on minimising whipsaws using stochastics(8,3,5) and cci14, in 15min, hrly and daily timeframes, this project is going fine, i'll publish soon.

thnx all, pl. write if have some ideas.
 
jonny,

can you help me for rectifying the below AFL?


_SECTION_BEGIN
messageboard =ParamToggle("Message Board","Show|Hide",1);
no = Optimize("TSL",Param("A (Change To Optimise)",10, 1, 55 ,1),1, 55 ,1);
multiplier1 = Optimize("Multiplier1",Param("B (Change To Optimise)",5, 1, 55 ,1),1, 55 ,1);
multiplier2 = Optimize("Multiplier2",Param("C (Change To Optimise)",22, 1, 55 ,1),1, 55 ,1);
showtsl =ParamToggle("Show SL Line","No|Yes");
aggressivemode =ParamToggle("Aggressive Mode","Yes|No",0);
stopreverse =ParamToggle("Switch To Stop And Reverse","No|Yes",0);
CloseAtEnd = ParamToggle("Close Positions EOD", "No|Yes");
ShowBands = ParamToggle("Show Trending Bands", "No|Yes");
supres=ParamToggle("Show Support / Resistance","No|Yes");
ShowCrossover = ParamToggle("Show Crossover", "No|Yes");
AudioAlert = ParamToggle("Human Voice Alert", "No|Yes");
EmailAlert = ParamToggle("E-mail Alert", "No|Yes");
AlertOutput = ParamToggle("Alert Output", "No|Yes");
showtrendline = ParamToggle("Show Trend Line", "No|Yes");
fibs = ParamToggle("Plot Fibonacci Retracement","No|Yes");
text = ParamToggle("Plot Fibonnaci As Text","No|Yes",0);
mktclose=Param("Market Close Time",152500,000000,235959,1 );

Param_Margin = Param("Margin required (used for backtesting only)", 15,0.001,100,0.001);
Param_LotSize = Param("Lot Size (used for backtesting only)", 50,5,5000,5);
Param_NoOfLots = Param("No of lots normally traded (used for backtesting only)",1,1,10000,1);

C13=20;
C14=2.1;
C15=12;
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");

EntrySignal = TBTS_F1();
ExitSignal = TBTS_F2();
Color = IIf( EntrySignal, colorBlue, IIf( ExitSignal, colorRed, colorLightGrey ));
Plot( C, "Price", Color, styleCandle | styleThick );

if (stopreverse==0)
{
if (aggressivemode == 0)

{
dtsl=TBTS_F3(no);
dB=H>dtsl;
dS=L<dtsl;
state=IIf(BarsSince(DB)<BarsSince(DS),1,0);
col=IIf(state == 1 ,51,IIf(state ==0,3,1));
//Plot(2,"",COL,styleArea|styleOwnScale|styleNoLabel,0,100);

TimeFrameSet(multiplier1*Interval());
wtsl=TBTS_F3(no);
WB=H>WTSL;
WS=L<WTSL;
TimeFrameRestore();
wtsl=TimeFrameExpand(wtsl,multiplier1*Interval(),expandFirst);
wb=TimeFrameExpand(WB,multiplier1*Interval(),expandFirst);
ws=TimeFrameExpand(WS,multiplier1*Interval(),expandFirst);


TimeFrameSet(multiplier2*Interval());
mtsl=TBTS_F3(no);
MB=H>MTSL;//Cross(H,mtsl);
MS=L<MTSL;//Cross(mtsl,L);
TimeFrameRestore();
mtsl=TimeFrameExpand(mtsl,multiplier2*Interval(),expandFirst);
mb=TimeFrameExpand(MB,multiplier2*Interval(),expandFirst);
ms=TimeFrameExpand(MS,multiplier2*Interval(),expandFirst);
}

if (aggressivemode == 1)
{
dtsl=TBTS_F3(no);
dB=H>dtsl;
dS=L<dtsl;
state=IIf(BarsSince(DB)<BarsSince(DS),1,0);
col=IIf(state == 1 ,51,IIf(state ==0,3,1));
//Plot(2,"",COL,styleArea|styleOwnScale|styleNoLabel,0,100);

TimeFrameSet(multiplier1*Interval());
wtsl=TBTS_F3(no);
WB=H>WTSL;
WS=L<WTSL;
TimeFrameRestore();
wtsl=TimeFrameExpand(wtsl,multiplier1*Interval(),expandLast);
wb=TimeFrameExpand(WB,multiplier1*Interval(),expandLast);
ws=TimeFrameExpand(WS,multiplier1*Interval(),expandLast);

TimeFrameSet(multiplier2*Interval());
mtsl=TBTS_F3(no);
MB=H>MTSL;
MS=L<MTSL;
TimeFrameRestore();
mtsl=TimeFrameExpand(mtsl,multiplier2*Interval(),expandLast);
mb=TimeFrameExpand(MB,multiplier2*Interval(),expandLast);
ms=TimeFrameExpand(MS,multiplier2*Interval(),expandLast);
}

Buy = IIf((Low > WTSL AND Low > MTSL), DB, ((WB AND Low > DTSL AND Low > MTSL) OR (MB AND Low > DTSL AND Low > WTSL)));
Sell=IIf(CloseAtEnd==False, (DS OR (DS AND WS) AND (Low > MTSL)), (DS OR (DS AND WS) AND (Low > MTSL)) OR TimeNum() > mktclose);
Short = IIf((High < WTSL AND High < MTSL), DS, (WS AND High < DTSL AND High < MTSL) OR (MS AND High < DTSL AND High < WTSL));
Cover=IIf(CloseAtEnd==False, (DB OR (DB AND WB) AND (High < MTSL)), (DB OR (DB AND WB) AND (High < MTSL)) OR TimeNum() > mktclose);
}

if (stopreverse==1)
{
dtsl=TBTS_F4(no);
dB=C>dtsl;
dS=C<dtsl;
state=IIf(BarsSince(DB)<BarsSince(DS),1,0);
col=IIf(state == 1 ,51,IIf(state ==0,3,1));
//Plot(2,"",COL,styleArea|styleOwnScale|styleNoLabel,0,100);
Buy = Cover = DB;
Sell = Short = DS;
}

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);

SellPrice=ValueWhen(Short,C,1);
BuyPrice=ValueWhen(Buy,C,1);
Long=Flip(Buy,Sell);
Shrt=Flip(Short,Cover);
Relax = NOT Long AND NOT Buy AND NOT shrt AND NOT Sell AND NOT Sell AND NOT Cover;
SellSL=ValueWhen(Short,DTSL,1);
BuySL=ValueWhen(Buy,DTSL,1);
BuyDifference= BuyPrice - BuySL;
SellDifference = SellSL - SellPrice;

tar1 = IIf(Buy OR Long AND NOT Relax AND NOT Sell AND NOT Cover, (BuyPrice + BuyDifference), (SellPrice - SellDifference));
tar2 = IIf(Buy OR Long AND NOT Relax AND NOT Sell AND NOT Cover, (BuyPrice + (2*BuyDifference)), (SellPrice - (2*SellDifference)));
tar3 = IIf(Buy OR Long AND NOT Relax AND NOT Sell AND NOT Cover, (BuyPrice + (4*BuyDifference)), (SellPrice - (4*SellDifference)));

buyach1 = IIf((Buy OR Long AND NOT Relax AND NOT Cover AND NOT Short AND NOT Shrt), H > tar1, 0);
buyach2 = IIf((Buy OR Long AND NOT Relax AND NOT Cover AND NOT Short AND NOT Shrt), H > tar2, 0);
buyach3 = IIf((Buy OR Long AND NOT Relax AND NOT Cover AND NOT Short AND NOT Shrt), H > tar3, 0);

sellach1 = IIf((Short OR Shrt AND NOT Relax AND NOT Sell AND NOT Buy AND NOT Long), L < tar1, 0);
sellach2 = IIf((Short OR Shrt AND NOT Relax AND NOT Sell AND NOT Buy AND NOT Long), L < tar2, 0);
sellach3 = IIf((Short OR Shrt AND NOT Relax AND NOT Sell AND NOT Buy AND NOT Long), L < tar3, 0);

Trend = ADX(14) > 25 AND NOT ADX(14) < Ref(ADX(14), -1);
Range = ADX(14) < 25 AND NOT ADX(14) > Ref(ADX(14), -1);


if (AudioAlert==True)
{
if (SelectedValue(Buy)==1) Say("Go long in "+Name()+" at current market price "+C);
if (SelectedValue(Short)==1) Say("Go short in "+Name()+" at current market price "+C);
if (stopreverse==0)
{
if (SelectedValue(Sell AND NOT Short)==1) Say("Exit long in "+Name()+" at current market price "+C);
if (SelectedValue(Cover AND NOT Buy)==1) Say("Exit short in "+Name()+" at current market price "+C);
}
}

if (EmailAlert==True)
{
AlertIf( Buy, "EMAIL", "Long signal generated on "+FullName(), 1 );
if (stopreverse==0)
{
AlertIf( Sell AND NOT Short, "EMAIL", "Exit long signal generated on "+FullName(), 1 );
}
AlertIf( Short, "EMAIL", "Short signal generated on "+FullName(), 1 );
if (stopreverse==0)
{
AlertIf( Cover AND NOT Buy, "EMAIL", "Exit short signal generated on "+FullName(), 1 );
}
}

if (AlertOutput==True) {
AlertIf( Buy, "", "Buy Signal Generated"+Name(), 4 );
AlertIf( Sell AND NOT Short, "", "Exit Long Signal Generated"+Name(), 4 );
AlertIf( Short, "", "Short Signal Generated"+Name(), 4 );
AlertIf( Cover AND NOT Buy, "", "Exit Short Signal Generated"+Name(), 4 );
}

if (showtsl==True)
{
tsl = IIf(Buy OR Long OR Short OR Shrt AND NOT Relax, dtsl,Null);
tslcolor = IIf(Buy OR Long AND NOT Relax, colorGreen, colorRed);
Plot(tsl, "",tslcolor, styleLine|styleDots|styleThick);
}

if
(messageboard == 0 )

{

SetChartOptions(0,chartShowArrows|chartShowDates);
Title = EncodeColor(colorYellow)+ Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorSkyblue) +
" - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Open-"+O+" "+"High-"+H+" "+"Low-"+L+" "+"Close-"+C+" "+ "Volume= "+ WriteVal(V);

GfxSelectFont( "Tahoma", 13, 100 );

GfxSetBkMode( 1 );

GfxSetTextColor
( colorWhite );

GfxSelectSolidBrush( colorGreen );

pxHeight = Status( "pxchartheight" ) ;

xx = Status( "pxchartwidth");

Left = 1100;

width = 310;

x = 5;

x2 = 290;

y = pxHeight;

GfxSelectPen
( colorLightBlue, 1); // border color

GfxRoundRect
( x, y - 215, x2, y , 7, 7 ) ;

GfxTextOut
( ("For Enquiry: www.stockmaniacs.net"),13,y-210);

GfxTextOut
( ("" + WriteIf(trend, "Trending Market Condition " ,"")), 13, y-185);

GfxTextOut
( ("" + WriteIf(range, "Rangebound Market Condition " ,"")), 13, y-185);

GfxTextOut
( ("" + WriteIf(Buy, "Go Long At "+C+" - SL " +dtsl,"")), 13, y-165);

GfxTextOut
( ("" + WriteIf (Short, "Go Short At "+C+" - SL " +dtsl,"")), 13, y-165);

if (stopreverse==0)
{
GfxTextOut
( ("" + WriteIf (Sell AND NOT Short, "Exit Long At "+C,"")), 13, y-165);

GfxTextOut
( ("" + WriteIf (Cover AND NOT Buy, "Exit Short At "+C,"")), 13, y-165);
}

GfxTextOut
( ("" + WriteIf (Long AND NOT Buy, "Long At "+(BuyPrice)+" - TSL " + dtsl + "","")), 13, y-165);

GfxTextOut
( ("" + WriteIf (shrt AND NOT Short, "Short At "+(SellPrice)+" - TSL " + dtsl + "","")), 13, y-165);

GfxTextOut
( ("" + WriteIf (Relax, "Not In Trade - RELAX!!!","")), 13, y-165);

GfxTextOut
( ("" + WriteIf (Long AND NOT Buy, "Current P/L: "+(C-BuyPrice)+" Points","")), 13, y-145);

GfxTextOut
( ("" + WriteIf (shrt AND NOT Short, "Current P/L: "+(SellPrice-C)+" Points","")), 13, y-145);

GfxTextOut
( ("" + WriteIf (Long OR Buy OR Shrt OR Short, "Target 1: "+tar1,"")), 13, y-125);

GfxTextOut
( ("" + WriteIf (Long OR Buy OR Shrt OR Short, "Target 2: "+tar2,"")), 13, y-105);

GfxTextOut
( ("" + WriteIf (Long OR Buy OR Shrt OR Short, "Target 3: "+tar3,"")), 13, y-85);

GfxTextOut
( ("" + WriteIf (buyach1, "Target 1 Done: "+tar1,"")), 13, y-65);

GfxTextOut
( ("" + WriteIf (sellach1, "Target 1 Done: "+tar1,"")), 13, y-65);

GfxTextOut
( ("" + WriteIf (buyach2, "Target 2 Done: "+tar2,"")), 13, y-45);

GfxTextOut
( ("" + WriteIf (sellach2, "Target 2 Done: "+tar2,"")), 13, y-45);

GfxTextOut
( ("" + WriteIf (buyach3, "Target 3 Done: "+tar3,"")), 13, y-25);

GfxTextOut
( ("" + WriteIf (sellach3, "Target 3 Done: "+tar3,"")), 13, y-25);

}

GfxSetBkMode( 1 );
GfxSelectFont("Tahoma", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxSetTextColor( ColorRGB (217,217,213));
//GfxTextOut( "Trend Blaster V1.2", Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
//GfxTextOut( "By", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
//GfxTextOut( "www.stockmaniacs.net", Status("pxwidth")/C14, Status("pxheight")/C15*4 );
GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-25);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-35);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-30);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=25);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=35);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-30);
if (stopreverse==0)
{
PlotShapes(IIf(Sell, shapeStar, shapeNone),colorGold, 0, L, Offset=-15);
PlotShapes(IIf(Cover, shapeStar, shapeNone),colorGold, 0,L, Offset=-15);
PlotShapes(IIf(CloseAtEnd==True AND TimeNum() > mktclose AND NOT Relax, shapeStar, shapeNone),colorGold, 0,L, Offset=-15);
}

if (messageboard == 1 )
{
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorYellow)+ "Trend Blaster Trading System V1.1 - www.stockmaniacs.net" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorSkyblue) +
" - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Open-"+O+" "+"High-"+H+" "+"Low-"+L+" "+"Close-"+C+" "+ "Volume= "+ WriteVal(V)+"\n"+"\n"+
EncodeColor(colorLime)+"\n"+
WriteIf(trend, "Trending Market Condition " ,"")+
WriteIf(range, "Rangebound Market Condition " ,"")+"\n"+
WriteIf (Buy, "Action: Go Long At "+C+" - SL " +DTSL,"")+
WriteIf (Short, "Action: Go Short At "+C+" - SL " +DTSL,"")+
WriteIf(Long AND NOT Buy, "Action : Long Taken At "+(BuyPrice)+" - Trail SL @ " + DTSL + "","")+
WriteIf(shrt AND NOT Sell, "Action : Short Taken At "+(SellPrice)+" - Trail SL @ " + DTSL + "","")+
WriteIf (Sell AND NOT Short, "Exit Long At "+C,"")+
WriteIf (Cover AND NOT Buy, "Exit Short At "+C,"")+
WriteIf(NOT Long AND NOT Buy AND NOT shrt AND NOT Sell, "Action: Not In A Trade - RELAX!!!","")+"\n"+
WriteIf(Long AND NOT Buy, "Profit/Loss: "+(C-BuyPrice)+" Points","")+
WriteIf(shrt AND NOT Sell, "Profit/Loss: "+(SellPrice-C)+" Points","")+"\n"+
WriteIf(Long OR Buy OR Shrt OR Short, "Target 1: "+tar1,"")+"\n"+
WriteIf(Long OR Buy OR Shrt OR Short, "Target 2: "+tar2,"")+"\n"+
WriteIf(Long OR Buy OR Shrt OR Short, "Target 3: "+tar3,"")+"\n"+
WriteIf(buyach1, "Target 1 Done: "+tar1,"")+
WriteIf(sellach1, "Target 1 Done: "+tar1,"")+"\n"+
WriteIf(buyach2, "Target 2 Done: "+tar2,"")+
WriteIf(sellach2, "Target 2 Done: "+tar2,"")+"\n"+
WriteIf(buyach3, "Target 3 Done: "+tar3,"")+
WriteIf(sellach3, "Target 3 Done: "+tar3,""));
}

//Settings for exploration

Filter=Buy OR Short;
AddColumn( IIf( Buy, 66 , 83 ), "Signal", formatChar, colorDefault, IIf( Buy , colorGreen, colorRed ) );
AddColumn(Close,"Entry Price",1.4, colorDefault, IIf( Buy , colorGreen, colorRed ));
AddColumn(dtsl,"Stop Loss",1.4, colorDefault, IIf( Buy , colorGreen, colorRed ));
AddColumn(tar1,"Target 1",1.4, colorDefault, IIf( Buy , colorGreen, colorRed ));
AddColumn(tar2,"Target 2",1.4, colorDefault, IIf( Buy , colorGreen, colorRed ));
AddColumn(tar3,"Target 3",1.4, colorDefault, IIf( Buy , colorGreen, colorRed ));
AddColumn(Volume,"Volume",1.0, colorDefault, IIf ((Volume > 1.25 * EMA( Volume, 34 )),colorBlue,colorYellow));


//Settings for Backtester
SetOption("AllowSameBarExit", False);
SetOption("AllowPositionShrinking", False);
SetOption("FuturesMode", True);
SetOption("InterestRate",0);
SetOption("MaxOpenPositions",1);
RoundLotSize = Param_LotSize;
SetOption("MinShares",RoundLotSize);
SetOption("PriceBoundChecking",False);
//SetOption("CommissionMode",3);
//SetOption("CommissionAmount",12.5/RoundLotSize);
SetOption("AccountMargin",Param_Margin);
SetOption("ReverseSignalForcesExit",True);
SetOption("UsePrevBarEquityForPosSizing",True);
ApplyStop(stopTypeTrailing, stopModePoint, DTSL, True, True );

PositionSize = C*RoundLotSize*Param_NoOfLots;
SetTradeDelays(0,0,0,0);
BuyPrice = Close;
SellPrice = Close;
ShortPrice = Close;
CoverPrice = Close;

//End of Settings for Backtester

/* Standard Error Bands */
Periods = 80;
Smooth = 14;

MALRCurve = TBTS_F5(Periods,Smooth);
SErrorAvg = TBTS_F6(Periods,Smooth);

LowerBand = MALRCurve - SErrorAvg ;
UpperBand = MALRCurve + SErrorAvg ;
if(ShowBands==True)
{
Plot( MALRCurve , "MidBand", ParamColor("ColorMB",colorLime) , ParamStyle("StyleMB", style=styleDashed, Mask=maskDefault ));
Plot( UpperBand , "UpperBand", ParamColor("ColorUp",colorLime) , ParamStyle("StyleUp", style=styleLine, Mask=maskDefault ));
Plot( LowerBand , "LowerBand", ParamColor("ColorLo",colorLime) , ParamStyle("StyleLo", style=styleLine, Mask=maskDefault ));
}

// Support & resistance identification

HaClose = EMA(TBTS_F7(),3);
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
Temp = Max(High, HaOpen);
Temp = Min(Low,HaOpen);

if(supres==True)
{
Prd1=Param("Res_Period1",10,0,200,1);

test = TEMA ( High , Prd1 ) ;

PK = test > Ref(test,-1) AND Ref(test,1) < High;//Peak
PKV0 = ValueWhen(PK,haHigh,0);//PeakValue0
PKV1 = ValueWhen(PK,haHigh,1);//PeakValue1
PKV2 = ValueWhen(PK,haHigh,2);//PeakValue2

MPK = PKV2 < PKV1 AND PKV1 > PKV0 ;//MajorPeak

MPKV = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,1); //MajorPeakValue
MPKD = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),1); //MajorPeakDate
SD = IIf(DateNum() < LastValue(MPKD,lastmode = True ), Null, LastValue(MPKV,Lastmode = True));//SelectedDate
Plot(SD, "Resist1", colorRed,ParamStyle("ResStyle1",styleLine|styleThick|styleDots|styleNoTitle,maskAll));

MPKV2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,2); //MajorPeakValue
MPKD2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),2); //MajorPeakDate
SD2 = IIf(DateNum() < LastValue(MPKD2,lastmode = True ), Null, LastValue(MPKV2,Lastmode = True));//SelectedDate
Plot(SD2, "Resist2", colorRed,ParamStyle("ResStyle2",styleLine|styleNoTitle,maskAll));


MPKV3 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,3); //MajorPeakValue
MPKD3 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),3); //MajorPeakDate
SD3 = IIf(DateNum() < LastValue(MPKD3,lastmode = True ), Null, LastValue(MPKV3,Lastmode = True));//SelectedDate
Plot(SD3, "Resist3", colorRed,ParamStyle("ResStyle3",styleLine|styleNoTitle,maskAll));

HaClose = EMA(TBTS_F7(),3);
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
Temp = Max(High, HaOpen);
Temp = Min(Low,HaOpen);

//SP=L > Ref(L,-1) AND Ref(L,1) < L;//Peak

Prd2=10;

test2 = TEMA ( Low , Prd2 ) ;

SP = Ref(test2,1) > Low AND test2 < Ref(test2,-1);//Peak
SPV0 = ValueWhen(SP,haLow,0);//PeakValue0
SPV1 = ValueWhen(SP,haLow,1);//PeakValue1
SPV2 = ValueWhen(SP,haLow,2);//PeakValue2

//PKV5 = ValueWhen(PK,haHigh,5);//PeakValue5
//PKV6 = ValueWhen(PK,haHigh,6);//PeakValue6

MSP = SPV2 > SPV1 AND SPV1 < SPV0 ;//MajorPeak

MSPV = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,1);
MSPD = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),1);
SD = IIf(DateNum() < LastValue(MSPD,lastmode = True ), Null, LastValue(MSPV,Lastmode = True));
Plot(SD,"Support1", colorGreen,ParamStyle("SupportLine1",styleLine|styleThick|styleDots|styleNoTitle,maskAll));

MSPV2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,2);
MSPD2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),2);
SD2 = IIf(DateNum() < LastValue(MSPD2,lastmode = True ), Null, LastValue(MSPV2,Lastmode = True));
Plot(SD2,"Support2", colorGreen,ParamStyle("SupportLine2",styleLine|styleNoTitle,maskAll));

MSPV3 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,3);
MSPD3 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),3);
SD3 = IIf(DateNum() < LastValue(MSPD3,lastmode = True ), Null, LastValue(MSPV3,Lastmode = True));
Plot(SD3,"Support3", colorGreen,ParamStyle("SupportLine3",styleLine|styleNoTitle,maskAll));
}

//Fibonacci cluster
pctH = 0.325;
HiLB = 1;
pctL = 0.325;
LoLB = 1;
Back = 1;
Fwd = 0;
hts = -33.5;
style =styleLine;
x = BarIndex();
pRp = PeakBars( H, pctH, 1) == 0;
yRp0 = SelectedValue(ValueWhen( pRp, H, HiLB));
xRp0 = SelectedValue(ValueWhen( pRp, x, HiLB));
pSp = TroughBars( L, pctL, 1) == 0;
ySp0 = SelectedValue(ValueWhen( pSp, L, LoLB));
xSp0 = SelectedValue(ValueWhen( pSp, x, LoLB));
Delta = yRp0 - ySp0;

function fib(ret)
{
retval = (Delta * ret);
Fibval = IIf(ret < 1.0
AND xSp0 < xRp0, yRp0 - retval, IIf(ret < 1.0
AND xSp0 > xRp0, ySp0 + retval,IIf(ret > 1.0
AND xSp0 < xRp0, yRp0 - retval, IIf(ret > 1.0
AND xSp0 > xRp0, ySp0 + retval, Null))));
return FibVal;
}

x0 = Min(xSp0,xRp0)-Back;
x1 = (BarCount -1);
//////////////////////////////////////////////////////////////////
r236 = fib(0.236); r236I = LastValue (r236,1);
r382 = fib(0.382); r382I = LastValue (r382,1);
r050 = fib(0.50); r050I = LastValue (r050,1);
r618 = fib(0.618); r618I = LastValue (r618,1);
r786 = fib(0.786); r786I = LastValue (r786,1);
e127 = fib(1.27); e127I = LastValue (e127,1);
e162 = fib(1.62); e162I = LastValue (e162,1);
e200 = fib(2.00); e200I = LastValue (e200,1);
e262 = fib(2.62); e262I = LastValue (e262,1);
e424 = fib(4.24); e424I = LastValue (e424,1);
//////////////////////////////////////////////////////////////////
p00 = IIf(xSp0 > xRp0,ySp0,yRp0); p00I = LastValue (p00,1);
p100 = IIf(xSp0 < xRp0,ySp0,yRp0); p100I = LastValue (p100,1);
color00 =IIf(xSp0 > xRp0,colorLime,colorRed);
color100 =IIf(xSp0 < xRp0,colorLime,colorRed);
//////////////////////////////////////////////////////////////////
numbars = LastValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
//////////////////////////////////////////////////////////////////
if(fibs==True)
{
Plot(LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back),"PR",32,8|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back),"PS",27,8|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r236,x1,r236,Back),"",45,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r382,x1,r382,Back),"",44,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r050,x1,r050,Back),"",41,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r618,x1,r618,Back),"",43,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r786,x1,r786,Back),"",42,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e127,x1,e127,Back),"e127",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e162,x1,e162,Back),"e162",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e200,x1,e200,Back),"p200",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e262,x1,e262,Back),"p262",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e424,x1,e424,Back),"p424",25,style|styleNoRescale,Null, Null,Fwd);
}
//////////////////////////////////////////////////////////////////
if(text==1)
{
PlotText(" 0% = " + WriteVal(p00,fraction), LastValue(BarIndex())-(numbars/hts), p00I + 0.05, color00);
PlotText("23% = " + WriteVal(r236,fraction), LastValue(BarIndex())-(numbars/hts), r236I + 0.05, 45);
PlotText("38% = " + WriteVal(r382,fraction), LastValue(BarIndex())-(numbars/hts), r382I + 0.05, 44);
PlotText("50% = " + WriteVal(r050,fraction), LastValue(BarIndex())-(numbars/hts), r050I + 0.05, 41);
PlotText("62% = " + WriteVal(r618,fraction), LastValue(BarIndex())-(numbars/hts), r618I + 0.05, 43);
PlotText("78% = " + WriteVal(r786,fraction), LastValue(BarIndex())-(numbars/hts), r786I + 0.05, 42);
PlotText("100% = " + WriteVal(p100,fraction), LastValue(BarIndex())-(numbars/hts),p100I + 0.05, color100);
PlotText("127% = " + WriteVal(e127,fraction), LastValue(BarIndex())-(numbars/hts),e127I + 0.05, 47);
PlotText("162% = " + WriteVal(e162,fraction), LastValue(BarIndex())-(numbars/hts),e162I + 0.05, 47);
PlotText("200% = " + WriteVal(e200,fraction), LastValue(BarIndex())-(numbars/hts),e200I + 0.05, 47);
PlotText("262% = " + WriteVal(e262,fraction), LastValue(BarIndex())-(numbars/hts),e262I + 0.05, 47);
PlotText("424% = " + WriteVal(e424,fraction), LastValue(BarIndex())-(numbars/hts),e424I + 0.05, 25);
}
/////////////////////////////////////////////////////////////////
m = 60;
amv0=Volume*(O+H+L+C)/4;
line=Sum(amv0,50)/Sum(Volume,50);
CG=MA(C,14);
holdline=HHV(CG,3);
if(ShowCrossover==True)
{
Plot(line,"Modified",7,1);
Plot(cg,"A",10,1);
Plot(Holdline,"B",13,1);
PlotOHLC(Holdline,Cg,Holdline,Cg,"",13,styleCloud);
}

if (showtrendline == True)

{
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
THIS SECTION DRAWS TD TREND LINES */

percent = 0.01 * 1; /* Adjust this percent as necessary, */
firstpointL = 2;
firstpointH = 2;

y0=LastValue(Trough(L,percent,firstpointL));
y1=LastValue(Trough(Ref(L,-1),percent,1));

for( i = 1; i < BarCount AND y0 >= y1; i++ )
{

firstpointL++;
y0=LastValue(Trough(L,percent,firstpointL));
}

x0=BarCount - 1 - LastValue(TroughBars(L,percent,firstpointL));
x1=BarCount - 1 - LastValue(TroughBars(Ref(L,-1),percent,1));
LineL = LineArray( x0, y0, x1, y1, 1 );
/*
Plot(C, "C", colorBlack, styleCandle);
*/
Plot( LineL, " Support Trend line", colorGreen,4 +8 );


yt0=LastValue(Peak(H,percent,firstpointH));
yt1=LastValue(Peak(Ref(H,-1),percent,1));

for(i = 1; i < BarCount AND yt0 <= yt1; i++ )
{

firstpointH++;
yt0=LastValue(Peak(H,percent,firstpointH));
}
xt0=BarCount - 1 - LastValue(PeakBars(H,percent,firstpointH));
xt1=BarCount - 1 - LastValue(PeakBars(Ref(H,-1),percent,1));
LineH = LineArray( xt0, yt0, xt1, yt1, 1 );

Plot( LineH, "Resistance Trend line", colorRed,4 + 8 );

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
}

_SECTION_END();
 

Similar threads