My amibroker afl collections

yasu222

Active Member
#1
//

m = Param("Long Pds", 60, 20, 100, 1 );

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g,Hi %g,Lo %g, Close %g (%.1f%%)
Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
barcolor =IIf(C>O, ParamColor("Up candlestick", colorBrightGreen ), ParamColor("Down candlestick", colorOrange ));
Plot( C, "Close", barColor, styleCandle);
amv0=Volume*(O+H+L+C)/4;
line=Sum(amv0,50)/Sum(Volume,50);
Plot(line,"Modified",7,1);
CG=MA(C,14);
Plot(cg,"A",10,1);
holdline=HHV(CG,3);
Plot(Holdline,"B",13,1);
PlotOHLC(Holdline,Cg,Holdline,Cg,"",13,styleCloud) ;

_SECTION_BEGIN("Volume");
Plot( Volume, "Volume", ParamColor("Color", colorLightGrey ), 2 | 32768 );
_SECTION_END();
 

lvgandhi

Well-Known Member
#2
Good work. But write their intended job in comments at the beginning of AFL.
 
#3
hik
it takes volume weighted average price-similar to vwap
agent brokers for institutions are paid for buying at price lower than vwap and selling at price higher than vwap

buy if prce is at or above holdline cloud.
sell if price is below holdline cloud
 

yasu222

Active Member
#4
"GAIN" AFL FOR intraday players

PctVlt=(ATR(14)/C)*100;//PercentVolatility

PK=IIf(PctVlt<0.5,Peak(Close,0.5,1),
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,Peak(Close,0.70,1),
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,Peak(Close,0.90,1),
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,Peak(Close,1.10,1),
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,Peak(Close,1.30,1),
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,Peak(Close,1.50,1),
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,Peak(Close,1.70,1),
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,Peak(Close,2.00,1),
Peak(Close,2.20,1) ))))))));

TGH=IIf(PctVlt<0.5,Trough(Close,0.5,1),
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,Trough(Close,0.75,1),
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,Trough(Close,1.00,1),
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,Trough(Close,1.25,1),
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,Trough(Close,1.50,1),
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,Trough(Close,1.75,1),
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,Trough(Close,2.00,1),
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,Trough(Close,2.25,1),
Trough(Close,2.50,1) ))))))));

Sens=IIf(PctVlt<0.5,0.5,
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,0.75,
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,1.00,
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,1.25,
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,1.50,
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,1.75,
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,2.00,
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,2.25,
2.50 ))))))));


Color=IIf(BarsSince(Cross(C,Ref(PK,-1)))<BarsSince(Cross(Ref(TGH,-1),C)),colorBrightGreen,colorRed);
Plot(C,"Chaloke.com Peak-Trough",Color,styleCandle);

///////////////////////////////////////////////////////////////////////////////////////////////////////////
_SECTION_BEGIN("RI Auto Trading System");

acc = Param("Acceleration", 0.1, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.06, 0, 1, 0.001 );

Buy = Cross(Open, SAR(acc,accm));
Sell = Cross(SAR(acc,accm), Open );

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone), colorYellow, 0, Low, Offset=-15);
PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone), colorYellow, 0, Low, Offset=-28);

PlotShapes(IIf(Sell, shapeDownArrow,shapeNone), colorWhite, 0, High, Offset=-15);
PlotShapes(IIf(Sell, shapeSmallCircle,shapeNone), colorWhite, 0, High, Offset= 28);

_SECTION_END();

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


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", colorRed,
styleDashed);
Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ), "Support Level", colorGreen,
styleDashed);
}
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) ;

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


/////////////////////////////////////////////////////////////////////////////////
///// Trailing Stop Module /////

P6=Param("Trailing Stop Risk",2.5,2,3.5,0.1);
P7=Param("Trailing Stop LookBack",14,5,25,1);
P8=Param("Trailing Stop PrevLow Switch",0,0,1,1);
PrevLow=IIf(P8==1, Ref(C,-TroughBars(C,5,1)) ,Null);
Plot(PrevLow,"",colorRed);

//Position sizing//
MyTotalPort = Param("MyTotalPort",1000000,10000,10000000,100000);
AcceptableRisk = Param("AcceptableRisk",0.5,0.1,3,0.1);
BarsFromStart = BarsSince(Cross(C,Ref(PK,-1))AND Ref(Color,-1)==colorRed) ;
InitialStopLoss =Ref( H - P6*ATR(P7),-BarsFromStart);
PositionSizing = 0.01*AcceptableRisk*MyTotalPort/( C - InitialStopLoss );

Plot(IIf( HHV(H - P6*ATR(P7),BarsFromStart+1) <C ,HHV(H - P6*ATR(P7),BarsFromStart+1),Null) ,"",colorCustom12,1);

PlotShapes(shapeDownArrow*Cross(Ref(HHV(H - P6*ATR(P7),BarsFromStart+1),-1),C),colorBlack,0,H,Offset=-43);

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



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

_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 )) ));

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

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),styleDots|styleThick);

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



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

Code to automatically identify pivots TRIANGLE

