Linkon's AFL collection...

johnnypareek

Well-Known Member
here it is

HTML:
SetChartOptions(0,chartShowArrows|chartShowDates);

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} -                       "+ EncodeColor(colorYellow)+"Open = "+ EncodeColor(colorYellow) +"%g    "+ EncodeColor(colorBrightGreen)+"High = "+ EncodeColor(colorBrightGreen) +"%g - "+ EncodeColor(colorRed)+"Low = "+ EncodeColor(colorRed) +"%g    "+ EncodeColor(colorYellow) +"Close = "+ EncodeColor(colorYellow) +" %g                                                                                                                                                                                                                                                                                                                                          (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

/////////////////////////////////////////////////////////////////////////////////////////////////

SetChartBkColor(ParamColor("Outer panel color ",colorBlack));
tgt = 37;
a = CCI(20) < -tgt;
b = CCI(20) > tgt;
state = IIf(a>b,-1,IIf(a==b,0,1));
Color = IIf(state == 0, colorBlue, IIf(state == 1, colorBrightGreen, IIf(state == -1, colorRed, 0)));
//Plot(state, "", color, styleHistogram);

/////////////////////////////////////////////////////////////////////////////////////////////////

Plot( C, "Close", color, styleNoTitle |styleBar|styleNoTitle); 

/////////////////////////////////////////////////////////////////////////////////////////////////

Odd=13;//enter Odd numbers only
CoefOdd=round(Odd/2);

Even=12;//enter Even numbers only
Coefeven=Even/2;
Coefeven2=Coefeven+1;

CongestionPercent=2.8;/*Set % above/below Moving average for congestion / sideways market*/

TriangularOdd=MA(MA(C,CoefOdd),CoefOdd);
TriangularEven=MA(MA(C,Coefeven),Coefeven2);

finalMov_avg=IIf(Odd > even,triangularOdd,TriangularEven);

Color=colorBrightGreen;//select Moving average line color
tickercolor=colorBlack;//select price color

Plot(finalMov_avg,"",IIf(C < finalmov_avg,colorRed,Color),styleDashed|styleThick);


/////////////////////////////////////////////////////////////////////////////////////////////////////

//Previous Days HI LO //

DayH = TimeFrameGetPrice("H", inDaily, -1);	 DayHI = LastValue (DayH,1);// yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1);	 DayLI = LastValue (DayL,1);	// yesterdays low
DayC = TimeFrameGetPrice("C", inDaily, -1);	 	// yesterdays close
DayO = TimeFrameGetPrice("O", inDaily);			// current day open
DayH2= TimeFrameGetPrice("H", inDaily, -2);  DayH2I = LastValue (DayH2,1); // Two days before high
DayL2= TimeFrameGetPrice("L", inDaily, -2);  DayL2I = LastValue (DayL2,1);  // Two days before low
DayH3= TimeFrameGetPrice("H", inDaily, -3);  DayH3I = LastValue (DayH3,1);  // Three days before high
DayL3= TimeFrameGetPrice("L", inDaily, -3);  DayL3I = LastValue (DayL3,1);  // Three days before low

numbars = LastValue(Cum(Status("barvisible")));
hts  = -33.5;

YHL = ParamToggle("Yesterday HI LO","Show|Hide",1);
if(YHL==1) {
  Plot(DayL,"YL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(DayH,"YH",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  PlotText(" YH " , 	LastValue(BarIndex())-(numbars/Hts), DayHI, colorTurquoise);
  PlotText(" YL " , 	LastValue(BarIndex())-(numbars/Hts), DayLI, colorTurquoise);
}

TDBHL = ParamToggle("2/3Days before HI LO","Show|Hide",0);
if(TDBHL==1) {
  Plot(DayL2,"2DBL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(DayH2,"2DBH",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(DayL3,"3DBL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(DayH3,"3DBH",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  PlotText(" 2DBH " , 	LastValue(BarIndex())-(numbars/Hts), DayH2I, colorTurquoise);
  PlotText(" 2DBL " , 	LastValue(BarIndex())-(numbars/Hts), DayL2I, colorTurquoise);
  PlotText(" 3DBH " , 	LastValue(BarIndex())-(numbars/Hts), DayH3I, colorTurquoise);
  PlotText(" 3DBL " , 	LastValue(BarIndex())-(numbars/Hts), DayL3I, colorTurquoise);
}

// Pivot Levels //
PP = (DayL + DayH + DayC)/3;  PPI = LastValue (PP,1);   // Pivot
R1  =  (PP * 2) - DayL;       R1I = LastValue (R1,1);   // Resistance 1
S1  =  (PP * 2)  - DayH;      S1I = LastValue (S1,1);   // Support 1
R2  =  PP + R1 - S1;          R2I = LastValue (R2,1);   // Resistance 2
S2  =  PP - R1 + S1;          S2I = LastValue (S2,1);   // Support 2
R3  =  PP + R2 - S1;          R3I = LastValue (R3,1);   // Resistance 3
S3  =  PP - R2 + S1;          S3I = LastValue (S3,1);   // Support 3

ppl = ParamToggle("Pivot Levels","Show|Hide",1);
if(ppl==1)  {
  Plot(PP, "PP",colorYellow,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(R1, "R1",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(S1, "S1",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(R2, "R2",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(S2, "S2",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(R3, "R3",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(S3, "S3",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);

  PlotText(" Pivot ",  LastValue(BarIndex())-(numbars/Hts), PPI, colorYellow);
  PlotText(" R1 " ,    LastValue(BarIndex())-(numbars/Hts), R1I, colorViolet);
  PlotText(" S1 " ,    LastValue(BarIndex())-(numbars/Hts), S1I, colorViolet);
  PlotText(" R2 " ,    LastValue(BarIndex())-(numbars/Hts), R2I, colorViolet);
  PlotText(" S2 " ,    LastValue(BarIndex())-(numbars/Hts), S2I, colorViolet);
  PlotText(" R3 " ,    LastValue(BarIndex())-(numbars/Hts), R3I, colorViolet);
  PlotText(" S3 " ,    LastValue(BarIndex())-(numbars/Hts), S3I, colorViolet);
}
// Camerilla Levels //

rg = (DayH - DayL);

H5=DayC+1.1*rg;     H5I = LastValue (H5,1);
H4=DayC+1.1*rg/2;   H4I = LastValue (H4,1);
H3=DayC+1.1*rg/4;   H3I = LastValue (H3,1);
H2=DayC+1.1*rg/6;   H2I = LastValue (H2,1);
H1=DayC+1.1*rg/12;  H1I = LastValue (H1,1);
L1=DayC-1.1*rg/12;  L1I = LastValue (L1,1);
L2=DayC-1.1*rg/6;   L2I = LastValue (L2,1);
L3=DayC-1.1*rg/4;   L3I = LastValue (L3,1);
L4=DayC-1.1*rg/2;   L4I = LastValue (L4,1);
L5=DayC-1.1*rg;     L5I = LastValue (L5,1);

pcl = ParamToggle("Camerilla Levels","Show|Hide",0);
if(pcl==1)  {
   Plot(H5,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(H4,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(H3,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(H2,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(H1,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(L1,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(L2,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(L3,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(L4,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(L5,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   PlotText(" H5 = " , 	LastValue(BarIndex())-(numbars/Hts), H5I  +0.05, colorRose);
   PlotText(" H4 = " , 	LastValue(BarIndex())-(numbars/Hts), H4I  +0.05, colorRose);
   PlotText(" H3 = " , 	LastValue(BarIndex())-(numbars/Hts), H3I  +0.05, colorRose);
   PlotText(" H2 = " , 	LastValue(BarIndex())-(numbars/Hts), H2I  +0.05, colorRose);
   PlotText(" H1 = " , 	LastValue(BarIndex())-(numbars/Hts), H1I  +0.05, colorRose);
   PlotText(" L1 = " , 	LastValue(BarIndex())-(numbars/Hts), L1I  +0.05, colorRose);
   PlotText(" L2 = " , 	LastValue(BarIndex())-(numbars/Hts), L2I  +0.05, colorRose);
   PlotText(" L3 = " , 	LastValue(BarIndex())-(numbars/Hts), L3I  +0.05, colorRose);
   PlotText(" L4 = " , 	LastValue(BarIndex())-(numbars/Hts), L4I  +0.05, colorRose);
   PlotText(" L5 = " , 	LastValue(BarIndex())-(numbars/Hts), L5I  +0.05, colorRose);
}

// Current Days Hi Lo //
THL = ParamToggle("Todays Hi Lo","Show|Hide",1);
if(THL==1)  {
  isRth = TimeNum() >= 084500 & TimeNum() <= 085959;
  isdRth = TimeNum() >= 084500 & TimeNum() <= 160000;
  aRthL = IIf(isRth, L, 1000000);
  aRthH = IIf(isdRth, H, Null);
  aRthLd = IIf(isdRth, L, 1000000);
  DayH = TimeFrameCompress( aRthH, inDaily, compressHigh );
  DayH = TimeFrameExpand( DayH, inDaily, expandFirst );
  DayL = TimeFrameCompress( aRthLd, inDaily, compressLow );
  DayL = TimeFrameExpand( DayL, inDaily, expandFirst );
  Bars = BarsSince(TimeNum() >= 94500 AND TimeNum() < 095959);//,BarIndex(),1); // AND DateNum()==LastValue(DateNum());
  x0 = BarCount-LastValue(Bars);
  x1 = BarCount-1;
  DayHline=LineArray(x0,LastValue(DayH),x1,LastValue (DayH),0); 
  DayLline=LineArray(x0,LastValue(DayL),x1,LastValue (DayL),0); 
  DayHlineI = LastValue (DayHline,1);
  DayLlineI = LastValue (DayLline,1);
  Plot(DayHline,"DayH",colorYellow,styleBar|styleNoRescale|styleNoTitle);
  Plot(DayLline,"DayL",colorYellow,styleBar|styleNoRescale|styleNoTitle);
  PlotText(" Day Hi " , 	LastValue(BarIndex())-(numbars/Hts), DayHlineI  +0.05, colorYellow);
  PlotText(" Day Lo " , 	LastValue(BarIndex())-(numbars/Hts), DayLlineI  +0.05, colorYellow);
 }

/////////////////////////////////////////////////////////////////////////////////////////////////

//Support and resistance levels using RSI.
//graham Kavanagh May 2003
//Load into Indicator Builder
//Sensitivity of the levels can be changed with the variables
//Can test different numbers live with the Param function ctrl-R with open pane
RSIperiod	= 5;	// Param("RSI p",3,14,30,1);
Percent 		= 5;	//	Param("ZIG %",8,9,15,1);
EMAperiod 	= 5;	//Param("EMA p",4,5,10,1);
HHVperiod 	= 5;	//Param("HHV p",3,5,10,1);
NumLine 		= 1;	//Param("Num Lines",3,1,20,1);

Base = DEMA(RSI(RSIperiod),EMAperiod);

for( i = 1; i <= numline; i++ )
{
ResBase = LastValue(Peak(Base,Percent,i));
SupBase = LastValue(Trough(Base,Percent,i));
Plot(ValueWhen( ResBase==Base, HHV(H,HHVperiod) ), "Resist Level", colorPink,
styleDots);
Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ), "Support Level", colorBlue,
styleDots);
}
Title = Name() + "; " + Date() + ": Support & Resistance Levels using RSI: " +
/*EncodeColor(colorGreen)+ "Support Levels are Green; "+EncodeColor(colorRed)+
"Resistance Levels are Red: "+EncodeColor(colorBlack)+*/ "Num lines
="+WriteVal(numline,1) ;

/////////////////////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("MACD Exploration");
r1 = Param( "Fast avg", 15, 2, 200, 1 );
r2 = Param( "Slow avg", 30, 2, 200, 1 );
r3 = Param( "Signal avg", 12, 2, 200, 1 );
Z=Param("zig",1,0,10,0.1);
Cond1 = Cross(MACD(r1,r2),Signal(r1,r2,r3));

EMA34 = EMA(C,34); 
LSMA = LinearReg(C,25); 

//Uncomment for lsma. 
//Plot(LSMA,"LSMA 25", colorLightBlue, styleLine | styleNoLabel | styleThick); 

PI = atan(1.00) * 4; 
periods = 30; 
HighHigh = HHV(H, periods); 
LowLow = LLV(L, periods); 
range = 25 / (HighHigh - LowLow) * LowLow; 

x1_EMA34 = 0; 
x2_EMA34 = 2; 
y1_EMA34 = 0; 
y2_EMA34 = (Ref(EMA34, -2) - EMA34) / Avg * range; 

c_EMA34 = sqrt((x2_EMA34 - x1_EMA34)*(x2_EMA34 - x1_EMA34) + (y2_EMA34 - y1_EMA34)*(y2_EMA34 - y1_EMA34)); 
angle_EMA34 = round(180 * acos((x2_EMA34 - x1_EMA34)/c_EMA34) / PI); 

TitleAngleEMA34 = EncodeColor(colorWhite) + "\nEMA34 angle = "; 

angle_EMA34 = IIf(y2_EMA34 > 0, - angle_EMA34, angle_EMA34); 
if(abs(SelectedValue(angle_EMA34)) >= 25) 
{ 
TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorBrightGreen); 
} 
else if(abs(SelectedValue(angle_EMA34)) >= 15) 
{ 
TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorBlue); 
} 
else 
{ 
TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorRed); 
} 
TitleAngleEMA34 = TitleAngleEMA34 + angle_EMA34; 


//////////////////////////////////////////////////////////////////////////////

Color_ema_eangle= IIf(angle_ema34>=5,colorBrightGreen,IIf(angle_ema34<=-5,colorRed,colorBlue)); 

Plot(EMA34,"EMA 34",Color_ema_eangle, styleLine | styleThick | styleNoLabel ); 

//////////////////////////////////////////////////////////////////////////////
_SECTION_END();



//////////////////////////////////////////////////////////////////////////////
 /* **********************************

Code to automatically identify pivots

********************************** */
// -- what will be our lookback range for the hh and ll?
farback=Param("How Far back to go",200,12,30,1);
nBars = Param("Number of bars", 12, 1, 30, 1);
// -- Create 0-initialized arrays the size of barcount
aHPivs = H - H;
aLPivs = L - L;
// -- More for future use, not necessary for basic plotting
aHPivHighs = H - H;
aLPivLows = L - L;
aHPivIdxs = H - H;
aLPivIdxs = L - L;
nHPivs = 0;
nLPivs = 0;
lastHPIdx = 0;
lastLPIdx = 0;
lastHPH = 0;
lastLPL = 0;
curPivBarIdx = 0;
// -- looking back from the current bar, how many bars 
// back were the hhv and llv values of the previous 
// n bars, etc.?
aHHVBars = HHVBars(H, nBars);
aLLVBars = LLVBars(L, nBars);
aHHV = HHV(H, nBars);
aLLV = LLV(L, nBars);
// -- Would like to set this up so pivots are calculated back from
// last visible bar to make it easy to "go back" and see the pivots
// this code would find. However, the first instance of 
// _Trace output will show a value of 0
aVisBars = Status("barvisible");
nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));
_TRACE("Last visible bar: " + nLastVisBar);
// -- Initialize value of curTrend
curBar = (BarCount-1);
curTrend = "";
if (aLLVBars[curBar] < 
aHHVBars[curBar]) {
curTrend = "D";
}
else {
curTrend = "U";
}
// -- Loop through bars. Search for 
// entirely array-based approach
// in future version
for (i=0; i<farback; i++) {
curBar = (BarCount - 1) - i;
// -- Have we identified a pivot? If trend is down...
if (aLLVBars[curBar] < aHHVBars[curBar]) {
// ... and had been up, this is a trend change
if (curTrend == "U") {
curTrend = "D";
// -- Capture pivot information
curPivBarIdx = curBar - aLLVBars[curBar];
aLPivs[curPivBarIdx] = 1;
aLPivLows[nLPivs] = L[curPivBarIdx];
aLPivIdxs[nLPivs] = curPivBarIdx;
nLPivs++;
}
// -- or current trend is up
} else {
if (curTrend == "D") {
curTrend = "U";
curPivBarIdx = curBar - aHHVBars[curBar];
aHPivs[curPivBarIdx] = 1;
aHPivHighs[nHPivs] = H[curPivBarIdx];
aHPivIdxs[nHPivs] = curPivBarIdx;
nHPivs++;
}
// -- If curTrend is up...else...
} 
// -- loop through bars
} 
// -- Basic attempt to add a pivot this logic may have missed
// -- OK, now I want to look at last two pivots. If the most 
// recent low pivot is after the last high, I could
// still have a high pivot that I didn't catch
// -- Start at last bar
curBar = (BarCount-1);
candIdx = 0;
candPrc = 0;
lastLPIdx = aLPivIdxs[0];
lastLPL = aLPivLows[0];
lastHPIdx = aHPivIdxs[0];
lastHPH = aHPivHighs[0];
if (lastLPIdx > lastHPIdx) {
// -- Bar and price info for candidate pivot
candIdx = curBar - aHHVBars[curBar];
candPrc = aHHV[curBar]; 
if (
lastHPH < candPrc AND
candIdx > lastLPIdx AND
candIdx < curBar) {
// -- OK, we'll add this as a pivot...
aHPivs[candIdx] = 1;
// ...and then rearrange elements in the 
// pivot information arrays
for (j=0; j<nHPivs; j++) {
aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-
(j+1)];
aHPivIdxs[nHPivs-j] = aHPivIdxs[nHPivs-(j+1)];
}
aHPivHighs[0] = candPrc ;
aHPivIdxs[0] = candIdx;
nHPivs++;
} 
} else {
// -- Bar and price info for candidate pivot
candIdx = curBar - aLLVBars[curBar];
candPrc = aLLV[curBar]; 
if (
lastLPL > candPrc AND
candIdx > lastHPIdx AND
candIdx < curBar) {
// -- OK, we'll add this as a pivot...
aLPivs[candIdx] = 1;
// ...and then rearrange elements in the 
// pivot information arrays
for (j=0; j<nLPivs; j++) {
aLPivLows[nLPivs-j] = aLPivLows[nLPivs-(j+1)];
aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-(j+1)];
}
aLPivLows[0] = candPrc;
aLPivIdxs[0] = candIdx;
nLPivs++;
}
}
// -- Dump inventory of high pivots for debugging
/*
for (k=0; k<nHPivs; k++) {
_TRACE("High pivot no. " + k
+ " at barindex: " + aHPivIdxs[k] + ", " 
+ WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k], 
DateTime(), 1), formatDateTime)
+ ", " + aHPivHighs[k]);
}
*/
// -- OK, let's plot the pivots using arrows
PlotShapes(IIf(aHPivs==1, shapeSmallDownTriangle, shapeNone), colorCustom12, 0, High, Offset=-5);
PlotShapes(IIf(aLPivs==1, shapeSmallUpTriangle , shapeNone), colorCustom11, 0, Low, Offset=-5);

Sell = aHPivs == 1 ;
Buy = aLPivs == 1 ;
Filter=Buy OR Sell; 
Sell=ExRem(Sell,Buy); 
Buy=ExRem(Buy,Sell);

/////////////////////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("Price");

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}}    -    {{INTERVAL}}    -    {{DATE}}                "+ EncodeColor(colorYellow)+"Open = "+ EncodeColor(colorYellow) +"%g    "+ EncodeColor(colorBrightGreen)+"High = "+ EncodeColor(colorBrightGreen) +"%g    "+ EncodeColor(colorRed)+"Low = "+ EncodeColor(colorRed) +"%g    "+ EncodeColor(colorYellow) +"Close = "+ EncodeColor(colorYellow) +" %g                                                                                                                                                                                                                                                                                                                                          (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("Magnified Market Price");
//by Vidyasagar, [email protected]//
FS=Param("Font Size",30,30,100,1);
GfxSelectFont("Arial", FS, 900, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorYellow) );
Hor=Param("Horizontal Position",800,800,800,800);
Ver=Param("Vertical Position",26,26,26,26);
GfxTextOut(""+C,Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Arial", 12, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorYellow) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor+5, Ver+45 );
_SECTION_END();

/////////////////////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("trending ribbon");
uptrend=PDI()>MDI()AND Signal()<MACD();
downtrend=MDI()>PDI()AND Signal()>MACD();
Plot( 2, /* defines the height of the ribbon in percent of pane width */"ribbon",
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, colorPink )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();
GraphXSpace = 20 ;
/////////////////////////////////////////////////////////////////////////////////////////////////
[email protected]
 
Thread starter Similar threads Forum Replies Date
linkon7 Options 170
VJAY Options 10
linkon7 Options 36
linkon7 Day Trading 477
linkon7 Options 17

Similar threads