วันเสาร์ที่ 30 พฤศจิกายน พ.ศ. 2556
+++ HOLY GRAIL for Amibroker
_SECTION_BEGIN("PRASAD SYSTEMS");
Param("DEDICATED TO MY FATHER",5);
_SECTION_END();
_SECTION_BEGIN("BACK COLR");
SetChartBkColor( ParamColor("Chart Color", colorBlack));
SetChartOptions(0,chartShowArrows|chartShowDates);
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/13 );
GfxSetTextAlign( 6 );// center alignment
GfxSetTextColor( ParamColor("Text Color", ColorHSB( 42, 42, 42 ) ));
GfxSetBkMode(0); // transparent
GfxTextOut( Name(), Status("pxwidth")/2, Status("pxheight")/7);
GfxSelectFont("Tahoma", Status("pxheight")/17 );
GfxTextOut( "HOLY GRAIL", Status("pxwidth")/2, Status("pxheight")/2.6 );
GfxSelectFont("Tahoma", Status("pxheight")/30 );
GfxTextOut( "prasad9rao@gmail.com", Status("pxwidth")/2, Status("pxheight")/2.1);
GfxSelectFont("Arial Bold", Status("pxheight")/15);
GfxTextOut( "PRASAD ANALYSTIC ver 5", Status("pxwidth")/2, Status("pxheight")/20);
_SECTION_END();
GfxSetTextColor(ColorRGB(200, 150, 100) );
GfxSelectFont("Arial BOLD", Status("pxheight")/60);
GfxTextOut( "Dedicated to My Father : BALKRISHNA RAO",Status("pxwidth")/5, Status("pxheight")/1.06);
SetBarFillColor( IIf(O>C,ColorRGB(217,0,0),ColorRGB(1,149,38)) );
Plot( C, "Price", IIf( O>C,ColorRGB(255,208,82), ColorRGB(255,255,255)), styleCandle );
/******************FIXED TITLES**************/
Chg=Ref(C,-1);
Title = EncodeColor(colorYellow)+ "Company :: " +Title = Name() + " " + EncodeColor(colorLightOrange) + "Date :: " + Date() +EncodeColor(11) + EncodeColor(colorWhite) + "\n{{INTERVAL}} " +
EncodeColor(55)+ " Open: "+ EncodeColor(colorWhite)+ WriteVal(O,format=1.2) +
EncodeColor(55)+ " High: "+ EncodeColor(colorWhite) + WriteVal(H,format=1.2) +
EncodeColor(55)+ " Low: "+ EncodeColor(colorWhite)+ WriteVal(L,format=1.2) +
EncodeColor(55)+ " Close: "+ WriteIf(C> Chg,EncodeColor(colorBrightGreen),EncodeColor(colorRed))+ WriteVal(C,format=1.2)+
EncodeColor(55)+ " Change: "+ WriteIf(C> Chg,EncodeColor(colorBrightGreen),EncodeColor(colorRed))+ WriteVal(ROC(C,1),format=1.2)+ "%"+
EncodeColor(55)+ " Volume: "+ EncodeColor(colorWhite)+ WriteVal(V,1);
/************************************************************
SUPPORTS & RESISTANCE
*************************************************************/
HaClose =EMA((O+H+L+C)/4,3);
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
_SECTION_BEGIN("Support and Resistance");
supres=ParamToggle("Display(ON - OFF)","Off|On",0);
if(supres)
{
Prd1=Param("Resistance Period",2,0,200,1);
test = TEMA ( High , Prd1 ) ;
PK = test > Ref(test,-1) AND Ref(test,1) < High;//Peak
PKV0 = ValueWhen(PK,haHigh,0);//PeakValue0
PKV1 = ValueWhen(PK,haHigh,1);//PeakValue1
PKV2 = ValueWhen(PK,haHigh,2);//PeakValue2
MPK = PKV2 < PKV1 AND PKV1 > PKV0 ;//MajorPeak
MPKV = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,1); //MajorPeakValue
MPKD = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),1); //MajorPeakDate
SD = IIf(DateNum() < LastValue(MPKD,lastmode = True ), Null, LastValue(MPKV,Lastmode = True));//SelectedDate
Plot(SD, "Resist1", colorDarkRed,styleDots|styleDashed|styleThick|styleNoTitle,maskAll);
MPKV2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,2); //MajorPeakValue
MPKD2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),2); //MajorPeakDate
SD2 = IIf(DateNum() < LastValue(MPKD2,lastmode = True ), Null, LastValue(MPKV2,Lastmode = True));//SelectedDate
Plot(SD2, "Resist2", colorDarkRed,styleDots|styleDashed|styleThick|styleNoTitle,maskAll);
MPKV3 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,3); //MajorPeakValue
MPKD3 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),3); //MajorPeakDate
SD3 = IIf(DateNum() < LastValue(MPKD3,lastmode = True ), Null, LastValue(MPKV3,Lastmode = True));//SelectedDate
Plot(SD3, "Resist3", colorDarkRed,styleDots|styleDashed|styleThick|styleNoTitle,maskAll);
MPKV4 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,4); //MajorPeakValue
MPKD4 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),4); //MajorPeakDate
SD4 = IIf(DateNum() < LastValue(MPKD4,lastmode = True ), Null, LastValue(MPKV4,Lastmode = True));//SelectedDate
Plot(SD4, "Resist4", colorDarkRed,styleDots|styleDashed|styleThick|styleNoTitle,maskAll);
MPKV5 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,5); //MajorPeakValue
MPKD5 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),5); //MajorPeakDate
SD5 = IIf(DateNum() < LastValue(MPKD5,lastmode = True ), Null, LastValue(MPKV5,Lastmode = True));//SelectedDate
Plot(SD5, "Resist5", colorDarkRed,styleDots|styleDashed|styleThick|styleNoTitle,maskAll);
MPKV6 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,6); //MajorPeakValue
MPKD6 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),6); //MajorPeakDate
SD6 = IIf(DateNum() < LastValue(MPKD6,lastmode = True ), Null, LastValue(MPKV6,Lastmode = True));//SelectedDate
Plot(SD6, "Resist6", colorDarkRed,styleDots|styleDashed|styleThick|styleNoTitle,maskAll);
//SP=L > Ref(L,-1) AND Ref(L,1) < L;//Peak
Prd2=Param("Suppport Period",2,0,200,1);
test2 = TEMA ( Low , Prd2 ) ;
SP = Ref(test2,1) > Low AND test2 < Ref(test2,-1);//Peak
SPV0 = ValueWhen(SP,haLow,0);//PeakValue0
SPV1 = ValueWhen(SP,haLow,1);//PeakValue1
SPV2 = ValueWhen(SP,haLow,2);//PeakValue2
//PKV5 = ValueWhen(PK,haHigh,5);//PeakValue5
//PKV6 = ValueWhen(PK,haHigh,6);//PeakValue6
MSP = SPV2 > SPV1 AND SPV1 < SPV0 ;//MajorPeak
MSPV = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,1);
MSPD = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),1);
SD = IIf(DateNum() < LastValue(MSPD,lastmode = True ), Null, LastValue(MSPV,Lastmode = True));
Plot(SD,"Support1", colorYellow,styleDots|styleDashed|styleThick|styleNoTitle,maskAll);
MSPV2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,2);
MSPD2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),2);
SD2 = IIf(DateNum() < LastValue(MSPD2,lastmode = True ), Null, LastValue(MSPV2,Lastmode = True));
Plot(SD2,"Support2", colorYellow,styleDots|styleDashed|styleThick|styleNoTitle,maskAll);
MSPV3 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,3);
MSPD3 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),3);
SD3 = IIf(DateNum() < LastValue(MSPD3,lastmode = True ), Null, LastValue(MSPV3,Lastmode = True));
Plot(SD3,"Support3", colorYellow,styleDots|styleDashed|styleThick|styleNoTitle,maskAll);
MSPV4 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,4);
MSPD4 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),4);
SD4 = IIf(DateNum() < LastValue(MSPD4,lastmode = True ), Null, LastValue(MSPV4,Lastmode = True));
Plot(SD4,"Support4", colorYellow,styleDots|styleDashed|styleThick|styleNoTitle,maskAll);
MSPV5 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,5);
MSPD5 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),5);
SD5 = IIf(DateNum() < LastValue(MSPD5,lastmode = True ), Null, LastValue(MSPV5,Lastmode = True));
Plot(SD5,"Support5", colorYellow,styleDots|styleDashed|styleThick|styleNoTitle,maskAll);
MSPV6 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,6);
MSPD6 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),6);
SD6 = IIf(DateNum() < LastValue(MSPD6,lastmode = True ), Null, LastValue(MSPV6,Lastmode = True));
Plot(SD6,"Support6", colorYellow,styleDots|styleDashed|styleThick|styleNoTitle,maskAll);
}
_SECTION_END();
/* **********************************
PIVOTS
********************************** */
_SECTION_BEGIN("PIVOT Average ");
P = ParamField("Field");
Type = ParamList("Type", "Weighted,Lagless-21,Hull-26,Linear Regression-45,Exponential,Double Exponential,Tripple Exponential,Wilders,Simple");
Periods = Param("Periods", 9, 2, 100 );
Displacement = Param("Displacement", 1, -50, 50 );
m = 0;
if( Type == "Weighted" ) m= WMA( P, Periods );
if( Type == "Lagless-21" ) m= 2*EMA(P, Periods)-EMA(EMA(P, Periods), Periods);
if( Type == "Hull-26" ) m= WMA(2*(WMA(P, Periods/2))-WMA(P, Periods) ,4 );
if( Type == "Linear Regression-45" ) m= LinearReg( P, Periods );
if( Type == "Exponential" ) m = EMA( P, Periods );
if( Type == "Double Exponential" ) m = DEMA( P, Periods );
if( Type == "Tripple Exponential" ) m = TEMA( P, Periods );
if( Type == "Wilders" ) m = Wilders( P, Periods );
if( Type == "Simple" ) m = MA( P, Periods );
_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,50,5000,10);
nBars = Param("Number of bars", 12, 5, 40);
"BIdxJJJ = " + BarIndex() +
"\n" + "OGGGGGGGGGGG = " + O + "\n"+"H = "+ H + "\n"+"L = " + L
+ "\n"+"C " ;
GraphXSpace=7;
// -- 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;
aHHVBars = HHVBars(H, nBars);
aLLVBars = LLVBars(L, nBars);
aHHV = HHV(H, nBars);
aLLV = LLV(L, nBars);
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";
}
if (BarCount > farback)
{
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
}
}
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;
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++;
}
}
PlotShapes(
IIf(aHPivs==1,shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-15);
PlotShapes(IIf(aLPivs==1,shapeUpArrow , shapeNone), ColorRGB(168,255,0), 0, Low, Offset=-15);
printf("\n Buuuy pivotss %g", aLPivs);
printf("\n Seel pivotss %g \n",aHPivs);
IIf( (aHPivs==1 AND aLPivs==0),PIVOT_SELL = 5, PIVOT_SELL = 0 );
IIf( aLPivs==1 AND aHPivs==0, PIVOT_BUY = 0, PIVOT_BUY = 5 );
PIVOT_BUY = IIf(aLPivs==1, 5, 0);
PIVOT_SELL = IIf(aHPivs==1, 5, 0);
printf("\n Buuuy pivotss %g", PIVOT_BUY);
printf("\n Seel pivotss %g \n",PIVOT_SELL);
PIVOT_status = WriteIf(PIVOT_BUY,"Buy["+PIVOT_BUY+"]",WriteIf(PIVOT_SELL,"Sell["+PIVOT_SELL+"]","NA"));
PIVOT_col = IIf (PIVOT_BUY,colorGreen, IIf (PIVOT_SELL,colorRed,colorLightGrey));
_SECTION_END();
/************************************************************
VOLUMES INCLUDED IN CHART
*************************************************************/
_SECTION_BEGIN("Volume");
VOLUME_TOGGLE = ParamToggle("Plot Volume","Off|On",0);
minimum = LastValue( Lowest( Volume ) );
maximum = LastValue( Highest( Volume ) )*10;
Period = Param("Period", 10, 2, 300, 1, 10 );
Volumeclimaxup = colorRed;
HighVolumeChurnbars = colorLime;
Lowvolumebars = colorYellow;
Volumeclimaxdn = colorWhite;
ClimaxChurnColor=colorBlue;
Value1 = V;
Value2 = V*(H-L);
Value3 = V/(H-L);
SetBarFillColor(IIf( (Value2 == HHV(Value2,Period)),ColorRGB(255,0,0),
IIf( (Value3 == HHV(Value3,Period)), ColorRGB(0, 142,0),
IIf( (Value1 == LLV(Value1,Period)), ColorRGB(255,255,0),
IIf( ((Value2 == HHV(Value2,Period) AND (Value3 == HHV(Value3,Period)))), ClimaxChurnColor,
IIf( (Value3 == LLV(Value3,Period)), Volumeclimaxdn, ColorRGB(0, 206, 255 )))))));
BarColor = IIf( (Value2 == HHV(Value2,Period)),ColorRGB(255,0,0),
IIf( (Value3 == HHV(Value3,Period)),ColorRGB(0, 142,0),
IIf( (Value1 == LLV(Value1,Period)), ColorRGB(255,255,0),
IIf( ((Value2 == HHV(Value2,Period) AND (Value3 == HHV(Value3,Period)))), ClimaxChurnColor,
IIf( (Value3 == LLV(Value3,Period)), Volumeclimaxdn, ColorRGB(0, 206, 255))))));
if(VOLUME_TOGGLE==1)
{
Plot( Volume, "Volume", Barcolor, styleCandle | styleThick | styleOwnScale, minimum, maximum);
_SECTION_END();
}
/************************************************************
EMA 21 50 crossover
*************************************************************/
_SECTION_BEGIN("EMA");
EMA_TOGGLE = ParamToggle("Plot EMA","Off|On",1);
LOW_EMA= Param("Lower EMA",21,21,49,1);
L_EMA = EMA(C,LOW_EMA);
HIGH_EMA= Param("Higher EMA",50,50,199,1);
H_EMA = EMA(C,HIGH_EMA);
HIGHEST_EMA= Param("Highest EMA",200,200,365,1);
HT_EMA = EMA(C,HIGHEST_EMA);
if(EMA_TOGGLE==1)
{
Plot( EMA( C, LOW_EMA), _DEFAULT_NAME(), ParamColor("Lower EMA Color", colorPink ), ParamStyle("Style") );
Plot( EMA( C, HIGH_EMA), _DEFAULT_NAME(), ParamColor("Higher EMA Color", colorSkyblue), ParamStyle("Style") );
Plot( EMA( C, HIGHEST_EMA), _DEFAULT_NAME(), ParamColor("Highest EMA Color", colorRed ), ParamStyle("Style") );
}
_SECTION_END();
/**********************************************************
/ADX
***********************************************************/
range = Param("Range",14,3,60,1);
px = PDI(range);
nx = MDI(range);
ax = ADX(range);
Line_Control = 20;
up_adx = Ref(ADX(range),-1) < ADX(range);
dw_adx = Ref(ADX(range),-1) > ADX(range);
// ADX Trends
Notrend = ADX(range) < 20;
ModerateTrend = ADX(range) >= 20 AND ADX(range) < 40 AND up_adx ;
StrongTrend = ADX(range) >= 40 AND ADX(range) < 60 AND up_adx ;
VeryStrongTrend = ADX(range) >= 60 AND ADX(range) < 80 AND up_adx ;
ExtremelyStrongTrend = ADX(range) >= 80 AND up_adx ;
// Buy Conditions
bcon1 = Cross(px,ax) AND nx < px AND ax > Ref(ax,-1);
scon1 = Cross(nx,ax) AND px < nx AND ax > Ref(ax,-1);
adbuy = ax < 20 AND ax > Ref(ax,-1) AND ( Cross(px,nx) OR nx < px) ;
adsell = ax < 20 AND ax > Ref(ax,-1) AND ( Cross(nx,px) OR nx > px) ;
adbuy1 = Cross(px,ax) AND nx < px AND ax > Ref(ax,-1) AND px > ax;
adsell1 = Cross(nx,ax) AND nx > px AND ax > Ref(ax,-1) AND nx > ax;
BUY_ADX = bcon1 + adbuy + adbuy1;
SELL_ADX = scon1 + adsell + adsell1;
ADX_status = WriteIf(BUY_ADX,"Buy["+BUY_ADX+"]",WriteIf(SELL_ADX,"Sell["+SELL_ADX+"]","NA"));
ADX_col = IIf (BUY_ADX,colorGreen, IIf (SELL_ADX,colorRed,colorLightGrey));
/**********************************************************
/MACD Cross
***********************************************************/
_SECTION_BEGIN("MACD");
MACD_TOGGLE = ParamToggle("Plot MACD","Off|On",0);
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
m1 = MACD(r1, r2);
s1 = Signal(r1,r2,r3);
difference = m1-s1;
mycolor=IIf(m1<0 AND m1>s1,51,IIf(m1>0 AND m1>s1,colorBrightGreen,IIf(m1>0 AND m1<s1,colorLightOrange,colorRed)));
// **********************
//MACD crossing zero
B_MACD_0 = Cross(MACD(r1, r2),0);
S_MACD_0 = Cross(0,MACD(r1, r2));
// **********************
//Bullish - Bearish MACD crossing signal above zero or below zero plane
BULL_CROSS_ABOVE_ZERO = Cross (MACD(r1, r2),Signal(r1,r2,r3)) AND MACD(r1, r2) > 0;
BEAR_CROSS_ABOVE_ZERO = Cross (Signal(r1,r2,r3),MACD(r1, r2)) AND MACD(r1, r2) > 0;
// **********************
//bELOW ZERO Bullish - Bearish MACD crossing signal above zero or below zero plane
BULL_CROSS_BELOW_ZERO = Cross (MACD(r1, r2),Signal(r1,r2,r3)) AND MACD(r1, r2)<0;
BEAR_CROSS_BELOW_ZERO = Cross(Signal(r1,r2,r3),MACD(r1, r2)) AND MACD(r1, r2)<0;
// **********************
//Zero line reject ZLR
BEAR_ZLR = BarsSince(B_MACD_0);
BEAR_ZLR1 = (BEAR_ZLR < 6) AND (S_MACD_0);
BULL_ZLR = BarsSince(S_MACD_0);
BULL_ZLR1 = (BULL_ZLR < 6) AND (B_MACD_0);
// **********************
//HOOKS
BULL_HOOK1 = BarsSince(BEAR_CROSS_ABOVE_ZERO);
BULL_HOOK = (BULL_HOOK1<6) AND BULL_CROSS_ABOVE_ZERO ;
BEAR_HOOK1 = BarsSince(BULL_CROSS_ABOVE_ZERO);
BEAR_HOOK = (BEAR_HOOK1<6) AND BEAR_CROSS_ABOVE_ZERO ;
BUY_MACD = B_MACD_0 + BULL_CROSS_ABOVE_ZERO + BULL_CROSS_BELOW_ZERO + BULL_ZLR1 + BULL_HOOK;
SELL_MACD = S_MACD_0 + BEAR_CROSS_ABOVE_ZERO + BEAR_CROSS_BELOW_ZERO + BEAR_ZLR1 + BEAR_HOOK;
/*
if(MACD_TOGGLE==1)
{
GraphX = 5;
Plot( m1, StrFormat(_SECTION_NAME()+"(%g,%g)", r1, r2), ParamColor("MACD color", colorRed ),ParamStyle("MACD style") );
Plot( s1 ,"Signal" + _PARAM_VALUES(), ParamColor("Signal color", colorBlueGrey ), ParamStyle("Signal style") );
Color =IIf(difference > 0,colorLime,colorRed);
Plot(m1-s1, "MACD Histogram", mycolor, styleHistogram | styleThick | styleNoLabel, styleOwnScale);
PlotShapes(IIf(B_MACD_0,shapeDigit1 ,Null),colorYellow,0,Min(0,0),Min(0,0));
PlotShapes(IIf(B_MACD_0,shapeUpArrow,Null),colorGreen,0,Min(0,0),-20);
PlotShapes(IIf(S_MACD_0,shapeDigit2 ,Null),colorOrange,0,Min(0,0),0);
PlotShapes(IIf(S_MACD_0,shapeDownArrow,Null),colorRed,0,Min(0,0),-20);
PlotShapes(IIf(BULL_CROSS_ABOVE_ZERO,shapeDigit3 ,Null),colorYellow,0,Min(0,0),Min(0,0));
PlotShapes(IIf(BULL_CROSS_ABOVE_ZERO,shapeUpArrow,Null),colorGreen,0,Min(0,0),-20);
PlotShapes(IIf(BEAR_CROSS_ABOVE_ZERO ,shapeDigit4 ,Null),colorOrange,0,Min(0,0),Min(0,0));
PlotShapes(IIf(BEAR_CROSS_ABOVE_ZERO ,shapeDownArrow,Null),colorRed,0,Min(0,0),-20);
PlotShapes(IIf(BULL_CROSS_BELOW_ZERO,shapeDigit5 ,Null),colorYellow,0,Min(0,0),Min(0,0));
PlotShapes(IIf(BULL_CROSS_BELOW_ZERO,shapeUpArrow,Null),colorGreen,0,Min(0,0),-20);
PlotShapes(IIf(BEAR_CROSS_BELOW_ZERO,shapeDigit6 ,Null),colorOrange,0,Min(0,0),Min(0,0));
PlotShapes(IIf(BEAR_CROSS_BELOW_ZERO,shapeDownArrow,Null),colorRed,0,Min(0,0),-20);
PlotShapes(IIf(BEAR_ZLR1,shapeStar+shapePositionAbove,shapeNone),colorRed,0,0,-30);
PlotShapes(IIf(BULL_ZLR1,shapeStar+shapePositionAbove,shapeNone),colorGold,0,0,30);
PlotShapes(IIf(BULL_HOOK,shapeStar+shapePositionAbove,shapeNone),colorGold,0,0,30);
PlotShapes(IIf(BEAR_HOOK,shapeStar+shapePositionAbove,shapeNone),colorRed,0,0,-30);
}
*/
_SECTION_END();
BUY_MACD = B_MACD_0 + BULL_CROSS_ABOVE_ZERO + BULL_CROSS_BELOW_ZERO + BULL_ZLR1 + BULL_HOOK ;
SELL_MACD = S_MACD_0 + BEAR_CROSS_ABOVE_ZERO + BEAR_CROSS_BELOW_ZERO + BEAR_ZLR1 + BEAR_HOOK ;
MACD_status = WriteIf(BUY_MACD,"Buy["+BUY_MACD+"]",WriteIf(SELL_MACD,"Sell["+SELL_MACD+"]","NA"));
MACD_col = IIf (BUY_MACD,colorGreen, IIf (SELL_MACD,colorRed,colorLightGrey));
/**************************************************
Stochastics
***************************************************/
_SECTION_BEGIN("STOCHASTICS");
STOC_TOGGLE = ParamToggle("Plot STOCHASTICS","Off|On",0);
SP = Param( "Periods", 10, 1, 200, 1 );
Ksmooth = Param( "%K avg", 5, 1, 200, 1 );
Dsmooth = Param( "%D avg", 5, 1, 200, 1 );
StochDval = StochD( SP , Ksmooth, DSmooth );
StochKval = StochK( SP , Ksmooth);
Overbought = 80;
Oversold = 20;
/*
if(STOC_TOGGLE==1)
{
GraphX = 5;
Plot( StochD( SP , Ksmooth, DSmooth), _DEFAULT_NAME(), ParamColor( "ColorD", colorTurquoise ), ParamStyle("Style") );
Plot( StochK( SP , Ksmooth), _DEFAULT_NAME(), ParamColor( "ColorK", colorPaleGreen ), ParamStyle("Style") );
Plot(Overbought,"Overbought Level",colorRed);
Plot(Oversold,"Oversold Level",colorGreen);
}
*/
StochBuy = Cross(StochK(SP,Ksmooth), StochD(SP,Ksmooth, DSmooth)) AND
(StochD(SP,Ksmooth, DSmooth) > 20) AND (StochK(SP,Ksmooth) > 20) AND
(StochD(SP,Ksmooth, DSmooth) < 80) AND (StochK(SP,Ksmooth) < 80);
StochSell = Cross (StochD(SP,Ksmooth, DSmooth), StochK(SP,Ksmooth)) AND
(StochD(SP,Ksmooth, DSmooth) > 20) AND (StochK(SP,Ksmooth) > 20) AND
(StochD(SP,Ksmooth, DSmooth) < 80) AND (StochK(SP,Ksmooth) < 80);
StochStrongBuy = Cross(StochK(SP,Ksmooth),StochD(SP,Ksmooth, DSmooth)) AND
(StochD(SP,Ksmooth, DSmooth) < 20) AND (StochK(SP,Ksmooth) < 20) ;
StochStrongSell = Cross (StochD(SP,Ksmooth,DSmooth), StochK(SP , Ksmooth));
(StochD(SP,Ksmooth, DSmooth) > 80) AND (StochK(SP,Ksmooth) > 80);
BUY_STOCH = StochBuy + StochStrongBuy;
SELL_STOCH = StochSell + StochStrongSell;
printf("sto %g",BUY_STOCH);
_SECTION_END();
STOCH_status = WriteIf(BUY_STOCH,"Buy["+BUY_STOCH+"]",WriteIf(SELL_STOCH,"Sell["+SELL_STOCH+"]","NA"));
STOCH_col = IIf (BUY_STOCH,colorGreen, IIf (SELL_STOCH,colorRed,colorLightGrey));
/**************************************************
TREND DETECTOR
***************************************************/
_SECTION_BEGIN("Trend Detector");
TREND_TOGGLE = ParamToggle("Plot Trend","Off|On",0);
A = (H+C+L)/3;
B=MA(A,5)-EMA(A,34);
D = EMA(A,34)-MA(A,5);
Bcolor=IIf(B>D,25,39);
Dcolor=IIf(D<B,25,39);
Up = B > D;
down = B < D;
TREND_B = Cross(B,D);
TREND_S = Cross(D,B);
if(TREND_TOGGLE==1)
{
Plot(B,"B ",Bcolor,styleLine|styleThick);
Plot(D,"D ",Dcolor,styleLine|styleThick);
Plot(B,"",Bcolor,styleHistogram|styleThick);
Plot(D,"",Dcolor,styleHistogram|styleThick);
Plot(0,"",colorWhite,styleLine);
PlotShapes(IIf(TREND_S, shapeHollowDownArrow , shapeNone), colorRed,0,0,-8);
PlotShapes(IIf(TREND_B, shapeHollowUpArrow , shapeNone), colorGreen,0,0,-8);
}
_SECTION_END();
TREND_status = WriteIf(TREND_B,"Buy",WriteIf(TREND_S ,"Sell","NA"));
TREND_col = IIf (TREND_B,colorGreen, IIf (TREND_S ,colorRed,colorLightGrey));
/**************************************************
RSI
***************************************************/
_SECTION_BEGIN("RSI");
Rperiods = Param( "Periods", 14, 1, 200, 1 );
OB = Param("OverBrought Line",70,70,100,1);
OS = Param("OverSold Line",30,20,40,1);
CentreRSI = 50;
Overbought = OB;
Oversold = OS;
RSI_PERIODS = Prec(RSI( Rperiods),1);
//******* RSI Cross 30 or 70**//
B_RSI = RSI_CROSS_30 = Cross(RSI_PERIODS,OS);
S_RSI = RSI_CROSS_70 = Cross(OB,RSI_PERIODS);
//******* RSI < 30 or > 70**//
RSI_BELOW_30 = RSI_PERIODS < OS ;
RSI_ABOVE_70 = RSI_PERIODS > OB ;
//******* RSI > OR < IN LAST 14 DAYS***//
RSI_14_GREATEST = RSI_PERIODS>=HHV( RSI_PERIODS, 14);
RSI_14_LOWEST = RSI_PERIODS<=LLV( RSI_PERIODS, 14);
//******* RSI DIVERGENCE***//
RSI_BEAR_DIV = Close >= HHV( Close, 14 ) AND RSI_PERIODS < HHV( RSI_PERIODS, 14 );
RSI_BULL_DIV = RSI_PERIODS >= HHV( RSI_PERIODS, 14 ) AND Close < HHV( Close, 14 );
RSI_BULL_DIV1 = Close <= LLV( Close, 14 ) AND RSI_PERIODS > LLV(RSI_PERIODS, 14 );
RSI_BEAR_DIV1 = RSI_PERIODS <= LLV( RSI_PERIODS, 14) AND Close > LLV(Close,14);
/*****/////////
RSI_BUY = B_RSI ;
RSI_SELL =S_RSI ;
_SECTION_END();
RSI_status = WriteIf(RSI_BUY,"Buy["+RSI_BUY+"]",WriteIf(RSI_SELL,"Sell["+RSI_SELL+"]","NA"));
RSI_col = IIf (RSI_BUY,colorGreen, IIf (RSI_SELL,colorRed,colorLightGrey));
/**************************************************
OBV
***************************************************/
_SECTION_BEGIN("OBV");
MA_OBV_Period = Param("OBV_MA Period",10,10,21,1);
/***********OBV CROSS MA************/
OBV_BUY = Cross(OBV(),MA(OBV(),MA_OBV_Period));
OBV_SELL = Cross(MA(OBV(),MA_OBV_Period),OBV());
_SECTION_END();
OBV_status = WriteIf(OBV_BUY,"Buy",WriteIf(OBV_SELL,"Sell","NA"));
OBV_col = IIf (OBV_BUY,colorGreen, IIf (OBV_SELL,colorRed,colorLightGrey));
/**************************************************
TSV = SIMILAR TO WORDEN
***************************************************/
_SECTION_BEGIN("TSV");
Period = Param("Period for FVE", 22, 5, 80, 1 );
Coeff = Param("Coeff for Cutoff", 0.1, 0, 2, 0.01 );
intra=log(H)-log(L);
Vintra = StDev(intra, period );
inter = log(Avg)-log(Ref(Avg,-1));
Vinter = StDev(inter,period);
Cutoff = Coeff * (Vinter+Vintra)*C;
MF = C- (H+L)/2 + Avg - Ref( Avg, -1 );
VC = IIf( MF > Cutoff, V,
IIf( MF < -Cutoff, -V, 0 ));
FVE = 100 * Sum( VC, Period )/(MA( V, Period ) * Period );
// Momemtum Indicator by William Blau
TSI = 100 * ( EMA( EMA( C - Ref( C, -1 ) ,25 ) ,13)
/ EMA( EMA( abs( C - Ref( C, -1) ),25 ), 13 ) );
TSI_BUY = Cross(TSI,EMA(TSI,7));
TSI_SELL = Cross(EMA(TSI,7),TSI);
_SECTION_END();
TSI_status = WriteIf(TSI_BUY,"Buy",WriteIf(TSI_SELL,"Sell","NA"));
TSI_col = IIf (TSI_BUY,colorGreen, IIf (TSI_SELL,colorRed,colorLightGrey));
/**************************************************
TRIX
***************************************************/
_SECTION_BEGIN("TRIX");
// TRIX - 15 Periods, 9 Signal Periods
tPeriods = Param("Periods", 15, 2, 100, 1 );
tSig = Param("Signal", 9, 2, 100, 1);
Zero = 0;
TRIX_VAL = Trix(tPeriods);
SIG_TRIX = EMA(Trix(tPeriods),tSig);
/***********TRIX & Signal Line cross ************/
TRIX_SIGNAL_BUY = Cross(TRIX_VAL, SIG_TRIX) AND TRIX_VAL < 0;
TRIX_SIGNAL_SELL = Cross(SIG_TRIX, TRIX_VAL)AND TRIX_VAL > 0;
/***********TRIX & Zero Line cross ************/
TRIX_ZERO_BUY = Cross(TRIX_VAL, Zero);
TRIX_ZERO_SELL = Cross(Zero, TRIX_VAL);
TRIX_BUY = TRIX_SIGNAL_BUY + TRIX_ZERO_BUY;
TRIX_SELL = TRIX_SIGNAL_SELL + TRIX_ZERO_SELL;
_SECTION_END();
TRIX_status = WriteIf(TRIX_BUY,"Buy",WriteIf(TRIX_SELL,"Sell","NA"));
TRIX_col = IIf (TRIX_BUY,colorGreen, IIf (TRIX_SELL,colorRed,colorLightGrey));
/************************************************
Gap
*************************************************/
GAP_UP = GapUp();
GAP_DW = GapDown();
GAP_status = WriteIf(GAP_UP,"Buy",WriteIf(GAP_DW ,"Sell","NA"));
GAP_col = IIf (GAP_UP,colorGreen, IIf (GAP_DW ,colorRed,colorLightGrey));
/************************************************
Total of Bullish/Bearish
*************************************************/
Total_Buy = PIVOT_BUY + BUY_ADX + BUY_MACD + BUY_STOCH+ TREND_B + GAP_UP + RSI_BUY + OBV_BUY + TSI_BUY + TRIX_BUY;
Total_Sell = PIVOT_SELL + SELL_ADX + SELL_MACD + SELL_STOCH + TREND_S + GAP_DW + RSI_SELL + OBV_SELL +TSI_SELL+TRIX_SELL;
printf("B OIVOTS %g\n",PIVOT_BUY);
printf("SELL PIVOTS %g\n",PIVOT_SELL);
printf("BUY GAP %g\n",TREND_B);
printf("BUY TREND %g\n",GAP_UP);
printf("BUY RSI %g\n",B_RSI + RSI_14_GREATEST + RSI_BULL_DIV1 + RSI_BULL_DIV);
/****************************************************
CHART TITLES
****************************************************/
_SECTION_BEGIN("ANALYSIS");
ANALYSIS_TOGGLE = ParamToggle("ON - OFF","Off|On",1);
if(ANALYSIS_TOGGLE==1)
{
Chg=Ref(C,-1);
Title = EncodeColor(ColorRGB(109,178,255))+ "Company :: " +Title = Name() + " " + EncodeColor(colorLightOrange) + "Date :: " + Date() +EncodeColor(11) + EncodeColor(colorWhite) + "\n{{INTERVAL}} " +
EncodeColor(ColorRGB(0,240,255))+ " Open: "+ EncodeColor(colorWhite)+ WriteVal(O,format=1.2) +
EncodeColor(ColorRGB(0,240,255))+ " High: "+ EncodeColor(colorWhite) + WriteVal(H,format=1.2) +
EncodeColor(ColorRGB(0,240,255))+ " Low: "+ EncodeColor(colorWhite)+ WriteVal(L,format=1.2) +
EncodeColor(ColorRGB(0,240,255))+ " Close: "+ WriteIf(C> Chg,EncodeColor(ColorRGB(168,255,0)),EncodeColor(colorRed))+ WriteVal(C,format=1.2)+
EncodeColor(ColorRGB(0,240,255))+ " Change: "+ WriteIf(C> Chg,EncodeColor(ColorRGB(168,255,0)),EncodeColor(colorRed))+ WriteVal(ROC(C,1),format=1.2)+ "%"+
EncodeColor(ColorRGB(195,158,255))+ " Volume: "+ EncodeColor(colorWhite)+ WriteVal(V,1)
+"\n"
+"\n"+EncodeColor(colorYellow) +"---------------------"
+"\n"+EncodeColor(colorGold)+ " Prasad "
+"\n"+EncodeColor(colorYellow) +"---------------------"
/**************** PIVOTS***************************/
+ "\n"
+EncodeColor(colorWhite)+"PIVOTS = " +
WriteIf (aLPivs,EncodeColor(ColorRGB(168,255,0))+" BUY("+PIVOT_BUY+")",WriteIf (aHPivs,EncodeColor(colorRed)+ " SELL("+PIVOT_SELL+")","Neutral"))
/**************** ADX***************************/
+ "\n"
+EncodeColor(colorWhite)+"ADX = " +
WriteIf (BUY_ADX,EncodeColor(ColorRGB(168,255,0))+"BUY("+BUY_ADX+")",WriteIf (SELL_ADX,EncodeColor(colorRed)+ " SELL("+SELL_ADX+")","Neutral"))
/**************** MACD ***************************/
+ "\n" +
EncodeColor(colorWhite)+"MACD "+"["+r1+"]"+" " +"["+r2+"]"+" " +"["+r3+"] = " +
WriteIf (BUY_MACD,EncodeColor(ColorRGB(168,255,0))+"BUY("+BUY_MACD+")",WriteIf (SELL_MACD,EncodeColor(colorRed)+ "SELL("+SELL_MACD+")","Neutral"))
/********************STOChASTICS*********************/
+"\n"+EncodeColor(colorWhite)+"Stochastics = "
+ WriteIf(BUY_STOCH,EncodeColor(ColorRGB(168,255,0))+"BUY ("+BUY_STOCH+")",WriteIf(SELL_STOCH,EncodeColor(colorRed)+"SELL("+SELL_STOCH+")","Neutral"))
/********************RSI*********************/
+"\n" + EncodeColor(colorWhite)+"RSI"+"("+Rperiods+") = "
+WriteIf(B_RSI,EncodeColor(ColorRGB(168,255,0))+"BUY("+RSI_BUY+")",WriteIf (S_RSI,EncodeColor(colorRed)+"SELL("+RSI_SELL+")","NEUTRAL"))
/********************OBV********************/
+"\n"
+EncodeColor(colorWhite)+"OBV = "+
WriteIf(OBV_BUY,EncodeColor(ColorRGB(168,255,0))+"BUY(1)",WriteIf(OBV_SELL,EncodeColor(colorRed)+"SELL(1)",""))+
WriteIf(NOT OBV_BUY AND NOT OBV_SELL,"No Cross","")
/********************TSV********************/
+"\n"
+EncodeColor(colorWhite)+"TSV = " +
WriteIf(TSI_BUY,EncodeColor(ColorRGB(168,255,0))+"BUY(1)",
WriteIf(TSI_SELL,EncodeColor(colorRed)+"SELL(1)",""))+
WriteIf(NOT TSI_BUY AND NOT TSI_SELL,EncodeColor(colorAqua)+"NA","")
/********************TRIX*********************/
+"\n"
+EncodeColor(colorWhite)+"TRIX "+ "("+tPeriods+") "+"(" +tSig+ ") = "
+EncodeColor(ColorRGB(168,255,0))+
WriteIf (TRIX_BUY, "BUY ("+TRIX_BUY+")","")
+EncodeColor(colorRed)+
WriteIf (TRIX_SELL, "SELL("+TRIX_SELL+")","")
+EncodeColor(colorAqua)+
WriteIf (NOT TRIX_SELL AND NOT TRIX_BUY, "No Cross","")
/**************TREND*********************************/
+"\n" +EncodeColor(colorWhite)+"Trend = "
+WriteIf(Up AND NOT TREND_B,EncodeColor(ColorRGB(168,255,0))+"Up ",WriteIf(Up AND TREND_B,EncodeColor(colorBrightGreen)+ "BUY(1)",
WriteIf(Down AND NOT TREND_S,EncodeColor(colorRed)+"Down",WriteIf(Down AND TREND_S,EncodeColor(colorRed)+"SELL(1)","."))))
/**************GAPS *********************************/
+"\n"+EncodeColor(colorWhite)+"GAP = "
+WriteIf(GAP_UP,EncodeColor(ColorRGB(168,255,0))+"UP (1)",WriteIf(GAP_DW,EncodeColor(colorRed)+"DOWN (1)", EncodeColor(colorAqua)+"Neutral"))
+"\n"+EncodeColor(colorPink) +"======================"
+"\n"+EncodeColor((ColorRGB(242,157,255)))+"BUY = "+EncodeColor(colorYellow)+Total_Buy
+"\n"+EncodeColor((ColorRGB(242,157,255)))+"SELL = "+EncodeColor(colorYellow)+Total_Sell
+"\n"+EncodeColor(colorPink) +"---------------------";
}
_SECTION_END();
//**************************************************************************************
// EXPLORATION COLUMNS
//***********************************************************************************/
Filter = Total_Buy OR Total_Sell;
SetOption("NoDefaultColumns", True);
AddTextColumn( Name(), "Security", 1, textColor=colorBlack, bkgndColor=colorSkyblue);
AddColumn( DateTime(), "Date", formatDateTime, colorBlack, colorTan);
AddTextColumn(PIVOT_status, "MACD", 1, colorWhite,PIVOT_col);
AddTextColumn(MACD_status, "MACD", 1, colorWhite, MACD_col);
AddTextColumn(STOCH_status, "STOCH", 1, colorWhite, STOCH_col);
AddTextColumn(RSI_status, "RSI", 1, colorWhite, RSI_col);
AddTextColumn(OBV_status, "OBV", 1, colorWhite, OBV_col);
AddTextColumn(TSI_status, "TSV", 1, colorWhite, TSI_col);
AddTextColumn(TRIX_status, "TRIX", 1, colorWhite, TRIX_col);
AddTextColumn(TREND_status, "TREND", 1, colorWhite, TREND_col);
AddTextColumn(GAP_status, "GAP", 1, colorWhite, GAP_col);
AddColumn(Total_Buy,"Ttl Buy",1.2,colorBlack);
AddColumn(Total_Sell,"Ttl Sell",1.2,colorBlack);
+++ Auto Fibo for Amibroker
// Automatic Linear Trend Channel
// Trend is defined using an example trend: MA(cp,100)
// Amibroker AFL code by Edward Pottasch, November 2011
_SECTION_BEGIN("parameters");
sdfact=Param("Standard Deviation Factor",2,0.5,5,0.1);
offset=Param("Offset",2,1,50,1);
tc=ParamList("Channel Display",List="No Channel|Channel|ChannelRT|Both Channels",1);
_SECTION_END();
function getUptrend(cp)
{
return IIf(cp>MA(cp,100),1,0);
}
function getDowntrend(cp)
{
return IIf(cp<=MA(cp,100),-1,0);
}
// trend definition
cp=(H+L)/2;
TrendUp=getUptrend(cp);
TrendDown=getDowntrend(cp);
totalTrend=IIf(TrendUp,TrendUp,TrendDown);
dtotalTrend=totalTrend-Ref(totalTrend,-1);
vtotalTrend=ValueWhen(dtotalTrend,dtotalTrend);
// definition start points up and down trend
cbull=vtotalTrend>0 AND Ref(vtotalTrend,-1)<0;cbull=Ref(cbull,1);
cbear=vtotalTrend<0 AND Ref(vtotalTrend,-1)>0;cbear=Ref(cbear,1);
cbull=vtotalTrend>0 AND Ref(vtotalTrend,-1)<0;cbull=Ref(cbull,1);cbull[BarCount-1]=1;
cbear=vtotalTrend<0 AND Ref(vtotalTrend,-1)>0;cbear=Ref(cbear,1);cbear[BarCount-1]=1;
// definition areas up and down trend
nwbull=Ref(Flip(cbull,cbear),-1);nwbear=Ref(Flip(cbear,cbull),-1);
xxbull=BarsSince(cbull);xxbull[BarCount-1]=xxbull[BarCount-2]+1;
aaabull=LinRegIntercept(cp,xxbull);bbbbull=LinRegSlope(cp,xxbull);
daabull=Ref(ValueWhen(cbear,aaabull,0),-1);dbbbull=Ref(ValueWhen(cbear,bbbbull,0),-1);
yybull=daabull+dbbbull*(xxbull-1);yybull=IIf(xxbull>Max(offset,1),yybull,Null);
wdbull=sdfact*StdErr(cp,xxbull);wdbull=Ref(ValueWhen(cbear,wdbull,0),-1);
xxbear=BarsSince(cbear);xxbear[BarCount-1]=xxbear[BarCount-2]+1;
aaabear=LinRegIntercept(cp,xxbear);bbbbear=LinRegSlope(cp,xxbear);
daabear=Ref(ValueWhen(cbull,aaabear,0),-1);dbbbear=Ref(ValueWhen(cbull,bbbbear,0),-1);
yybear=daabear+dbbbear*(xxbear-1);yybear=IIf(xxbear>Max(offset,1),yybear,Null);
wdbear=sdfact*StdErr(cp,xxbear);wdbear=Ref(ValueWhen(cbull,wdbear,0),-1);
llbull=LinearReg(cp,xxbull);llbull=IIf(xxbull>Max(Offset,1),llbull,Null);
llbullp=LinearReg(cp,xxbull)+sdfact*StdErr(cp,xxbull);llbullp=IIf(xxbull>Max(Offset,2),llbullp,Null);
llbullm=LinearReg(cp,xxbull)-sdfact*StdErr(cp,xxbull);llbullm=IIf(xxbull>Max(Offset,2),llbullm,Null);
llbear=LinearReg(cp,xxbear);llbear=IIf(xxbear>Max(Offset,1),llbear,Null);
llbearp=LinearReg(cp,xxbear)+sdfact*StdErr(cp,xxbear);llbearp=IIf(xxbear>Max(Offset,2),llbearp,Null);
llbearm=LinearReg(cp,xxbear)-sdfact*StdErr(cp,xxbear);llbearm=IIf(xxbear>Max(Offset,2),llbearm,Null);
_SECTION_BEGIN("Chart Colors");
SetChartBkColor(ParamColor("Background Color",colorBlack));
SetChartOptions(0,chartShowDates);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color",colorGreen),IIf(C<=O,ParamColor("Candle Down Color",colorRed),colorLightGrey)));
Plot(C,"Price",IIf(C>O,ParamColor("Wick UP Color",colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color",colorDarkRed),colorLightGrey)),64,0,0,0,0);
switch(tc)
{
case("No Channel"):
break;
case("Channel"):
Plot(IIf(nwbull,yybull,Null),"",bbb=ColorRGB(0,255,0),styleDashed);
Plot(IIf(nwbull,yybull+wdbull,Null),"",bbb,styleThick);
Plot(IIf(nwbull,yybull-wdbull,Null),"",bbb,styleThick);
Plot(IIf(nwbear,yybear,Null),"",sss=ColorRGB(255,0,0),styleDashed);
Plot(IIf(nwbear,yybear+wdbear,Null),"",sss,styleThick);
Plot(IIf(nwbear,yybear-wdbear,Null),"",sss,styleThick);
PlotOHLC(IIf(nwbull,yybull+wdbull,Null),IIf(nwbull,yybull+wdbull,Null),IIf(nwbull,yybull-wdbull,Null),
IIf(nwbull,yybull-wdbull,Null),"",ColorRGB(10,15,10),styleCloud|styleNoLabel,0,0,0,-1);
PlotOHLC(IIf(nwbear,yybear+wdbear,Null),IIf(nwbear,yybear+wdbear,Null),IIf(nwbear,yybear-wdbear,Null),
IIf(nwbear,yybear-wdbear,Null),"",ColorRGB(15,10,10),styleCloud|styleNoLabel,0,0,0,-1);
break;
case("ChannelRT"):
Plot(IIf(nwbull,llbull,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbull,llbullp,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbull,llbullm,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbear,Null),"",colorRed,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbearp,Null),"",colorRed,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbearm,Null),"",colorRed,styleDashed,0,1,0,1);
PlotOHLC(IIf(nwbull,llbullp,Null),IIf(nwbull,llbullp,Null),IIf(nwbull,llbullm,Null),
IIf(nwbull,llbullm,Null),"",ColorRGB(10,15,10),styleCloud|styleNoLabel,0,0,0,-1);
PlotOHLC(IIf(nwbear,llbearp,Null),IIf(nwbear,llbearp,Null),IIf(nwbear,llbearm,Null),
IIf(nwbear,llbearm,Null),"",ColorRGB(15,10,10),styleCloud|styleNoLabel,0,0,0,-1);
break;
case("Both Channels"):
Plot(IIf(nwbull,yybull,Null),"",bbb=ColorRGB(0,255,0),styleLine);
Plot(IIf(nwbull,yybull+wdbull,Null),"",bbb,styleThick);
Plot(IIf(nwbull,yybull-wdbull,Null),"",bbb,styleThick);
Plot(IIf(nwbear,yybear,Null),"",sss=ColorRGB(255,0,0),styleLine);
Plot(IIf(nwbear,yybear+wdbear,Null),"",sss,styleThick);
Plot(IIf(nwbear,yybear-wdbear,Null),"",sss,styleThick);
Plot(IIf(nwbull,llbull,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbull,llbullp,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbull,llbullm,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbear,Null),"",colorRed,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbearp,Null),"",colorRed,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbearm,Null),"",colorRed,styleDashed,0,1,0,1);
break;
}
_SECTION_END();/* Fibonacci Internal & External Retracements */
// This is a Modified Version that shows Fibonacci 00% & 100% instead of WRONG Sup & Res
_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, colorRed, 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(colorYellow) + "Fibonacci Internal & External Retracements " + EncodeColor(colorWhite) + Name() + " " + 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( Color100) + "100% = " + EncodeColor(Color100) + p100 + " "+"\n"+
EncodeColor( colorWhite) + "78.6% = " + EncodeColor(42)+ r786 + " " +"\n"+
EncodeColor( colorWhite) + "61.8% = " + EncodeColor(43)+ r618 + " "+"\n"+
EncodeColor( colorWhite) + "50% = " + EncodeColor(41)+ r050 + " "+"\n"+
EncodeColor( colorWhite) + "38.2% = " + EncodeColor(44)+ r382 + " "+"\n"+
EncodeColor( colorWhite) + "23.6% = " + EncodeColor(45)+ r236+ " " +"\n"+
EncodeColor( Color00) + "00% = " + EncodeColor(Color00) + p00 + " " ;
}
GraphXSpace=5;
// Trend is defined using an example trend: MA(cp,100)
// Amibroker AFL code by Edward Pottasch, November 2011
_SECTION_BEGIN("parameters");
sdfact=Param("Standard Deviation Factor",2,0.5,5,0.1);
offset=Param("Offset",2,1,50,1);
tc=ParamList("Channel Display",List="No Channel|Channel|ChannelRT|Both Channels",1);
_SECTION_END();
function getUptrend(cp)
{
return IIf(cp>MA(cp,100),1,0);
}
function getDowntrend(cp)
{
return IIf(cp<=MA(cp,100),-1,0);
}
// trend definition
cp=(H+L)/2;
TrendUp=getUptrend(cp);
TrendDown=getDowntrend(cp);
totalTrend=IIf(TrendUp,TrendUp,TrendDown);
dtotalTrend=totalTrend-Ref(totalTrend,-1);
vtotalTrend=ValueWhen(dtotalTrend,dtotalTrend);
// definition start points up and down trend
cbull=vtotalTrend>0 AND Ref(vtotalTrend,-1)<0;cbull=Ref(cbull,1);
cbear=vtotalTrend<0 AND Ref(vtotalTrend,-1)>0;cbear=Ref(cbear,1);
cbull=vtotalTrend>0 AND Ref(vtotalTrend,-1)<0;cbull=Ref(cbull,1);cbull[BarCount-1]=1;
cbear=vtotalTrend<0 AND Ref(vtotalTrend,-1)>0;cbear=Ref(cbear,1);cbear[BarCount-1]=1;
// definition areas up and down trend
nwbull=Ref(Flip(cbull,cbear),-1);nwbear=Ref(Flip(cbear,cbull),-1);
xxbull=BarsSince(cbull);xxbull[BarCount-1]=xxbull[BarCount-2]+1;
aaabull=LinRegIntercept(cp,xxbull);bbbbull=LinRegSlope(cp,xxbull);
daabull=Ref(ValueWhen(cbear,aaabull,0),-1);dbbbull=Ref(ValueWhen(cbear,bbbbull,0),-1);
yybull=daabull+dbbbull*(xxbull-1);yybull=IIf(xxbull>Max(offset,1),yybull,Null);
wdbull=sdfact*StdErr(cp,xxbull);wdbull=Ref(ValueWhen(cbear,wdbull,0),-1);
xxbear=BarsSince(cbear);xxbear[BarCount-1]=xxbear[BarCount-2]+1;
aaabear=LinRegIntercept(cp,xxbear);bbbbear=LinRegSlope(cp,xxbear);
daabear=Ref(ValueWhen(cbull,aaabear,0),-1);dbbbear=Ref(ValueWhen(cbull,bbbbear,0),-1);
yybear=daabear+dbbbear*(xxbear-1);yybear=IIf(xxbear>Max(offset,1),yybear,Null);
wdbear=sdfact*StdErr(cp,xxbear);wdbear=Ref(ValueWhen(cbull,wdbear,0),-1);
llbull=LinearReg(cp,xxbull);llbull=IIf(xxbull>Max(Offset,1),llbull,Null);
llbullp=LinearReg(cp,xxbull)+sdfact*StdErr(cp,xxbull);llbullp=IIf(xxbull>Max(Offset,2),llbullp,Null);
llbullm=LinearReg(cp,xxbull)-sdfact*StdErr(cp,xxbull);llbullm=IIf(xxbull>Max(Offset,2),llbullm,Null);
llbear=LinearReg(cp,xxbear);llbear=IIf(xxbear>Max(Offset,1),llbear,Null);
llbearp=LinearReg(cp,xxbear)+sdfact*StdErr(cp,xxbear);llbearp=IIf(xxbear>Max(Offset,2),llbearp,Null);
llbearm=LinearReg(cp,xxbear)-sdfact*StdErr(cp,xxbear);llbearm=IIf(xxbear>Max(Offset,2),llbearm,Null);
_SECTION_BEGIN("Chart Colors");
SetChartBkColor(ParamColor("Background Color",colorBlack));
SetChartOptions(0,chartShowDates);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color",colorGreen),IIf(C<=O,ParamColor("Candle Down Color",colorRed),colorLightGrey)));
Plot(C,"Price",IIf(C>O,ParamColor("Wick UP Color",colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color",colorDarkRed),colorLightGrey)),64,0,0,0,0);
switch(tc)
{
case("No Channel"):
break;
case("Channel"):
Plot(IIf(nwbull,yybull,Null),"",bbb=ColorRGB(0,255,0),styleDashed);
Plot(IIf(nwbull,yybull+wdbull,Null),"",bbb,styleThick);
Plot(IIf(nwbull,yybull-wdbull,Null),"",bbb,styleThick);
Plot(IIf(nwbear,yybear,Null),"",sss=ColorRGB(255,0,0),styleDashed);
Plot(IIf(nwbear,yybear+wdbear,Null),"",sss,styleThick);
Plot(IIf(nwbear,yybear-wdbear,Null),"",sss,styleThick);
PlotOHLC(IIf(nwbull,yybull+wdbull,Null),IIf(nwbull,yybull+wdbull,Null),IIf(nwbull,yybull-wdbull,Null),
IIf(nwbull,yybull-wdbull,Null),"",ColorRGB(10,15,10),styleCloud|styleNoLabel,0,0,0,-1);
PlotOHLC(IIf(nwbear,yybear+wdbear,Null),IIf(nwbear,yybear+wdbear,Null),IIf(nwbear,yybear-wdbear,Null),
IIf(nwbear,yybear-wdbear,Null),"",ColorRGB(15,10,10),styleCloud|styleNoLabel,0,0,0,-1);
break;
case("ChannelRT"):
Plot(IIf(nwbull,llbull,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbull,llbullp,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbull,llbullm,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbear,Null),"",colorRed,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbearp,Null),"",colorRed,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbearm,Null),"",colorRed,styleDashed,0,1,0,1);
PlotOHLC(IIf(nwbull,llbullp,Null),IIf(nwbull,llbullp,Null),IIf(nwbull,llbullm,Null),
IIf(nwbull,llbullm,Null),"",ColorRGB(10,15,10),styleCloud|styleNoLabel,0,0,0,-1);
PlotOHLC(IIf(nwbear,llbearp,Null),IIf(nwbear,llbearp,Null),IIf(nwbear,llbearm,Null),
IIf(nwbear,llbearm,Null),"",ColorRGB(15,10,10),styleCloud|styleNoLabel,0,0,0,-1);
break;
case("Both Channels"):
Plot(IIf(nwbull,yybull,Null),"",bbb=ColorRGB(0,255,0),styleLine);
Plot(IIf(nwbull,yybull+wdbull,Null),"",bbb,styleThick);
Plot(IIf(nwbull,yybull-wdbull,Null),"",bbb,styleThick);
Plot(IIf(nwbear,yybear,Null),"",sss=ColorRGB(255,0,0),styleLine);
Plot(IIf(nwbear,yybear+wdbear,Null),"",sss,styleThick);
Plot(IIf(nwbear,yybear-wdbear,Null),"",sss,styleThick);
Plot(IIf(nwbull,llbull,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbull,llbullp,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbull,llbullm,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbear,Null),"",colorRed,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbearp,Null),"",colorRed,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbearm,Null),"",colorRed,styleDashed,0,1,0,1);
break;
}
_SECTION_END();/* Fibonacci Internal & External Retracements */
// This is a Modified Version that shows Fibonacci 00% & 100% instead of WRONG Sup & Res
_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, colorRed, 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(colorYellow) + "Fibonacci Internal & External Retracements " + EncodeColor(colorWhite) + Name() + " " + 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( Color100) + "100% = " + EncodeColor(Color100) + p100 + " "+"\n"+
EncodeColor( colorWhite) + "78.6% = " + EncodeColor(42)+ r786 + " " +"\n"+
EncodeColor( colorWhite) + "61.8% = " + EncodeColor(43)+ r618 + " "+"\n"+
EncodeColor( colorWhite) + "50% = " + EncodeColor(41)+ r050 + " "+"\n"+
EncodeColor( colorWhite) + "38.2% = " + EncodeColor(44)+ r382 + " "+"\n"+
EncodeColor( colorWhite) + "23.6% = " + EncodeColor(45)+ r236+ " " +"\n"+
EncodeColor( Color00) + "00% = " + EncodeColor(Color00) + p00 + " " ;
}
GraphXSpace=5;
+++ Automatic Linear Trend Channel for Amibroker
// Automatic Linear Trend Channel
// Trend is defined using an example trend: MA(cp,100)
// Amibroker AFL code by Edward Pottasch, November 2011
_SECTION_BEGIN("parameters");
sdfact=Param("Standard Deviation Factor",2,0.5,5,0.1);
offset=Param("Offset",2,1,50,1);
tc=ParamList("Channel Display",List="No Channel|Channel|ChannelRT|Both Channels",1);
_SECTION_END();
function getUptrend(cp)
{
return IIf(cp>MA(cp,100),1,0);
}
function getDowntrend(cp)
{
return IIf(cp<=MA(cp,100),-1,0);
}
// trend definition
cp=(H+L)/2;
TrendUp=getUptrend(cp);
TrendDown=getDowntrend(cp);
totalTrend=IIf(TrendUp,TrendUp,TrendDown);
dtotalTrend=totalTrend-Ref(totalTrend,-1);
vtotalTrend=ValueWhen(dtotalTrend,dtotalTrend);
// definition start points up and down trend
cbull=vtotalTrend>0 AND Ref(vtotalTrend,-1)<0;cbull=Ref(cbull,1);
cbear=vtotalTrend<0 AND Ref(vtotalTrend,-1)>0;cbear=Ref(cbear,1);
cbull=vtotalTrend>0 AND Ref(vtotalTrend,-1)<0;cbull=Ref(cbull,1);cbull[BarCount-1]=1;
cbear=vtotalTrend<0 AND Ref(vtotalTrend,-1)>0;cbear=Ref(cbear,1);cbear[BarCount-1]=1;
// definition areas up and down trend
nwbull=Ref(Flip(cbull,cbear),-1);nwbear=Ref(Flip(cbear,cbull),-1);
xxbull=BarsSince(cbull);xxbull[BarCount-1]=xxbull[BarCount-2]+1;
aaabull=LinRegIntercept(cp,xxbull);bbbbull=LinRegSlope(cp,xxbull);
daabull=Ref(ValueWhen(cbear,aaabull,0),-1);dbbbull=Ref(ValueWhen(cbear,bbbbull,0),-1);
yybull=daabull+dbbbull*(xxbull-1);yybull=IIf(xxbull>Max(offset,1),yybull,Null);
wdbull=sdfact*StdErr(cp,xxbull);wdbull=Ref(ValueWhen(cbear,wdbull,0),-1);
xxbear=BarsSince(cbear);xxbear[BarCount-1]=xxbear[BarCount-2]+1;
aaabear=LinRegIntercept(cp,xxbear);bbbbear=LinRegSlope(cp,xxbear);
daabear=Ref(ValueWhen(cbull,aaabear,0),-1);dbbbear=Ref(ValueWhen(cbull,bbbbear,0),-1);
yybear=daabear+dbbbear*(xxbear-1);yybear=IIf(xxbear>Max(offset,1),yybear,Null);
wdbear=sdfact*StdErr(cp,xxbear);wdbear=Ref(ValueWhen(cbull,wdbear,0),-1);
llbull=LinearReg(cp,xxbull);llbull=IIf(xxbull>Max(Offset,1),llbull,Null);
llbullp=LinearReg(cp,xxbull)+sdfact*StdErr(cp,xxbull);llbullp=IIf(xxbull>Max(Offset,2),llbullp,Null);
llbullm=LinearReg(cp,xxbull)-sdfact*StdErr(cp,xxbull);llbullm=IIf(xxbull>Max(Offset,2),llbullm,Null);
llbear=LinearReg(cp,xxbear);llbear=IIf(xxbear>Max(Offset,1),llbear,Null);
llbearp=LinearReg(cp,xxbear)+sdfact*StdErr(cp,xxbear);llbearp=IIf(xxbear>Max(Offset,2),llbearp,Null);
llbearm=LinearReg(cp,xxbear)-sdfact*StdErr(cp,xxbear);llbearm=IIf(xxbear>Max(Offset,2),llbearm,Null);
_SECTION_BEGIN("Chart Colors");
SetChartBkColor(ParamColor("Background Color",colorBlack));
SetChartOptions(0,chartShowDates);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color",colorGreen),IIf(C<=O,ParamColor("Candle Down Color",colorRed),colorLightGrey)));
Plot(C,"Price",IIf(C>O,ParamColor("Wick UP Color",colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color",colorDarkRed),colorLightGrey)),64,0,0,0,0);
switch(tc)
{
case("No Channel"):
break;
case("Channel"):
Plot(IIf(nwbull,yybull,Null),"",bbb=ColorRGB(0,255,0),styleDashed);
Plot(IIf(nwbull,yybull+wdbull,Null),"",bbb,styleThick);
Plot(IIf(nwbull,yybull-wdbull,Null),"",bbb,styleThick);
Plot(IIf(nwbear,yybear,Null),"",sss=ColorRGB(255,0,0),styleDashed);
Plot(IIf(nwbear,yybear+wdbear,Null),"",sss,styleThick);
Plot(IIf(nwbear,yybear-wdbear,Null),"",sss,styleThick);
PlotOHLC(IIf(nwbull,yybull+wdbull,Null),IIf(nwbull,yybull+wdbull,Null),IIf(nwbull,yybull-wdbull,Null),
IIf(nwbull,yybull-wdbull,Null),"",ColorRGB(10,15,10),styleCloud|styleNoLabel,0,0,0,-1);
PlotOHLC(IIf(nwbear,yybear+wdbear,Null),IIf(nwbear,yybear+wdbear,Null),IIf(nwbear,yybear-wdbear,Null),
IIf(nwbear,yybear-wdbear,Null),"",ColorRGB(15,10,10),styleCloud|styleNoLabel,0,0,0,-1);
break;
case("ChannelRT"):
Plot(IIf(nwbull,llbull,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbull,llbullp,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbull,llbullm,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbear,Null),"",colorRed,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbearp,Null),"",colorRed,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbearm,Null),"",colorRed,styleDashed,0,1,0,1);
PlotOHLC(IIf(nwbull,llbullp,Null),IIf(nwbull,llbullp,Null),IIf(nwbull,llbullm,Null),
IIf(nwbull,llbullm,Null),"",ColorRGB(10,15,10),styleCloud|styleNoLabel,0,0,0,-1);
PlotOHLC(IIf(nwbear,llbearp,Null),IIf(nwbear,llbearp,Null),IIf(nwbear,llbearm,Null),
IIf(nwbear,llbearm,Null),"",ColorRGB(15,10,10),styleCloud|styleNoLabel,0,0,0,-1);
break;
case("Both Channels"):
Plot(IIf(nwbull,yybull,Null),"",bbb=ColorRGB(0,255,0),styleLine);
Plot(IIf(nwbull,yybull+wdbull,Null),"",bbb,styleThick);
Plot(IIf(nwbull,yybull-wdbull,Null),"",bbb,styleThick);
Plot(IIf(nwbear,yybear,Null),"",sss=ColorRGB(255,0,0),styleLine);
Plot(IIf(nwbear,yybear+wdbear,Null),"",sss,styleThick);
Plot(IIf(nwbear,yybear-wdbear,Null),"",sss,styleThick);
Plot(IIf(nwbull,llbull,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbull,llbullp,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbull,llbullm,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbear,Null),"",colorRed,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbearp,Null),"",colorRed,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbearm,Null),"",colorRed,styleDashed,0,1,0,1);
break;
}
_SECTION_END();
// Trend is defined using an example trend: MA(cp,100)
// Amibroker AFL code by Edward Pottasch, November 2011
_SECTION_BEGIN("parameters");
sdfact=Param("Standard Deviation Factor",2,0.5,5,0.1);
offset=Param("Offset",2,1,50,1);
tc=ParamList("Channel Display",List="No Channel|Channel|ChannelRT|Both Channels",1);
_SECTION_END();
function getUptrend(cp)
{
return IIf(cp>MA(cp,100),1,0);
}
function getDowntrend(cp)
{
return IIf(cp<=MA(cp,100),-1,0);
}
// trend definition
cp=(H+L)/2;
TrendUp=getUptrend(cp);
TrendDown=getDowntrend(cp);
totalTrend=IIf(TrendUp,TrendUp,TrendDown);
dtotalTrend=totalTrend-Ref(totalTrend,-1);
vtotalTrend=ValueWhen(dtotalTrend,dtotalTrend);
// definition start points up and down trend
cbull=vtotalTrend>0 AND Ref(vtotalTrend,-1)<0;cbull=Ref(cbull,1);
cbear=vtotalTrend<0 AND Ref(vtotalTrend,-1)>0;cbear=Ref(cbear,1);
cbull=vtotalTrend>0 AND Ref(vtotalTrend,-1)<0;cbull=Ref(cbull,1);cbull[BarCount-1]=1;
cbear=vtotalTrend<0 AND Ref(vtotalTrend,-1)>0;cbear=Ref(cbear,1);cbear[BarCount-1]=1;
// definition areas up and down trend
nwbull=Ref(Flip(cbull,cbear),-1);nwbear=Ref(Flip(cbear,cbull),-1);
xxbull=BarsSince(cbull);xxbull[BarCount-1]=xxbull[BarCount-2]+1;
aaabull=LinRegIntercept(cp,xxbull);bbbbull=LinRegSlope(cp,xxbull);
daabull=Ref(ValueWhen(cbear,aaabull,0),-1);dbbbull=Ref(ValueWhen(cbear,bbbbull,0),-1);
yybull=daabull+dbbbull*(xxbull-1);yybull=IIf(xxbull>Max(offset,1),yybull,Null);
wdbull=sdfact*StdErr(cp,xxbull);wdbull=Ref(ValueWhen(cbear,wdbull,0),-1);
xxbear=BarsSince(cbear);xxbear[BarCount-1]=xxbear[BarCount-2]+1;
aaabear=LinRegIntercept(cp,xxbear);bbbbear=LinRegSlope(cp,xxbear);
daabear=Ref(ValueWhen(cbull,aaabear,0),-1);dbbbear=Ref(ValueWhen(cbull,bbbbear,0),-1);
yybear=daabear+dbbbear*(xxbear-1);yybear=IIf(xxbear>Max(offset,1),yybear,Null);
wdbear=sdfact*StdErr(cp,xxbear);wdbear=Ref(ValueWhen(cbull,wdbear,0),-1);
llbull=LinearReg(cp,xxbull);llbull=IIf(xxbull>Max(Offset,1),llbull,Null);
llbullp=LinearReg(cp,xxbull)+sdfact*StdErr(cp,xxbull);llbullp=IIf(xxbull>Max(Offset,2),llbullp,Null);
llbullm=LinearReg(cp,xxbull)-sdfact*StdErr(cp,xxbull);llbullm=IIf(xxbull>Max(Offset,2),llbullm,Null);
llbear=LinearReg(cp,xxbear);llbear=IIf(xxbear>Max(Offset,1),llbear,Null);
llbearp=LinearReg(cp,xxbear)+sdfact*StdErr(cp,xxbear);llbearp=IIf(xxbear>Max(Offset,2),llbearp,Null);
llbearm=LinearReg(cp,xxbear)-sdfact*StdErr(cp,xxbear);llbearm=IIf(xxbear>Max(Offset,2),llbearm,Null);
_SECTION_BEGIN("Chart Colors");
SetChartBkColor(ParamColor("Background Color",colorBlack));
SetChartOptions(0,chartShowDates);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color",colorGreen),IIf(C<=O,ParamColor("Candle Down Color",colorRed),colorLightGrey)));
Plot(C,"Price",IIf(C>O,ParamColor("Wick UP Color",colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color",colorDarkRed),colorLightGrey)),64,0,0,0,0);
switch(tc)
{
case("No Channel"):
break;
case("Channel"):
Plot(IIf(nwbull,yybull,Null),"",bbb=ColorRGB(0,255,0),styleDashed);
Plot(IIf(nwbull,yybull+wdbull,Null),"",bbb,styleThick);
Plot(IIf(nwbull,yybull-wdbull,Null),"",bbb,styleThick);
Plot(IIf(nwbear,yybear,Null),"",sss=ColorRGB(255,0,0),styleDashed);
Plot(IIf(nwbear,yybear+wdbear,Null),"",sss,styleThick);
Plot(IIf(nwbear,yybear-wdbear,Null),"",sss,styleThick);
PlotOHLC(IIf(nwbull,yybull+wdbull,Null),IIf(nwbull,yybull+wdbull,Null),IIf(nwbull,yybull-wdbull,Null),
IIf(nwbull,yybull-wdbull,Null),"",ColorRGB(10,15,10),styleCloud|styleNoLabel,0,0,0,-1);
PlotOHLC(IIf(nwbear,yybear+wdbear,Null),IIf(nwbear,yybear+wdbear,Null),IIf(nwbear,yybear-wdbear,Null),
IIf(nwbear,yybear-wdbear,Null),"",ColorRGB(15,10,10),styleCloud|styleNoLabel,0,0,0,-1);
break;
case("ChannelRT"):
Plot(IIf(nwbull,llbull,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbull,llbullp,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbull,llbullm,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbear,Null),"",colorRed,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbearp,Null),"",colorRed,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbearm,Null),"",colorRed,styleDashed,0,1,0,1);
PlotOHLC(IIf(nwbull,llbullp,Null),IIf(nwbull,llbullp,Null),IIf(nwbull,llbullm,Null),
IIf(nwbull,llbullm,Null),"",ColorRGB(10,15,10),styleCloud|styleNoLabel,0,0,0,-1);
PlotOHLC(IIf(nwbear,llbearp,Null),IIf(nwbear,llbearp,Null),IIf(nwbear,llbearm,Null),
IIf(nwbear,llbearm,Null),"",ColorRGB(15,10,10),styleCloud|styleNoLabel,0,0,0,-1);
break;
case("Both Channels"):
Plot(IIf(nwbull,yybull,Null),"",bbb=ColorRGB(0,255,0),styleLine);
Plot(IIf(nwbull,yybull+wdbull,Null),"",bbb,styleThick);
Plot(IIf(nwbull,yybull-wdbull,Null),"",bbb,styleThick);
Plot(IIf(nwbear,yybear,Null),"",sss=ColorRGB(255,0,0),styleLine);
Plot(IIf(nwbear,yybear+wdbear,Null),"",sss,styleThick);
Plot(IIf(nwbear,yybear-wdbear,Null),"",sss,styleThick);
Plot(IIf(nwbull,llbull,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbull,llbullp,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbull,llbullm,Null),"",colorGreen,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbear,Null),"",colorRed,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbearp,Null),"",colorRed,styleDashed,0,1,0,1);
Plot(IIf(nwbear,llbearm,Null),"",colorRed,styleDashed,0,1,0,1);
break;
}
_SECTION_END();
+++ The Top 41 Reasons Why Traders And Investors Fail
1: They come to the market for a quick buck. The only problem is, a quick dollar made can disappear just as quickly. Between course spruikers and over-zealous brokers, this one brings many to the market, and sends just as many away broke and empty handed.
2: They Don’t Have A Plan. A trading plan is the fundamental place you should start when trading or investing – and yet many people don’t have the time, don’t realize the importance of them, or just couldn’t be bothered.
3: They don’t use Stop Losses. All of the old traders and investors I know who have traded through crashes and recessions swear by one main thing – a place where they absolutely will get out of the market, also known as a stop loss. Make sure you know yours.
4: They haven’t got tested rules for entry and exit. Would you fire a nuclear missile randomly into the air? Of course not! Someone could get hurt! It’s the same with trading – find rules that work, rules that you have tested. Don’t just buy or sell randomly or you will get hurt.
5: They listen to the advice of their friends and family. I love my family. But there is no way I will ever take a stock tip from them – it will only lead to pain and loss. If you buy on their tip, then how do you know when to sell? You will have to follow them around just waiting for the signal.
6: They don’t watch the trend. Some of my best friends are extremely successful fundamental investors. But even the most successful fundamentalists lost money in 2008 (and some of the best fund managers got absolutely hammered), because they didn’t keep an eye on the trend. The stock market will lead the overall economy by approximately six months, so watch for a trend to emerge regardless of company balance sheets.
7: They pay too much in brokerage. Brokerage can have a devastating effect on a small account. If you are using a full service broker at around $60 one way, making 50 trades a year will cost you $6,000. This is a big drag on your account, especially when you are trying to use compounding to grow it faster. Larger accounts are not so bad, but it still pays to be aware of this pit fall.
8: They listen to their stock broker. Yes, there are some excellent stock brokers out there. But at the end of the day they get paid as a direct result of you making trades. They want you to trade more. And they get loads of conflicting research reports throughout the day. Not to mention they have to bend to the wishes of the brokerage firm if they are unloading a stock for a large client. For all these reasons, listen to your broker only at your peril.
9: They risk too much on one stock or trade. A classic mistake, this involves either not knowing they are risking too much, or being so over-zealous they bet the farm. It can result in some spectacular gains, but over the long term the result is largely the same – bust!
10: They don’t watch the larger / overall trend. It is amazing how many short term traders I see trading against the direction of the longer term trend. Not only are the profits small using this method, but the wins are low too. Always watch the larger overall trend.
11: They get attached to a particular stock. Your parents hold the stock. Your boss holds the stock. Your friends are all in the stock. The only thing is – it is sinking faster than the titanic. Don’t get attached!
12: They listen to the news. Everybody loves gossip, and traders and investors are no exception. The only trouble is when it comes to the news: they are reporters, not investors! They don’t actually know what the blazers is going on! So they make something up, like “hedge funds are short selling” or “investors are running to safe-haven assets”. If you want gossip, listen to the news. If you want trading wins, get a solid system.
13: They haven’t figured out their win probability. This is something every trader should know, and every investor should be interested in. If you can’t back-test your strategy using historical prices or data, check your last year of trading results. How many wins, and how many losers did you have? This is your win:loss ratio. Keep it close.
14: They haven’t figured out their expectancy. Expectancy is a step up from probability. The formula is (win percentage * average profit) – (loss percentage * average loss). For instance if I won 70% of the time and made 3 times the amount I lost, it would be (0.7 * 3) – (0.3 * 1) = 1.8. In other words over the long term I could expect to make 1.8 dollars for every dollar I risked.
15: They want to become millionaires overnight. Becoming a millionaire takes time – time for your compounding to grow your account, and time for your expectancy to show a consistent result. The truth is that people who want to be millionaires straight away usually go bust sooner.
16: They think that investing does not mean hard work. Ah the carefree life of a trader – lying on the beach making casual calls to your broker. What a life! And what a load of marketing rubbish. The truth is, becoming a trader or investor is hard work. You need to research and manage your positions, while not losing your head.
17: They haven’t got a good support group or network. Sometimes trading or investing can really do a number on your psychology. You truly need someone who will support you in your endeavors, even if they don’t understand it. Your family, your spouse, your friends, colleagues. Check them all to see if they are a positive influence or a drain on your emotional resources.
18: They don’t actually invest. Let’s face it, some people just like to come up with ideas. They like to dream. They come up with a whiz bang theory, and test it till the cows come home. But when the time comes to put in into practice, they falter. Why? They like the research side better than the harsh truth of actual investing.
19: They haven’t got their psychology in check. Ok, there are way too many books devoted to psychology in trading. Way too many. But the truth is it does play a part in trading – you have to have the courage to stick to your plan, go against the grain sometimes, and jump back in after a loss. Get your psychology in check.
20: They blame others when things go wrong. Ah blame. It’s so easy to do! After all, if it’s their fault you don’t have to change, and your ego goes unruffled. But the thing is when you blame others, you lose the lesson. And when you are trading or investing, you definitely cannot afford to lose a single lesson.
21: They give up too quickly (and don’t let their expectancy work). Many methods will work over the longer term, given a positive expectancy. But some traders or investors get discouraged and give up, right when the market conditions are about to change in their favor.
22: They don’t have written goals. “If you don’t know where you’re going, any road will get you there.” So simple, yet so true. Write down your goals and your subconscious will find ways to make them a reality. After all, it processes things at 10,000 times the speed of the conscious brain.
23: They keep changing their methods. Another down fall of the novice trader – they look for the magic guru method, and when it doesn’t work after a few trades they look for the next guru method. And the next, and the next. But a jack of all trades is a master of none (no pun intended).
24: They use too much leverage. Leverage can be great, when used wisely. It can help you increase the amount of trades you have on, and take short positions, and it’s even tax deductible in many countries. But leverage is a double edged sword. Use too much of it and it can take you and your account down.
25: They over-diversify. Most financial planners will advocate diversification. But the truth is if you are over diversified you become at risk of under performing the overall market. The best investors and traders focus on a handful of great stocks or companies. In fact, it has been proven that between 6 and 12 stocks is optimum, and anything over that, your diversification is wasted.
26: They aren’t prepared for a string of losses. Mathematicians will tell you that even if your win percentage is 70%, probability states that you could still have a run of 10 losses in a row. And if you are investing for a long time, you will experience this in your lifetime. Be ready when it comes, and stick to your trading plan.
27: They think a stock will always go up over the long term. Many stock brokers or financial planners will have a large chart of the ASX or Dow Jones over 100 years. And it heads upwards. But what they don’t tell you is the market went sideways for 20 full years between 1960 and 1980, or that many stocks simply go bust and disappear. Babcock and Brown and Sons of Gwalia come to mind, but there are many more that have fallen deeply and just linger there, refusing to die.
28: They over-analyze. More commonly known as analysis paralysis, this can happen when you do so much research and get so many conflicting views that you find you can’t actually make a trade. Keep it simple – all the best traders do.
29: They can’t admit when they’re wrong. We are all wrong at times – but the best traders or investors don’t have trouble admitting it. They can change their mind on a dime, and are quite happy to sell a stock they were touting days or weeks ago. Forget your ego, and start being ok with being wrong. (Please note… this reason may also be wrong, and I’m OK with that).
30: They have a plan, but they don’t follow it. So they have done the research, they’ve tested their theories, but when they actually put money in the market they break all of their rules!
31: Subconsciously, they don’t actually want to win. Maybe their parents look down on the stock market. Maybe they got burned before and are afraid it might happen again. Whatever the reason, sometimes our subconscious can sabotage us. If so, some meditation or deep reflection can help.
32: They turn their money over to “experts”. The fact is, even most professional traders are not even right 50% of the time. And a large majority of managed funds don’t even perform as well as their index, let alone out perform it. No one will care as much about your money as you. Get educated.
33: They put too much emphasis on predicting the future. Traders who predict the future find all sorts of reasons to back it up – but when it doesn’t turn out like they planned, sometimes it can be hard to stay objective in making decisions. Take forecasts with a grain of salt.
34: They get impatient and move onto something else. Patience is essential, whether you are short term trading or long term investing. Sometimes you just have to wait it out. I know traders who sat out the whole of 2008 – but at least they did not lose money! Don’t get impatient with the market.
35: They don’t know how to make money in a down market. Whether you are shorting stocks, writing options, or just making money from your cash account as the stock market falls it doesn’t mater – you will be ahead of 90% of investors who simply sit there and lose money as the market falls.
36: They mistake a rising market for investment skill. Ah bull markets. How many “gurus” come out of the woodwork as a market is rising? And what happens to most of them when a bear market comes? That’s right, never heard of again. Whatever the conditions, keep learning in the markets. Or as Han Solo from Star Wars puts it: “Don’t get cocky, kid”.
37: They don’t enjoy doing research. The vast majority of trading or investing is doing research – whatever your method you have to do the rounds and find stocks that fit your criteria. Some people just don’t enjoy doing this – maybe they are more of a people person, maybe they just don’t have time. Either way, it still needs to be done.
38: They don’t have the discipline to stick to their strategy. For example a long term investor who gets shaken out of the market by a short term price fluctuation. If you have a strategy, stick to it. If it really doesn’t suit you, change it.
39: They think the market will stay this way forever. If there is anything that’s true about the markets, it is they are ever changing. What works today may not work tomorrow, and today’s bull market will become tomorrow’s bear. The market will never “stay this way forever”.
40: They can’t buy again if the stock turns around. When a trader sells a stock, it can be hard to buy it back again if they discover they were wrong. But the better investors throw away their ego and stick to their rules. If the rules say buy again, they buy.
41: They hound people for tips instead of learning the ropes. How people love tips! Some people will do anything for a “hot tip” in the market. But it’s usually at the expense of actually learning the ropes themselves. And if you buy using someone else’s tip, when do you sell?
Hope this helps and happy trading!
+++ http://www.mql4.com/ อีกหนึ่งเว็บที่ต้องเข้ามาดู สมัครสมาชิกไว้ จะมีทั้ง Free indicator/ Free EA ไรต่าง ๆ อีกมากครับ เยอะเวอร์ ...
http://www.mql4.com/ อีกหนึ่งเว็บที่ต้องเข้ามาดู สมัครสมาชิกไว้ จะมีทั้ง Free indicator/ Free EA ไรต่าง ๆ อีกมากครับ เยอะเวอร์ ...
นอกจากนี้เรายังสามารถเชื่อม port MT4 ของเราเข้ากับเว็บนี้และเขาจะมี report ไรต่างๆ เกี่ยวกับการเทรดของเรา คล้าย ๆ กับ myfxbook.com
นอกจากนี้เรายังสามารถเชื่อม port MT4 ของเราเข้ากับเว็บนี้และเขาจะมี report ไรต่างๆ เกี่ยวกับการเทรดของเรา คล้าย ๆ กับ myfxbook.com
+++ http://www.myfxbook.com/ เปิด acc แล้วไม่ว่า demo หรือ real อย่าลืมเชื่อมเข้ากับ myfxbook
http://www.myfxbook.com/ เปิด acc แล้วไม่ว่า demo หรือ real อย่าลืมเชื่อมเข้ากับ myfxbook เพื่อบันทึก record และเขาจะมี report ไรต่าง ๆ ให้เราได้วิเคราะห์ เยอะมาก
+++ ข่าว มีผลกระทบกับราคา เพราะคนเสพข่าว แล้วประมวลผล และเอาผลที่ประมวลได้มาเชื่อมกับความรู้สึก
http://www.forexfactory.com/ ไม่ว่าจะหุ้นไทยหรือ Forex หรือโปรดักส์ทางการเงินต่าง ๆ ข่าว มีผลกระทบกับราคา เพราะคนเสพข่าว แล้วประมวลผล และเอาผลที่ประมวลได้มาเชื่อมกับความรู้สึกและการตัดสินใต และคนเป็นคนกำหนดราคาของสินค้าทางการเงินนั้นๆ ..... เมื่อคนโลภ ไม่กลัว กล้า ราคาก็มักจะขึ้น เพราะคนส่วนใหญ่เชื่อแบบนั้น ...และเมื่อทุกคนกลัว ... คนเหล่านั้นก็จะเป็นคนกำหนดราคาอีกเช่นกัน .....
แพร่มซ่ะยาว แค่จะบอกว่า เว็บนี้มันกรอง เงื่อนไขข่าวได้ และกำหนด filter ได้ครับ
หน้าจออื่น ๆ ที่น่าสนใจ แนะนำสมัครสมาชิกแล้วลองกด ๆ ดูครับ มีไรให้ดูเยอะ
+++ รวมความหมายของ Backtest/Optimize Report ของ MT4 ...อย่าคิดว่า ทุก Indicator/EA จะใช้ได้หมดกับทุก Time Frame หรือ ทุกคู่ แต่เราควรหรือน่าจะทำการทดสอบก่อนนำไปใช้
สำหรับคนที่ชอบหา EA/Indicator ต่างๆ มาเล่น อย่าลืมนะครับก่อนนำไปใช้ ลองเอามาทำ Optimize ดูก่อน เพื่อดูว่ามันเหมาะกับ tf ไหน เหมาะกับคู่เงินไหน และค่า ที่เหมาะมันควรจะใช้เท่าไหร่ และพอได้ค่าแล้วก็มาสุ่มทำ back test เป็นช่วง ๆ อีกทีหนึ่ง ...
เมนูมันอยู่ตรงนี้นะครับ
Gross profit, the summed up profit for all profitable transactions;TotalNetProfit = GrossProfit - GrossLoss
ProfitFactor = GrossProfit / GrossLoss
Expected Payoff = (ProfitTrades / TotalTrades) * (GrossProfit / ProfitTrades) -
(LossTrades / TotalTrades) * (GrossLoss / LossTrades)
where:- TotalTrades - total amount of trades;
- ProfitTrades - the amount of profitable transactions;
- LossTrades - the amount of losing transactions;
- GrossProfit - the summed up profit;
- GrossLoss - the summed up loss.
AbsoluteDrawDown = InitialDeposit - MinimalBalance
MaximalDrawDown = Max of (Maximal Peak - next Minimal Peak)The basic stages of changing the maximal drawdown value within testing are given in the picture below. The total maximal drawdown value is in the thick arrows.
- Total trades - total amount of trades made by the expert within testing;
- Short positions (won %) - total amount of short positions and the precentage of
profitable ones among them (profitable short positions / total amount of short
positions * 100%);
- Long positions (won %) - total amount of long positions and the precentage of profitable
ones among them (profitable long positions / total amount of long positions * 100%);
- Profit trades (% of total) - total amount of profitable transactions and percentage
of the total amount of transactions (ProfitTrades / TotalTrades * 100%);
- Loss trades (% of total) - total amount of losing transactions and percentage of
the total amount of transactions (LossTrades / TotalTrades * 100%);
- Largest profit trade - the largest profitable trade among profitable trades;
- Largest loss trade - the largest losing trade among losing trades;
- Average profit trade - averaged size of profit of profit trades (GrossProfit / ProfitTrades);
- Average loss trade - averaged size of loss among losing trades (GrossLoss / LossTrades);
- Maximum consecutive wins (profit in money) - maximum consecutive amount of wins
among profitable series of trades and the summed up profit within this series;
- Maximum consecutive losses (loss in money) - maximum consecutive amount of losses
among losing series of trades and the summed up loss within this series;
- Maximal consecutive profit (count of wins) - maximum profit of a consecutive series
of profitable trades and the amount of trades in this series;
- Maximal consecutive loss (count of losses) - maximum loss of a consecutive series
of losing trades and the amount of trades in this series;
- Average consecutive wins - averaged amount of trades in consecutive profitable series.
- Average consecutive losses - averaged amount of trades in consecutive losing series.
Colors used for modeling quality diagram
The following colors are used in the color diagram:- Lime - modeling on minutes, marked with 7 in the picture below.
- Deeper green colors show modeling on large timeframes, from M5 to H4.
- Pink color - pure fractal modeling without data of a smaller timeframe, marked with
2 in the picture.
- Gray color - modeling limitation by date, marked with 1 in the picture.
Expected Payoff = (ProfitTrades / TotalTrades) * (GrossProfit / ProfitTrades) - (LossTrades / TotalTrades) * (GrossLoss / LossTrades) = = (ProfitTrades / TotalTrades) * (GrossProfit / ProfitTrades) - (LossTrades / TotalTrades) * (GrossLoss / LossTrades) = = GrossProfit / TotalTrades - GrossLoss /TotalTrades = = ( GrossProfit - GrossLoss ) / TotalTrades = = TotalNetProfit / TotalTrades Expected Payoff = TotalNetProfit / TotalTrades
สมัครสมาชิก:
บทความ (Atom)
