********************************** */
// -- 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("Pivot_Finder");
/* **********************************

Code to automatically identify pivots for STAR

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

// -- what will be our lookback range for the hh and ll?
farback=Param("How Far back to go",200,0,5000,10);
nBars = Param("Number of bars", 12, 5, 40);


// -- 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, shapeStar, shapeNone), colorBrightGreen, 0, H, 15);

PlotShapes(

IIf(aLPivs==1, shapeStar , shapeNone), colorCustom12, 0, L, -20);


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

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

messageboard = ParamToggle("Message Board","Show|Hide",0);
showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);
no=10;
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
s5d=IIf(avn==1,sup,res);

if (showsl == 0)
//{Plot(s5d,"Stop Loss",colorCustom14,styleDots);}
exitlong = Cross(s5d, H);
PlotShapes(exitlong * shapeDownArrow, colorBlack,0,H,-10);
exitshort = Cross(L, s5d);
PlotShapes(exitshort * shapeUpArrow, colorBlack,0,L,-15);

Buy = exitshort;
Sell = exitlong;
//Short = Sell;
//Cover = Buy;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
//Short = ExRem(Short, Cover);
//Cover = ExRem(Cover, Short);
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );

for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
sl = s5d;
tar1 = entry + (entry * .0056);
tar2 = entry + (entry * .0116);
tar3 = entry + (entry * .0216);

bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "SELL";
entry = C;
sl = s5d;
tar1 = entry - (entry * .0056);
tar2 = entry - (entry * .0116);
tar3 = entry - (entry * .0216);


bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, s5d[BarCount-1], Ref(s5d, -1));
sl = ssl[BarCount-1];

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);

Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorDarkRed, styleLine|styleLine, Null, Null, Offset);
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorGreen, styleLine|styleLine, Null, Null, Offset);

for (i=bars; i <BarCount;i++)
{
PlotText(""+sig+"@"+entry, BarCount+1,entry,Null,colorBlue);
PlotText("T1@"+tar1,BarCount+3,tar1,Null,Clr);PlotText("T2@"+tar2,BarCount+3,tar2,Null,Clr);PlotText("T3@"+tar3,BarCount+3,tar3,Null,Clr);

}


printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago");
printf("\n" + sig + " @ : " + entry + "\nStop Loss : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + "\nTarget_3 : " + tar3);
printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2));

if (messageboard == 0 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="BUY")
{
GfxSelectSolidBrush( colorBlue ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 290;

y = pxHeight;

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 163, x2, y , 7, 7 ) ;
GfxTextOut( ( " GAIN TRADE "),88,y-165);
GfxTextOut( (" "),27,y-160);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-140) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-120);
GfxTextOut( ("Trailing SL : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-100);
GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 88, y-22);;

}
//////////////////////////////////////////////////////////////////////////////////////////////////////////



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

_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",27,27,27,27);
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, colorBlack )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();
GraphXSpace=5;

//////////////////////////////////////////////////////////////////////////////
 
Last edited:

yasu222

Active Member
#5
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g,Hi %g,Lo %g, Close %g (%.1f%%)
Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
barcolor =IIf(C>O, ParamColor("Up candlestick", colorBrightGreen ), ParamColor("Down candlestick", colorOrange ));
Plot( C, "Close", barColor, 64);

BuyOffSet = 18;
SellOffset = 18;
RegLength = 5;
BuyATRPeriod = 2;
SellATRPeriod = BuyATRPeriod;
ATRMultiplier = 0.5;

G8 = HHV(H-ATRMultiplier*ATR(BuyATRPeriod),BuyOffset);
G9 = LLV(L+ATRMultiplier*ATR(SellATRPeriod),SellOffset) ;
ave=(G8+G9)/2;

Var1=(Open+Low+High+Close)/4;
Var2=EMA(EMA(Close, 2), 2);
Var3=EMA(EMA(Var2, 5), 5);
sup1=EMA(EMA(Var1,5),2);
sup2= LLV(sup1,13);
sup3= LLV(Low,60)*1.02;
res1= HHV(sup1,13);
res2= HHV(sup1,60);
res3= HHV(High,60)*0.98;

Plot(5, "",
IIf(sup1>Ref(sup1,-1),colorGreen,
IIf(sup2>Ref(sup2,-1),colorGrey50,
IIf(res1>Ref(res1,-1),colorBlue,
IIf(res2>Ref(res2,-1),colorYellow,
IIf(sup2=Ref(sup2,-1),colorRed,
IIf(res1=Ref(res1,-1),colorPink,
IIf(res2=Ref(res2,-1),colorLightBlue,
IIf(res3=Ref(res3,-1),colorBlue,colorWhite)))))))),
styleOwnScale|styleArea|styleNoLabel,-0.5, 350 );

nn=20;
mmm=120;
Ttt= ( H + L + 2 * C ) / 4;
CI= (Ttt -MA(Ttt,14)) / (0.015*StDev(Ttt,14));
CCCI=EMA(EMA(CI,3),3)+mmm;
Hh=HHV(H,nn);
Ll=LLV(L,nn);
MM=(Hh+Ll)/2;
CCCC=EMA(CCCI*(Hh-Ll)/(2*mmm)+Ll,3);
Plot(Hh,"Resistance",11,styleLine);
Plot(Ll,"Support",14,styleLine);
Plot(CCCC,"CNC",colorYellow,styleLine+4);

Buy = Cccc>Ref(Cccc,-1) AND ((Cccc>Ref(Cccc,-1) AND Ref(Cccc,-1)<Ref(Cccc,-2) AND Cccc<ave) OR Cross(Cccc,Ll) OR Cross(Cccc,G9));
Sell= Cccc<Ref(Cccc,-1) AND ((Cccc<Ref(Cccc,-1) AND Ref(Cccc,-1)>Ref(Cccc,-2) AND Cccc>ave) OR Cross(Hh,Cccc) OR Cross(G8,Cccc));
PlotShapes( IIf( Buy, shapeHollowUpArrow, shapeNone ), 10, layer = 0, yposition = L, offset = -15 );
PlotShapes( IIf( Sell, shapeHollowDownArrow, shapeNone ), 13, layer = 0, yposition = H, offset = -15 );

_SECTION_BEGIN("Volume");
Plot( Volume, "Volume", ParamColor("Color", colorLightGrey ), 2 | 32768 );
_SECTION_END();

_SECTION_BEGIN("Exploration");
pfrom = Param("Price From", 0, 0, 1000, 0.5 );
pto = Param("Price To", 1000, 0, 1000, 0.5 );
Minv = Param("Minimum Volume (K)", 500, 0, 1000, 50);
dd = Param("Decimal Digits", 1.2, 1, 1.7, 0.1 );

Filter = (Buy OR Sell) AND C>pfrom AND C<pto AND V>1000*Minv;
Color = IIf(Close>Open, colorGreen, colorRed);
bcolor = IIf(Buy, colorGreen, 1);
scolor = IIf(Sell, colorRed, 1);

AddColumn(Buy , "Buy" , 1.1, bcolor);
AddColumn(Sell , "Sell", 1.1, scolor);
AddColumn(O, "Open", dd, textColor = Color);
AddColumn(C, "Close", dd, textColor = Color);
AddColumn(Ll, "Support", dd, textColor = Color);
AddColumn(Hh, "Resistance", dd, textColor = Color);
AddColumn(V, "Volume", 1, textColor = Color);
AddTextColumn(FullName(),"Name");
_SECTION_END();
 

yasu222

Active Member
#6
_SECTION_BEGIN("C.com Peak");
//Chaloke.com Peak-Trough System + Auto ATR + Position sizing+Varible Sensitivity//
// Last Update 16 Oct 05 By Kook//

PctVlt=(ATR(14)/C)*100;//PercentVolatility

PK=IIf(PctVlt<0.5,Peak(Close,0.5,1),
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,Peak(Close,0.70,1),
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,Peak(Close,0.90,1),
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,Peak(Close,1.10,1),
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,Peak(Close,1.30,1),
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,Peak(Close,1.50,1),
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,Peak(Close,1.70,1),
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,Peak(Close,2.00,1),
Peak(Close,2.20,1) ))))))));

TGH=IIf(PctVlt<0.5,Trough(Close,0.5,1),
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,Trough(Close,0.75,1),
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,Trough(Close,1.00,1),
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,Trough(Close,1.25,1),
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,Trough(Close,1.50,1),
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,Trough(Close,1.75,1),
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,Trough(Close,2.00,1),
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,Trough(Close,2.25,1),
Trough(Close,2.50,1) ))))))));

Sens=IIf(PctVlt<0.5,0.5,
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,0.75,
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,1.00,
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,1.25,
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,1.50,
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,1.75,
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,2.00,
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,2.25,
2.50 ))))))));


Color=IIf(BarsSince(Cross(C,Ref(PK,-1)))<BarsSince(Cross(Ref(TGH,-1),C)),colorBrightGreen,colorRed);
Plot(C,"Chaloke.com Peak-Trough",Color,styleCandle);

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

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),styleDots|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|styleNoLin e|styleNoRescale|styleNoTitle);
Plot(DayH,"YH",colorTurquoise,styleDots|styleNoLin e|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|styleNo Line|styleNoRescale|styleNoTitle);
Plot(DayH2,"2DBH",colorTurquoise,styleDots|styleNo Line|styleNoRescale|styleNoTitle);
Plot(DayL3,"3DBL",colorTurquoise,styleDots|styleNo Line|styleNoRescale|styleNoTitle);
Plot(DayH3,"3DBH",colorTurquoise,styleDots|styleNo Line|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|styleNoResc ale|styleNoTitle);
Plot(R1, "R1",colorViolet,styleDots|styleNoLine|styleNoResc ale|styleNoTitle);
Plot(S1, "S1",colorViolet,styleDots|styleNoLine|styleNoResc ale|styleNoTitle);
Plot(R2, "R2",colorViolet,styleDots|styleNoLine|styleNoResc ale|styleNoTitle);
Plot(S2, "S2",colorViolet,styleDots|styleNoLine|styleNoResc ale|styleNoTitle);
Plot(R3, "R3",colorViolet,styleDots|styleNoLine|styleNoResc ale|styleNoTitle);
Plot(S3, "S3",colorViolet,styleDots|styleNoLine|styleNoResc ale|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|styleNo Rescale|styleNoTitle);
Plot(H4,"",colorRose,styleDots|styleNoLine|styleNo Rescale|styleNoTitle);
Plot(H3,"",colorRose,styleDots|styleNoLine|styleNo Rescale|styleNoTitle);
Plot(H2,"",colorRose,styleDots|styleNoLine|styleNo Rescale|styleNoTitle);
Plot(H1,"",colorRose,styleDots|styleNoLine|styleNo Rescale|styleNoTitle);
Plot(L1,"",colorRose,styleDots|styleNoLine|styleNo Rescale|styleNoTitle);
Plot(L2,"",colorRose,styleDots|styleNoLine|styleNo Rescale|styleNoTitle);
Plot(L3,"",colorRose,styleDots|styleNoLine|styleNo Rescale|styleNoTitle);
Plot(L4,"",colorRose,styleDots|styleNoLine|styleNo Rescale|styleNoTitle);
Plot(L5,"",colorRose,styleDots|styleNoLine|styleNo Rescale|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|styleNoR escale|styleNoTitle);
Plot(DayLline,"DayL",colorYellow,styleBar|styleNoR escale|styleNoTitle);
PlotText(" Day Hi " , LastValue(BarIndex())-(numbars/Hts), DayHlineI +0.05, colorYellow);
PlotText(" Day Lo " , LastValue(BarIndex())-(numbars/Hts), DayLlineI +0.05, colorYellow);
}

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

_SECTION_BEGIN("RI Auto Trading System");
acc = Param("Acceleration", 0.1, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.06, 0, 1, 0.001 );

Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorDarkGreen ), ParamStyle("Style", styleLine | styleLine, maskDefault | styleLine | styleLine ) );

Buy = Cross(Open, SAR(acc,accm));
Sell = Cross(SAR(acc,accm), Open );

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone), colorYellow, 0, Low, Offset=-15);
PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone), colorBrightGreen, 0, Low, Offset=-28);

PlotShapes(IIf(Sell, shapeDownArrow,shapeNone), colorWhite, 0, High, Offset=-15);
PlotShapes(IIf(Sell, shapeSmallCircle,shapeNone), colorRed, 0, High, Offset= 28);

AlertIf( Buy, "SOUND C:\\Windows\\Media\\Chord.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 2 );

_SECTION_END();

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


_SECTION_BEGIN("Break Outs");
//{Buy}
x1=5; x2=4; x3=3; x4=2; x5=1; x6=.5;
//{Lowest price stock <5}
AA=IIf(C<5,Cross(C,ValueWhen(Peak(H,x1,1) !=Ref(Peak(H,x1,1),-1),H,1)),
//{Price between 5 AND 20}
IIf(C>5 AND C<20,Cross(C,ValueWhen(Peak(H,x2,1) !=Ref(Peak(H,x2,1),-1),H,1)),
//{Price between 20 AND 70}
IIf(C>20 AND C<70,Cross(C,ValueWhen(Peak(H,x3,1) !=Ref(Peak(H,x3,1),-1),H,1)),
//{Price between 70 AND 150}
IIf(C>70 AND C<150,Cross(C,ValueWhen(Peak(H,x4,1) !=Ref(Peak(H,x4,1),-1),H,1)),
//{Price between 150 AND 300}
IIf(C>150 AND C<300,Cross(C,ValueWhen(Peak(H,x5,1) !=Ref(Peak(H,x5,1),-1),H,1)),
//{Price over 300}
Cross(C,ValueWhen(Peak(H,x6,1)!=Ref(Peak(H,x6,1),-1),H,1)))))));

//{Sell }
x1=5; x2=4; x3=3; x4=2; x5=1; x6=.5;
//{Lowest price stock <5}
BB=IIf(C<5,Cross(ValueWhen(Trough(L,x1,1) !=Ref(Trough(L,x1,1),-1),L,1),C),
//{Price between 5 AND 20}
IIf(C>5 AND C<20,Cross(ValueWhen(Trough(L,x2,1) !=Ref(Trough(L,x2,1),-1),L,1),C),
//{Price between 20 AND 70}
IIf(C>20 AND C<70,Cross(ValueWhen(Trough(L,x3,1) !=Ref(Trough(L,x3,1),-1),L,1),C),
//{Price between 70 AND 150}
IIf(C>70 AND C<150,Cross(ValueWhen(Trough(L,x4,1) !=Ref(Trough(L,x4,1),-1),L,1),C),
//{Price between 150 AND 300}
IIf(C>150 AND C<300,Cross(ValueWhen(Trough(L,x5,1) !=Ref(Trough(L,x5,1),-1),L,1),C),
//{Price over 300}
Cross(ValueWhen(Trough(L,x6,1)!=Ref(Trough(L,x6,1) ,-1),L,1),C))))));

Color=IIf(BarsSince(AA)>BarsSince(BB),colorRed,IIf (RSI()>70,colorCustom11,colorDarkGreen));

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

///// Trailing Stop Module /////

P6=Param("Trailing Stop Risk",2.5,2,3.5,0.1);
P7=Param("Trailing Stop LookBack",2,5,25,1);
P8=Param("Trailing Stop PrevLow Switch",0,0,1,1);
PrevLow=IIf(P8==1, Ref(C,-TroughBars(C,3,1)) ,Null);
//Plot(PrevLow,"",colorRed);

//Position sizing//
MyTotalPort = Param("MyTotalPort",1000000,10000,10000000,100000) ;
AcceptableRisk = Param("AcceptableRisk",0.5,0.1,3,0.1);
BarsFromStart = BarsSince(Cross(AA,BB)AND Ref(Color,-1)==colorRed) ;
InitialStopLoss =Ref( H - P6*ATR(P7),-BarsFromStart);
PositionSizing = 0.01*AcceptableRisk*MyTotalPort/( C - InitialStopLoss );

PPP = IIf( HHV(H - P6*ATR(P7),BarsFromStart+1) <C ,HHV(H - P6*ATR(P7),BarsFromStart+1),Null);
Plot( PPP ,"",colorCustom12);

_SECTION_END();

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

_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 )) ));

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

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

//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("Pivot_Finder");
/* **********************************

Code to automatically identify pivots

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

// -- what will be our lookback range for the hh and ll?
farback=Param("How Far back to go",100,0,100,10);
nBars = Param("Number of bars", 12, 5, 40);


// -- 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, shapeStar, shapeNone), colorBrightGreen, 0, H, 15);

PlotShapes(

IIf(aLPivs==1, shapeStar , shapeNone), colorCustom12, 0, L, -20);


//////////////////////////////////////////////////////////////////////////////
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 )) ));


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


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

Code to automatically identify pivots

********************************** */
// -- what will be our lookback range for the hh and ll?
farback=Param("How Far back to go",100,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("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",17,17,17,17);
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, colorBlack )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();
GraphXSpace=15;

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

yasu222

Active Member
#7
Fibinocy

_SECTION_BEGIN("NMA Swing");
SetBarsRequired(200,0);

GraphXSpace = 5;
SetChartOptions(0,chartShowArrows|chartShowDates);
k = Optimize("K",Param("K",1,0.25,5,0.25),0.25,5,0.25);
Per= Optimize("atr",Param("atr",2,3,20,1),3,20,1);
HACLOSE=(O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 1.0 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );

j=Haclose;

//=======================================================================================================================
//=========================Indicator==============================================================================================
f=ATR(10);

rfsctor = WMA(H-L, Per);

revers = k * rfsctor;

Trend = 1;
NW[0] = 0;


for(i = 1; i < BarCount; i++)
{
if(Trend[i-1] == 1)
{
if(j < NW[i-1])
{
Trend = -1;
NW = j + Revers;
}
else
{
Trend = 1;
if((j - Revers) > NW[i-1])
{
NW = j - Revers;
}
else
{
NW = NW[i-1];
}
}
}
if(Trend[i-1] == -1)
{
if(j > NW[i-1])
{
Trend = 1;
NW = j - Revers;
}
else
{
Trend = -1;
if((j + Revers) < NW[i-1])
{
NW = j + Revers;
}
else
{
NW = NW[i-1];
}
}
}
}

//===============system================

Plot(NW, "", IIf(Trend == 1, 27, 4), 4);
Buy=Cover=Cross(j,nw);
Sell=Short=Cross(nw,j);
SellPrice=ValueWhen(Sell,C,1);
BuyPrice=ValueWhen(Buy,C,1);
Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );
_SECTION_END();




_SECTION_BEGIN("J's SRI CHAKRA - PH: 9367151067");
//{J's SRI CHAKRA}
//{Buy}
x1=5; x2=4; x3=3; x4=2; x5=1; x6=.5;
//{Lowest price stock <5}
AA=IIf(C<5,Cross(C,ValueWhen(Peak(H,x1,1) !=Ref(Peak(H,x1,1),-1),H,1)),
//{Price between 5 AND 20}
IIf(C>5 AND C<20,Cross(C,ValueWhen(Peak(H,x2,1) !=Ref(Peak(H,x2,1),-1),H,1)),
//{Price between 20 AND 70}
IIf(C>20 AND C<70,Cross(C,ValueWhen(Peak(H,x3,1) !=Ref(Peak(H,x3,1),-1),H,1)),
//{Price between 70 AND 150}
IIf(C>70 AND C<150,Cross(C,ValueWhen(Peak(H,x4,1) !=Ref(Peak(H,x4,1),-1),H,1)),
//{Price between 150 AND 300}
IIf(C>150 AND C<300,Cross(C,ValueWhen(Peak(H,x5,1) !=Ref(Peak(H,x5,1),-1),H,1)),
//{Price over 300}
Cross(C,ValueWhen(Peak(H,x6,1)!=Ref(Peak(H,x6,1),-1),H,1)))))));

//{Sell }
x1=5; x2=4; x3=3; x4=2; x5=1; x6=.5;
//{Lowest price stock <5}
BB=IIf(C<5,Cross(ValueWhen(Trough(L,x1,1) !=Ref(Trough(L,x1,1),-1),L,1),C),
//{Price between 5 AND 20}
IIf(C>5 AND C<20,Cross(ValueWhen(Trough(L,x2,1) !=Ref(Trough(L,x2,1),-1),L,1),C),
//{Price between 20 AND 70}
IIf(C>20 AND C<70,Cross(ValueWhen(Trough(L,x3,1) !=Ref(Trough(L,x3,1),-1),L,1),C),
//{Price between 70 AND 150}
IIf(C>70 AND C<150,Cross(ValueWhen(Trough(L,x4,1) !=Ref(Trough(L,x4,1),-1),L,1),C),
//{Price between 150 AND 300}
IIf(C>150 AND C<300,Cross(ValueWhen(Trough(L,x5,1) !=Ref(Trough(L,x5,1),-1),L,1),C),
//{Price over 300}
Cross(ValueWhen(Trough(L,x6,1)!=Ref(Trough(L,x6,1),-1),L,1),C))))));

Color=IIf(BarsSince(AA)>BarsSince(BB),colorRed,IIf(RSI()>70,colorSeaGreen,colorDarkGreen));

///// Trailing Stop Module /////

P6=Param("Trailing Stop Risk",2.5,2,3.5,0.1);
P7=Param("Trailing Stop LookBack",14,5,25,1);
P8=Param("Trailing Stop PrevLow Switch",0,0,1,1);
PrevLow=IIf(P8==1, Ref(C,-TroughBars(C,5,1)) ,Null);
Plot(PrevLow,"",colorRed);

//Position sizing//
MyTotalPort = Param("MyTotalPort",1000000,10000,10000000,100000);
AcceptableRisk = Param("AcceptableRisk",0.5,0.1,3,0.1);
BarsFromStart = BarsSince(Cross(AA,BB)AND Ref(Color,-1)==colorRed) ;
InitialStopLoss =Ref( H - P6*ATR(P7),-BarsFromStart);
PositionSizing = 0.01*AcceptableRisk*MyTotalPort/( C - InitialStopLoss );

Plot(IIf( HHV(H - P6*ATR(P7),BarsFromStart+1) <C ,HHV(H - P6*ATR(P7),BarsFromStart+1),Null) ,"",colorGold,1);
Title=Name()+" "+Date()+" "+EncodeColor(colorWhite)+"J's SRI CHAKRA - Ph: 9367151067"+EncodeColor(colorCustom11)+" Vol="+NumToStr(Volume ,1.2)+
EncodeColor(colorYellow)+"\nO="+O+EncodeColor(colorCustom11)+"\nH="+H+"\nL="+L+"\nClose="+ C+""+"\nchange= "+NumToStr((Ref(C,-1)-Close) ,1.2) +
" ";

GraphXSpace=3;
_SECTION_END();

_SECTION_BEGIN("Background");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ParamColor("Outer panel",colorBlack)); // color of outer border
SetChartBkGradientFill( ParamColor("Inner panel upper",colorBlack),ParamColor("Inner panel lower",colorBlack));
tchoice=Param("Title Selection ",2,1,2,1);

Plot(C, "", IIf(O>=C, colorOrange, colorGreen), ParamStyle("Price Style",styleBar,maskPrice));
//////////////////////////////////////////////////////////////////
_SECTION_BEGIN("Fib Retracements");
fibs = ParamToggle("Plot Fibs","Off|On",1);
pctH = Param ("Pivot Hi %", 0.325,0.001,2.0,0.002);
HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
pctL = Param ("Pivot Lo %", 0.325,0.001,2.0,0.002);
LoLB = Param ("Lo LookBack",1,1,BarCount-1,1);
Back = Param ("Extend Left = 2",1,1,500,1);
Fwd = Param("Plot Forward", 0, 0, 500, 1);
text = ParamToggle("Plot Text","Off|On",1);
hts = Param ("Text Shift", -33.5,-50,50,0.10);
style =ParamStyle("Line Style",styleLine,styleNoLabel);
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==1)
{
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);
}
_SECTION_END();
//////////////////////////////////////////////////////////////////
if (tchoice==1 )
{
_N(Title = EncodeColor(colorWhite)+StrFormat(" {{NAME}} - {{INTERVAL}} {{DATE}} Open: %g, High: %g, Low: %g, Close: %g {{VALUES}}",O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
}
//////////////////////////////////////////////////////////////////
if (tchoice==2 )
{
Title = EncodeColor(colorWhite)+ Date() + " Tick = " + EncodeColor(5) + Interval()+
EncodeColor(colorWhite) + " Open = " + EncodeColor(colorWhite) + O +
EncodeColor(colorWhite) + " High = " + EncodeColor(5) + H +
EncodeColor(colorWhite) + " Low = " + EncodeColor(colorRed) + L +
EncodeColor(colorWhite) + " Close = " + EncodeColor(colorWhite) + C + "\n" +
EncodeColor( colorWhite) +"_______________"+"\n"+
EncodeColor( colorWhite) + "424% = " + EncodeColor(25)+ e424 + " " +"\n"+
EncodeColor( colorWhite) + "262% = " + EncodeColor(47)+ e262 + " " +"\n"+
EncodeColor( colorWhite) + "200% = " + EncodeColor(47)+ e200 + " " +"\n"+
EncodeColor( colorWhite) + "162% = " + EncodeColor(47)+ e162 + " " +"\n"+
EncodeColor( colorWhite) + "127% = " + EncodeColor(47)+ e127 + " " +"\n"+
EncodeColor( colorYellow) + " Res = " + EncodeColor(32)+ p100 + " " +"\n"+
EncodeColor( colorWhite) + " 78% = " + EncodeColor(42)+ r786 + " " +"\n"+
EncodeColor( colorWhite) + " 62% = " + EncodeColor(43)+ r618 + " " +"\n"+
EncodeColor( colorWhite) + " 50% = " + EncodeColor(41)+ r050 + " " +"\n"+
EncodeColor( colorWhite) + " 38% = " + EncodeColor(44)+ r382 + " " +"\n"+
EncodeColor( colorWhite) + " 23% = " + EncodeColor(45)+ r236+ " " +"\n"+
EncodeColor( colorYellow) + " Sup = " + EncodeColor(34)+ p00 + " " ;
}
GraphXSpace=5;




R=3;//Marking circle radius
m=0.015*(HHV(H,159)-LLV(L,159));//scaling factor
x=Cum(1);
per = 2.5;//Sensitivity Calibration
pR = PeakBars( H, per, 1 ) == 0;//Peak condition
x01= LastValue(ValueWhen( pR, x, 1 ));
x02=LastValue(ValueWhen( pR, x, 2 ));
x03=LastValue(ValueWhen( pR, x, 3 ));
y01 = LastValue(ValueWhen( pR, H, 1 ) );
y02=LastValue(ValueWhen( pR, H, 2 ) );
y03 = LastValue( ValueWhen( pR, H, 3 ));
Plot(C,"",2,64);
y0=y01;x0=x01;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
y0=y02;x0=x02;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
y0=y03;x0=x03;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
TpR = TroughBars( L, per, 1 ) == 0;//Trough condition
x01T= LastValue(ValueWhen( TpR, x, 1 ));
x02T=LastValue(ValueWhen( TpR, x, 2 ));
x03T=LastValue(ValueWhen( TpR, x, 3 ));
y01T = LastValue(ValueWhen( TpR, L, 1 ) );
y02T=LastValue(ValueWhen( TpR, L, 2 ) );
y03T = LastValue( ValueWhen( TpR, L, 3 ));
y0T=y01T;x0T=x01T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(Y,"",5,1);Plot(Y1,"",5,1);
y0T=y02T;x0T=x02T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(y,"",5,1);Plot(y1,"",5,1);
y0T=y03T;x0T=x03T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(y,"",5,1);Plot(y1,"",5,1);





R=2;//Marking circle radius
m=0.015*(HHV(H,159)-LLV(L,159));//scaling factor
x=Cum(1);
per = 1.5;//Sensitivity Calibration
pR = PeakBars( H, per, 1 ) == 0;//Peak condition
x01= LastValue(ValueWhen( pR, x, 1 ));
x02=LastValue(ValueWhen( pR, x, 2 ));
x03=LastValue(ValueWhen( pR, x, 3 ));
y01 = LastValue(ValueWhen( pR, H, 1 ) );
y02=LastValue(ValueWhen( pR, H, 2 ) );
y03 = LastValue( ValueWhen( pR, H, 3 ));
Plot(C,"",2,64);
y0=y01;x0=x01;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
y0=y02;x0=x02;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
y0=y03;x0=x03;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
TpR = TroughBars( L, per, 1 ) == 0;//Trough condition
x01T= LastValue(ValueWhen( TpR, x, 1 ));
x02T=LastValue(ValueWhen( TpR, x, 2 ));
x03T=LastValue(ValueWhen( TpR, x, 3 ));
y01T = LastValue(ValueWhen( TpR, L, 1 ) );
y02T=LastValue(ValueWhen( TpR, L, 2 ) );
y03T = LastValue( ValueWhen( TpR, L, 3 ));
y0T=y01T;x0T=x01T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(Y,"",5,1);Plot(Y1,"",5,1);
y0T=y02T;x0T=x02T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(y,"",5,1);Plot(y1,"",5,1);
y0T=y03T;x0T=x03T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(y,"",5,1);Plot(y1,"",5,1);




R=1;//Marking circle radius
m=0.015*(HHV(H,159)-LLV(L,159));//scaling factor
x=Cum(1);
per = 0.325;//Sensitivity Calibration
pR = PeakBars( H, per, 1 ) == 0;//Peak condition
x01= LastValue(ValueWhen( pR, x, 1 ));
x02=LastValue(ValueWhen( pR, x, 2 ));
x03=LastValue(ValueWhen( pR, x, 3 ));
y01 = LastValue(ValueWhen( pR, H, 1 ) );
y02=LastValue(ValueWhen( pR, H, 2 ) );
y03 = LastValue( ValueWhen( pR, H, 3 ));
Plot(C,"",2,64);
y0=y01;x0=x01;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
y0=y02;x0=x02;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
y0=y03;x0=x03;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
TpR = TroughBars( L, per, 1 ) == 0;//Trough condition
x01T= LastValue(ValueWhen( TpR, x, 1 ));
x02T=LastValue(ValueWhen( TpR, x, 2 ));
x03T=LastValue(ValueWhen( TpR, x, 3 ));
y01T = LastValue(ValueWhen( TpR, L, 1 ) );
y02T=LastValue(ValueWhen( TpR, L, 2 ) );
y03T = LastValue( ValueWhen( TpR, L, 3 ));
y0T=y01T;x0T=x01T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(Y,"",5,1);Plot(Y1,"",5,1);
y0T=y02T;x0T=x02T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(y,"",5,1);Plot(y1,"",5,1);
y0T=y03T;x0T=x03T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(y,"",5,1);Plot(y1,"",5,1);





_SECTION_BEGIN("Elder Impulse Indicator");
/**************************************************************************
Name : Elder Impulse Indicator
Coded by : Lal
Date : 28.10.2005
Note : Please refer to Elder's "Come Into my Trading Room"
for full details
******************************************************************************/


// User-defined parameter for EMA periods
EMA_prds = Param("EMA_periods", 6, 1, 30, 1);


// Compute EMA and MACD Histogram
DayEMA = EMA(Close, EMA_prds);
Histogram = MACD() - Signal();

// Determine if we have an Impulse UP, DOWN or None
Impulse_Up = DayEMA > Ref(DayEMA, -1) AND Histogram > Ref(Histogram, -1);
Impulse_Down = DayEMA < Ref(DayEMA, -1) AND Histogram < Ref(Histogram, -1);
Impulse_None = (NOT Impulse_UP) AND (NOT Impulse_Down);

// Compute Weekly MACD and determine whether rising or falling
// Note: uses "non-standard" parameters!
TimeFrameSet(inWeekly);
MACD_val = MACD(5, 8);
Signal_val = Signal(5, 8, 5);
Hist_in_w = MACD_val - Signal_val;

wh_rising = Hist_in_w > Ref(Hist_in_w, -1);
wh_falling = Hist_in_w < Ref(Hist_in_w, -1);

TimeFrameRestore();

// Now get Monthly MACD Histogram....
TimeFrameSet(inMonthly);
MACD_val = MACD(5, 8);
Signal_val = Signal(5, 8, 5);
Hist_in_m = MACD_val - Signal_val;

mh_rising = Hist_in_m > Ref(Hist_in_m, -1);
mh_falling = Hist_in_m < Ref(Hist_in_m, -1);

TimeFrameRestore();

wh_rising = TimeFrameExpand( wh_rising, inWeekly );
wh_falling = TimeFrameExpand( wh_falling, inWeekly );
mh_rising = TimeFrameExpand(mh_rising, inMonthly);
mh_falling = TimeFrameExpand(mh_falling, inMonthly);

kol = IIf( wh_rising, colorGreen, IIf(wh_falling, colorRed, colorLightGrey));
mkol = IIf( mh_rising, colorCustom9, IIf(mh_falling, colorOrange, colorLightGrey));

// Plot them all!
Plot(3, "R", kol, styleOwnScale|styleArea|styleNoLabel, -12, 156); // Weekly trend
Plot(6, "R", mkol, styleOwnScale|styleArea|styleNoLabel, -0.5, 150); // Monthly Trend
_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,1,30,1);
nBars = Param("Number of bars", 6, 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 = "";

MinBars = 100;
MinBarsOK = IIf(BarCount >= MinBars, True, False);
if (MinBarsOK) { ;

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=-10);
PlotShapes(IIf(aLPivs==1, shapeSmallUpTriangle , shapeNone), colorCustom11, 0, Low, Offset=-10);



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


_SECTION_END();


_SECTION_BEGIN("SAR");
acc = Param("Acceleration", 0.05, 0, 3, 0.001 );
accm = Param("Max. acceleration", 0.9, 0, 3, 0.001 );
Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorYellow ), ParamStyle("Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );
_SECTION_END();




_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

//------------------------------------------------------------------------------
//
// Formula Name: Andrews Pitchfork
// Author/Uploader: Bob Johnson
// E-mail: [email protected]
// Date/Time Added: 2005-07-22 18:46:17
// Origin:
// Keywords: Andrews Andrew's Pitchfork
// Level: semi-advanced
// Flags: indicator
// Formula URL: http://www.amibroker.com/library/formula.php?id=522
// Details URL: AmiBroker - AFL Library
//
//------------------------------------------------------------------------------
//
// Plots Andrews Pitchfork using peak()/trough() to identify 3 pivot points to
// use in determining the pitchfork. Accepts params for pct threshhold for
// peak and trough, number of bars to look back, i.e. how many bars must have
// past before the accepting a peak or trough pivot point and a shift param to
// move the pitchfork up/down from its original plot. Calculates the pitchfork
// as exponential curves so they plot as straight lines on a semilog chart.
//
//------------------------------------------------------------------------------

// Andrews Pitchfork V.3
// Use Peak() & Trough() to get peaks & troughs.
// This version deals with adjacent peaks and adjacent
// troughs, i.e. two peaks without an intervening trough or vice-versa.
// It goes backwards from the selected bar until it has a set of
// peak,trough,peak or trough,peak,trough points to use for calulating
// the pitchfork. When 2 or more peaks or 2 or more troughs are adjacent
// it only uses the last one, i.e. the rightmost one, of the series.
//
// This version plots the trendlines as exponential curves that plot as
// straight lines on an semilog chart.
//
// 07/22/2005 By Bob Johnson with invaluable help from Graham Kavanagh getting
// me pointed in the right direction on the exponential equation logic.

SetBarsRequired( 999999,999999);

bi=BarIndex();
sbi=SelectedValue(bi);

// How many bars to wait before believing the pivot.
Lookbk=Param("LookBack",5,1,200,1);
// Pct threshhold for peak() & trough()
Zigpct1=Param("Zigpct1",3.0,1.0,30.0,0.1,0);
// How many bars to extend the pitchfork past the selected bar.
xtsn=Param("Extension",62,1,200,1);
// Shift to move pitchfork up/down from original position one penny at time.
shift=Param("Shift",0,-2000,2000,0.01);

// The peak/trough lines will be used to determine the y coordinates
// of the pitchfork's 3 determining points.

pline1=Peak(H,Zigpct1,1);
tline1=Trough(L,Zigpct1,1);

// Identify the pivots
pzag1=pline1 != Ref(pline1,-1);
tzag1=tline1 != Ref(tline1,-1);

// Get the x,y coordinates of the pivots skipping adjacent
// peaks and troughs. Go backwards from the current bar minus the lookback.

// These will hold the x,y coordinates of the pivot points in arrays at the
// sbi index.

zagx1=0;
zagx2=0;
zagx3=0;
zagy1=0;
zagy2=0;
zagy3=0;

for ( i = sbi - Lookbk, zagfnd = 0, pzagfnd = 0, tzagfnd = 0 ; i >= 0 && zagfnd <= 3; i-- ) {
if ( pzag1 || tzag1 ) {
if ( pzag1 && NOT pzagfnd ) {
zagfnd=zagfnd+1;
pzagfnd=1;
tzagfnd=0;
if ( zagfnd == 1 ) {
zagx1[sbi]=i;
zagy1[sbi]=pline1;
} else if (zagfnd == 2) {
zagx2[sbi]=i;
zagy2[sbi]=pline1;
} else if (zagfnd == 3) {
zagx3[sbi]=i;
zagy3[sbi]=pline1;
}
} else if ( tzag1 && NOT tzagfnd ) {
zagfnd=zagfnd+1;
tzagfnd=1;
pzagfnd=0;
if ( zagfnd == 1 ) {
zagx1[sbi]=i;
zagy1[sbi]=tline1;
} else if (zagfnd == 2) {
zagx2[sbi]=i;
zagy2[sbi]=tline1;
} else if (zagfnd == 3) {
zagx3[sbi]=i;
zagy3[sbi]=tline1;
}
}
}
}

// Calculate the Pitchfork itself

tslope=0;
tline=0;
midx=0;
midy=0;
Handle=0;
Handle1=0;
Top=0;
top1=0;
Bot=0;
bot1=0;

// Midpoint between the rightmost 2 pivots and the slope from the
// leftmost pivot to the midpoint.

Midx[sbi]=zagx2[sbi] + (zagx1[sbi]-zagx2[sbi]) / 2;
Midy[sbi]=exp( log(zagy1[sbi]) - ( log(zagy1[sbi])-log(zagy2[sbi]) ) / 2);
echng=(log(midy[sbi])-log(zagy3[sbi]))/(midx[sbi]-zagx3[sbi]);

tslope[sbi]=(midy[sbi]-zagy3[sbi]) / (midx[sbi]-zagx3[sbi]);

// Handle first

for ( j=zagx3[sbi],n=0 ; j < Min(sbi+xtsn,BarCount) ; j++,n++ ) {
Handle[j]=exp(log(zagy3[sbi]) + n*echng) + shift;
}

// High & low median lines.

if ( zagy2[sbi] > zagy1[sbi] ) { // Which one is top?
for ( j=zagx2[sbi],n=0 ; j < Min(sbi+xtsn,BarCount) ; j++,n++ ) {
top[j]=exp(log(zagy2[sbi]) + n*echng) + shift;
}
for ( j=zagx1[sbi],n=0 ; j < Min(sbi+xtsn,BarCount) ; j++,n++ ) {
bot[j]=exp(log(zagy1[sbi]) + n*echng) + shift;
}
} else {
for ( j=zagx2[sbi],n=0 ; j < Min(sbi+xtsn,BarCount) ; j++,n++ ) {
bot[j]=exp(log(zagy2[sbi]) + n*echng) + shift;
}
bot1 = exp( LineArray( zagx2[sbi], ln(zagy2[sbi]), Min(sbi + xtsn,BarCount), ln(zagy2[sbi] + n*tslope[sbi] + shift), 1, 1 ) );
for ( j=zagx1[sbi],n=0 ; j < Min(sbi+xtsn,BarCount) ; j++,n++ ) {
top[j]=exp(log(zagy1[sbi]) + n*echng) + shift;
}
}

// I'm using a white background, adjust to your own preferred background color
Hcolor=IIf(Handle==0,colorWhite,IIf(Ref(handle,-1)== 0 AND handle != 0, colorWhite,colorRed));
Tcolor=IIf(Top==0,colorWhite,IIf(Ref(top,-1)== 0 AND top != 0, colorWhite,colorRed));
Bcolor=IIf(Bot==0,colorWhite,IIf(Ref(bot,-1)== 0 AND bot != 0, colorWhite,colorRed));
Plot(Handle,"\nAndrews: pct="+Zigpct1+" lookback="+lookbk+" shift="+shift+" Handle",Hcolor,styleLine+styleDashed+styleNoRescale);
Plot(Top,"MLH",Tcolor,styleLine+styleDashed+styleNoRescale);
Plot(Bot,"MLL",Bcolor,styleLine+styleDashed+styleNoRescale);



_SECTION_BEGIN("ZIG - Zig");
P = ParamField( "Price field" );
change = Param("% change",5,0.1,25,0.1);
Plot( Zig(P, change), _DEFAULT_NAME(), ParamColor( "Color", colorCustom9 ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("ZIG - Zig1");
P = ParamField( "Price field" );
change = Param("% change",11,0.1,25,0.1);
Plot( Zig(P, change), _DEFAULT_NAME(), ParamColor( "Color", colorCustom12 ), ParamStyle("Style") );
_SECTION_END();



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

Name : Logic All In One for Intraday
Date : 10th JAN 2009
Author : j
E-Mail ID : j

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



EnableTextOutput(False);

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
//Title_X = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
Title_X = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} - "+ EncodeColor(colorWhite)+"Open = "+ EncodeColor(colorWhite) +"%g "+ EncodeColor(colorBrightGreen)+"High = "+ EncodeColor(colorBrightGreen) +"%g - "+ EncodeColor(colorRed)+"Low = "+ EncodeColor(colorRed) +"%g "+ EncodeColor(colorWhite) +"Close = "+ EncodeColor(colorWhite) +" %g ", O, H, L, C, SelectedValue( ROC( C, 1 ) ) );

SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack), ParamColor("Title", colorBlack));
SetChartBkColor(ParamColor("Background", colorBlack));
_SECTION_END();

//Indicators

_SECTION_BEGIN("Indicators");
RSI_Periods = Param("RSI Periods", 2, 1, 100, 1);
MA_Periods = Param("Periods for MAV", 50, 1, 200, 1);
Daily_Trend_MA_Pds = Param("Periods for Trend EMA", 6, 1, 100, 1);
_SECTION_END();

//Indicators

_SECTION_BEGIN("Indicators");
RSI_Periods = Param("RSI Periods", 2, 1, 100, 1);
MA_Periods = Param("Periods for MAV", 50, 1, 200, 1);
Daily_Trend_MA_Pds = Param("Periods for Trend EMA", 6, 1, 100, 1);
_SECTION_END();

SetBarsRequired(100000, 100000);

// Find nearest UP and DOWN bar before current bar
Up_Day = Close > Open;
Down_Day = Close < Open;
Reference_Low = ValueWhen(Up_Day, L, 1);
Reference_High = ValueWhen(Down_Day, H, 1);
Buy_Condition = C > O AND C > Reference_High;
Sell_Condition = C < O AND C < Reference_Low;
a= Buy_Condition;
b= Sell_Condition;
state=IIf(BarsSince(a)<BarsSince(b),1,0);
s=state>Ref(state,-1);
ss=state<Ref(state,-1);
sss=state==Ref(state,-1);
col=IIf(state == 1 ,51,IIf(state ==0,4,1));
Buy_Views = WriteIf(s,EncodeColor(colorWhite)+"EXIT ALL SHORT POSITIONS\nAND TRADE LONG WITH STOPLOSS="+EncodeColor(colorBrightGreen)+WriteVal(L,1.2)+",","");
Sell_Views = WriteIf(ss,EncodeColor(colorYellow)+"EXIT ALL LONG POSITIONS \nAND TRADE SHORT WITH STOPLOSS="+EncodeColor(colorRed)+WriteVal(H,1.2)+",","");


// RSI and Vol ratio calculation
RSI_Value = RSI(RSI_Periods);
MAV_Value = V/EMA(V, MA_Periods);

//Percentage change

s=C-Ref(C,-1);
t=(s/Ref(C,-1))*100;
Percentage= t;

//Percentage Change in Volume

w = V -Ref(V,-1);
x = (w/Ref(V,-1))*100;
Volume_Ratio = x;
//Volume_Ratio = V/EMA(V,50);
//Conditions

Condition1 = Percentage > 0.5 AND Volume_Ratio > 1.5;
Condition2 = Percentage > 1 AND Volume_Ratio < -1.5;
Condition3 = Percentage < 0 AND Volume_Ratio > -1.5;
Condition4 = Percentage < 1 AND Volume_Ratio < 1.5;
Condition5 = IIf(NOT Condition1 AND NOT Condition2 AND NOT Condition3 AND NOT Condition4, True,False);


Fresh_Buying = WriteIf(Condition1,"Fresh Buying", "");
Short_Covering = WriteIf(Condition2,"Short Covering", "");
Fresh_Short_Building = WriteIf(Condition3,"Fresh Short Building", "");
Possible_Bottom = WriteIf(Condition4,"Possible Bottom OR Top", "");
No_Major_Move = WriteIf(Condition5, "No_Major_Move","");

//interpretation output

EnableTextOutput(True);
"\nSell Below: " + WriteVal(ValueWhen(Up_Day, L, 1), 1.2);
"Buy Above : " + WriteVal(Reference_High, 1.2);
"";
"Current RSI Value: " + WriteVal(RSI_Value, 1.2);
"Current Vol. Ratio: " + WriteVal(MAV_Value, 1.2);
"";
"Fresh Buying: " + WriteIf(Condition1,"Fresh Buying","");

EnableTextOutput(False);

Filter = Buy_Condition OR Sell_Condition;

// Trading System
PositionSize = BuyPrice * 1;
Buy = Buy_condition;
Sell = Sell_condition;
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );

// Experimental Code BEGIN
Is_Last_Bar = BarIndex()+1 == BarCount;
printf("Last Bar: %g\n", Is_Last_Bar);
Buy_Alert = Buy AND Is_Last_Bar;
Sell_Alert = Sell AND Is_Last_Bar;
Buy_Alert_Text = WriteIf(Buy_Alert, "BUY WARNING!!!", "");
Sell_Alert_Text = WriteIf(Sell_Alert, "SELL WARNING!!!", "");
Buy_Alert_Text1 = WriteIf(Buy_Alert, "BUY", "");
Sell_Alert_Text1 = WriteIf(Sell_Alert, "SELL", "");
LastbarsignalCol = IIf(Buy_Alert, colorGreen, IIf(Sell_Alert, colorRed, colorLightGrey));


//Buy & Sell Arrows Signal
PlotShapes(shapeCircle * Buy_Alert, colorBrightGreen, 0, L, -15);
PlotShapes(shapeCircle * Sell_Alert, colorRed, 0, H, 15);




// Check if previous day's close is above its 6-day EMA
DailyClose = TimeFrameCompress(Close, inDaily);
DailyEMA = EMA( DailyClose, Daily_Trend_MA_Pds);
DailyClose = TimeFrameExpand(DailyClose, inDaily, expandFirst);
DailyEma = TimeFrameExpand(DailyEMA, inDaily, expandFirst);

// Trend detection based on 6EMA for Daily
Daily_Trend_UP = DailyClose > DailyEMA;
Daily_Trend_DOWN = DailyClose < DailyEMA;
Trend_UP_Text = WriteIf(Daily_Trend_UP, "Daily Trend UP", "");
Trend_DOWN_Text = WriteIf(Daily_Trend_DOWN, "Daily Trend DOWN", "");
Trend_Neutral_Text = WriteIf(NOT Daily_Trend_DOWN AND NOT Daily_Trend_UP, "Neutral", "");
TrendCol = IIf(Daily_Trend_UP, colorGreen, IIf(Daily_Trend_DOWN, colorRed, colorLightGrey));


/** Debug BEGIN */
printf("\nDaily Close: %g ", DailyClose);
printf("\nDaily Trend: %g", (DailyEMA));
/* Debug END ****/

//Inerpretation
Title = Title_X + "\n" +

EncodeColor(colorWhite) + "\nRSI(" + WriteVal(RSI_Periods, 1) + ") = " +
EncodeColor(colorBrightGreen) + WriteVal(RSI_Value, 1.2) + "\n\n" +
EncodeColor(colorRed) + Trend_Down_Text + EncodeColor(colorBrightGreen) + Trend_Up_Text +
EncodeColor(colorWhite) + Trend_Neutral_Text + "\n" +
EncodeColor(colorRed) + Sell_Alert_Text + EncodeColor(colorBrightGreen) + Buy_Alert_Text + "\n" +
EncodeColor(colorRed) + Fresh_Short_Building + EncodeColor(colorBrightGreen) + Fresh_Buying + EncodeColor(colorGreen) + Short_Covering + EncodeColor(colorDarkOliveGreen) + Possible_Bottom +"\n" +
EncodeColor(colorBrightGreen)+ "Buy Above = " + WriteVal(Reference_High, 1.2)+ "\n" +
EncodeColor(colorCustom5) + "Sell Below = " + WriteVal(ValueWhen(Up_Day, L, 1), 1.2) + "\n\n" +
//EncodeColor(colorYellow) + "Trend value: " + WriteVal(DailyEMA,1) +"\n"+
EncodeColor(colorBlue)+ Buy_Views + EncodeColor(colorOrange)+ Sell_Views;


//M J Povit Point

DayH = TimeFrameGetPrice("H", inDaily, -1); // yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1); // low
DayC = TimeFrameGetPrice("C", inDaily, -1); // close
DayO = TimeFrameGetPrice("O", inDaily); // current day open
Dayz = TimeFrameGetPrice("C", inDaily, -6); // six days close
if ( True )
{
PP = (Dayc + Dayc -6 )/2;
R1 = Dayc + (DayH - DayL)/2;
S1 = Dayc - (DayH - DayL)/2;
R2 = Dayc + (DayH - DayL);
S2 = Dayc - (DayH - DayL);
}
Plot(pp, "PP",colorCustom12,styleDots+styleNoLine);
Plot(R1, "R1",colorOrange,styleDots+styleNoLine);
Plot(S1, "S1",colorCustom9,styleDots+styleNoLine);
Plot(R2, "R2",colorRed,styleDots+styleNoLine);
Plot(S2, "S2",colorBlue,styleDots+styleNoLine);


//Average, Volitility & Percentage Scale.
av3=V/EMA(V,50);
V1= MA(V,50);
r = RSI(2);
s=C-Ref(C,-1);
t=(s/Ref(C,-1))*100;
p=H-L;
q=(p/Ref(C,-1))*100;

//Explore Options

Filter = 1; /* all symbols and quotes accepted */
//filer = Buy OR Sell ;
AddColumn(Open,"OPEN",1);
AddColumn(High,"HIGH",1);
AddColumn(Low,"LOW",1);
AddColumn(Close,"CLOSE",1);
AddColumn(t,"Per",1.2);
AddColumn(V,"VOLUME",1);
AddColumn(V1,"AGV VOLUME",1);
AddColumn(av3,"RATIO50",1.2);
AddColumn(r,"RSI",2);
AddTextColumn(WriteVal(Reference_High, 1.2),"BUY ABOVE",colorWhite,colorGreen);
AddTextColumn(WriteVal(ValueWhen(Up_Day, L, 1), 1.2),"SELL BELOW",colorWhite,colorRed);
AddTextColumn(Trend_Down_Text + Trend_Up_Text,"DAILY TREND",1,colorWhite,TrendCol);
AddTextColumn(Buy_Alert_Text + Sell_Alert_Text,"LAST BAR SIGNAL",1,colorWhite,Lastbarsignalcol);
 

yasu222

Active Member
#9
// TRADING THE MACD Ver 1.0 by Karthik Marar.

_SECTION_BEGIN("MACD");
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
r4 = Param( "Wk slow", 17, 2, 200, 1 );
r5 = Param( "Wk fast", 8, 2, 200, 1 );
m1=MACD(r1,r2);
s1=Signal(r1,r2,r3);
GraphXSpace =20;

mycolor=IIf(m1<0 AND m1>s1, 51,IIf(m1>0 AND m1>s1,colorLime,IIf(m1>0 AND m1<s1,colorOrange,colorRed)));
Plot( m1, StrFormat(_SECTION_NAME()+"(%g,%g)", r1, r2), mycolor,ParamStyle("MACD style") );
Plot( s1 ,"Signal" + _PARAM_VALUES(), ParamColor("Signal color", colorBlue ), ParamStyle("Signal style") );
histcolor = IIf((m1-s1)-Ref((m1-s1),-1)> 0, colorLime, colorRed );

TimeFrameSet( inDaily );// weekly
m1w=MACD(r4,r5);
s1w=Signal(r4,r5,r3);
kp=m1w-s1w;
kph=Ref(kp,-1);
TimeFrameRestore();

kw=TimeFrameExpand( kp, inDaily ); // expand for display
khw=TimeFrameExpand( kph, inDaily ); // expand for display
mw=TimeFrameExpand( m1w, inDaily ); // expand for display
sw=TimeFrameExpand( s1w, inDaily ); // expand for display

hcolor=IIf(mw<0 AND mw>sw, 51,IIf(mw>0 AND mw>sw,colorLime,IIf(mw>0 AND mw<sw,colorOrange,colorRed)));
gcolor=IIf(kw>khw,IIf(kw>0,colorDarkYellow,colorYellow),IIf(kw>0,colorSkyblue,colorBlue));

Plot( 2,"Wkly MACD ribbon",hcolor,styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
Plot( 2,"Ribbon",gcolor,styleOwnScale|styleArea|styleNoLabel, -0.4, 40,-0.6 );

Plot( m1-s1, "MACD Histogram", mycolor, styleHistogram | styleThick| styleOwnScale );

_SECTION_END();

_SECTION_BEGIN("Signals");
//Zero crossover up

j1=Cross(m1,0);
PlotShapes(IIf(j1,shapeDigit1 ,Null),colorPaleGreen,0,Min(0,0),Min(0,0));
PlotShapes(IIf(j1,shapeUpArrow,Null),colorGreen,0,Min(0,0),-10);

// crossover above zero

j2=Cross(m1,s1) AND m1>0;
PlotShapes(IIf(j2,shapeDigit2 ,Null),colorYellow,0,0,0);
PlotShapes(IIf(j2,shapeUpArrow,Null),colorGreen,0,0,-10);

//Zero crossover down

j3=Cross(s1,m1) AND m1>0;
PlotShapes(IIf(j3,shapeDigit3 ,Null),colorOrange,0,Min(0,0),0);
PlotShapes(IIf(j3,shapeDownArrow,Null),colorOrange,0,Min(0,0),-10);

// crossover below zero

j4=Cross(0,m1);
PlotShapes(IIf(j4,shapeDigit4 ,Null),colorRed,0,0,0);
PlotShapes(IIf(j4,shapeDownArrow,Null),colorRed,0,0,-10);

// Histogram peak and troughs
pt=m1-s1;
Tp = Ref(pT,-1) == HHV(pT,3);
Vl = Ref(pT,-1)==LLV(pT,3);
PlotShapes(IIf(Vl AND m1>s1 ,shapeSmallCircle+ shapePositionAbove,shapeNone),IIf(m1<0 ,colorYellow,colorLime),0,0,0);
PlotShapes(IIf(Tp AND m1<s1 ,shapeSmallCircle+ shapePositionAbove,shapeNone),colorRed,0,0,0);

//Zeroline reject bearish
zd=BarsSince(j1);
zlrd1=(zd<6 )AND j4;
PlotShapes(IIf(zlrd1,shapeStar+ shapePositionAbove,shapeNone),colorDarkRed,0,0,20);

//hooks bearish
Hu=BarsSince(j2);
Hu1=(Hu<6)AND j3;
PlotShapes(IIf(Hu1,shapeStar+ shapePositionAbove,shapeNone),colorRed,0,0,20);

//Zeroline reject Bullish
zu=BarsSince(j4);
zlru=zu<6 AND j1;
PlotShapes(IIf(zlru,shapeStar+ shapePositionAbove,shapeNone),colorPink,0,0,20);

//Hook Bullish
Hd=BarsSince(j3);
Hd1=Hd<6 AND j2;
PlotShapes(IIf(Hd1,shapeStar+ shapePositionAbove,shapeNone),colorLime,0,0,20);

//ADX related calculations
plus=EMA(PDI(14),3)>Ref(EMA(PDI(14),3),-5);
ap=EMA(ADX(14),3)>Ref(EMA(ADX(14),3),-5);
Minus=EMA(MDI(14),3)>Ref(EMA(MDI(14),3),-5);

//Power Dips - Bullish
PDIp=ADX(14)>MDI(14) AND PDI(14)>MDI(14) AND ap AND Vl AND m1>s1 AND plus ;
PlotShapes(IIf(PDIp,shapeHollowCircle+ shapePositionAbove,shapeNone),colorCustom12,0,0,0);

//power buys
pr2=ADX(14)>20 AND PDI(14)>20 AND ADX(14)>MDI(14) AND PDI(14)>MDI(14) AND plus AND j2;
PlotShapes(IIf(pr2,shapeHollowCircle+ shapePositionAbove,shapeNone),colorCustom12,0,0,20);

//Power Dips - Bearish
PDIm=ADX(14)>PDI(14) AND MDI(14)>PDI(14) AND ap AND Tp AND m1<s1 AND Minus ;
PlotShapes(IIf(PDIm,shapeHollowCircle+ shapePositionAbove,shapeNone),colorWhite,0,0,0);

//Power shorts
sr2=ADX(14)>20 AND MDI(14)>20 AND ADX(14)>PDI(14) AND MDI(14)>PDI(14) AND Minus AND j4;
PlotShapes(IIf(sr2,shapeHollowCircle+ shapePositionAbove,shapeNone),colorRed,0,0,-20);

//powerbuy2
pr2a=ADX(14)>20 AND PDI(14)>20 AND ADX(14)>MDI(14) AND PDI(14)>MDI(14) AND plus AND j1;
PlotShapes(IIf(pr2a,shapeHollowCircle+ shapePositionAbove,shapeNone),colorCustom12,0,0,20);
_SECTION_END();

_SECTION_BEGIN("Exploration");
Filter = j1 OR j2 OR j3 OR j4 OR PDIp OR PDIm OR pr2 OR sr2 ;

AddColumn(j1,"ZL UP",1);
AddColumn(J2,"MA Up",1);
AddColumn(j3,"MA DN",1);
AddColumn(J4,"ZL DN",1);
AddColumn(PDIp,"PDIP UP",1);
AddColumn(pr2,"PHK UP",1);
AddColumn(PDIm,"PDIP DN",1);
AddColumn(sr2,"PHk UP",1);
_SECTION_END();

_SECTION_BEGIN("Display the Signals");
Title = "Trading the MACD" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor() +

" - " + Date() +" - " +EncodeColor(colorLime)+ "MACD= "+WriteVal(m1)+"--"+EncodeColor(colorYellow)+
WriteIf (j1, " MACD Crossed above zero","")+
WriteIf (j2, " Bullish crossover above zero","")+
WriteIf (j4, " MACD Crossed below Zero","")+
WriteIf (j3, " Bearish crossover above zero","")+
WriteIf (PDIP, " Bullish Power Dip","")+
WriteIf (pr2, " & Power Buy","")+
WriteIf (sr2, " & Power Short","")+
WriteIf (PDIm, " Bearish Power Dip","")+
WriteIf (Hd1, " & Bullish Hook","")+
WriteIf (Hu1, " & Bearish Hook","")+
WriteIf (zlrd1, " & Bearish zeroline Reject","")+
WriteIf (zlru, " & Bullish Zeroline Reject","");
_SECTION_END();
 
#10
Thank you so much for posting such a wounderful afls, which are i am looking from your chest. Expecting some more and continues posting the afls from you which would very much helpful for good and smooth trading stratigies by using your afls:confused:[COLOR="bl[FONT="Arial Black"][/FONT]ack"][/COLOR]
 

Similar threads