Sunday 31 August 2014

Buy Sell Signals given for signals to signal tread.Trend Indicator for Amibroker (AFL)


Buy Sell Signals given for signals to signal tread.
Trend Indicator for Amibroker (AFL)



_SECTION_BEGIN("Price");
pds = 20;
MAFAST = EMA( Close, 20 );
MASLOW = EMA( Close, 40 );
 
DonchianUpper = HHV( Ref( H, -1 ), pds );
DonchianLower = LLV( Ref( L, -1 ), pds );
DonchianMiddle = ( DonchianUpper + DonchianLower ) / 2;
 
UpTrend = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) ) AND EMA( Close, 20 ) > EMA( Close, 40 );
DnTrend = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) ) AND EMA( Close, 20 ) < EMA( Close, 40 );
Color = IIf( UpTrend, colorGreen, IIf( DnTrend, colorRed, colorBlue) );
UpTrend=ExRem(UpTrend,DnTrend);
Dntrend=ExRem(DnTrend,UpTrend);

Plot( C, "Price", Color, styleBar | styleThick );
NewDay = IIf(Day() != Ref(Day(), -1) OR BarIndex() == LastValue(BarIndex()), 1, 0);

_SECTION_END();
PlotShapes(IIf(UpTrend, shapeUpArrow, shapeNone),colorBrightGreen, 0,L, Offset=-45);
PlotShapes(IIf(DnTrend, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-45);


_SECTION_BEGIN("L.T.P.");
cx = Param( "cxposn", 1000, 0, 1250, 1 );
cy = Param( "cyposn", 25, 0, 500, 1 );
GfxSelectFont( "Candara", 18, 98, False );
gfxcup = SelectedValue(C > Ref(C,-1));
gfxpcolor = IIf(gfxcup,colorBrightGreen,colorRed);
GfxSetTextColor(gfxpcolor);
//GfxSetTextColor( colorWhite );
GfxTextOut( "L.T.P.  " + C + " ", cx, cy );
_SECTION_END();

_SECTION_BEGIN("Background text");
SetChartBkColor(colorBlack);
strWeekday = StrMid("---sunday---Monday--TuesdayWednesday-Thursday--Friday--Saturday", SelectedValue(DayOfWeek())*9,9);
GraphXSpace=Param("GraphXSpace",0,-55,200,1);
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode(transparent=1);
GfxSetOverlayMode(1);
GfxSelectFont("Candara", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxSetTextColor( ColorRGB (217,217,213));
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( "By", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
GfxSelectFont("Candara", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( "Otithi Lozz", Status("pxwidth")/C14, Status("pxheight")/C15*4 );
GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);
_SECTION_END();

_SECTION_BEGIN("Title");

DODay = TimeFrameGetPrice("O", inDaily);
DHiDay = TimeFrameGetPrice("H", inDaily);
DLoDay = TimeFrameGetPrice("L", inDaily);
Title = EncodeColor(colorWhite)+"   Otithi     "+EncodeColor(colorWhite)+ Name() + ", " + Interval(2) + ", " + Date() + "   -  "+strWeekday + "  - " +
EncodeColor(colorWhite)   +  "\nO " + EncodeColor(colorWhite) + O +

 ",   H :  "   + H +
 ",   L  :  " + L +
 ",   C  :  "  + C +
"\n"+EncodeColor(colorWhite)+ "  Day-Open : " +DODay + "  Day-High : " +DHiDay + "  Day-Low : " + DLoDay


;
_SECTION_BEGIN("Time Left");
function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}
RequestTimedRefresh( 1 );
TimeFrame = Interval();
SecNumber = GetSecondNum();
Newperiod = SecNumber % TimeFrame == 0;
SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
SecsToGo = TimeFrame - SecsLeft;

x=Param("xposn",430,0,1000,1);
y=Param("yposn",40,0,1000,1);

GfxSelectSolidBrush( ColorRGB( 230, 230, 230 ) );
GfxSelectPen( ColorRGB( 230, 230, 230 ), 2 );
if ( NewPeriod )
{
GfxSelectSolidBrush( colorYellow );
GfxSelectPen( colorYellow, 2 );
Say( "New period" );
}

cx = Param( "cxposn", 1080, 0, 1250, 1 );
cy = Param( "cyposn", 5, 0, 500, 1 );
GfxSelectFont( "Candara", 14, 98, False );

GfxSetTextColor(colorBlue);

GfxTextOut( "T i m e L e f t   " + SecsToGo + " ", cx, cy );
_SECTION_END();

Strategy for swing trading Afl Fro Amibroker

  Strategy for swing trading




_SECTION_BEGIN("TD Fractl LINE");
strength = Param("Strength",1,1,15,1);
pR=PeakBars(RSI(14),strength)==0;
PlotShapes(shapeSmallCircle*pR,colorWhite,0,H,0);
_SECTION_END();

_SECTION_BEGIN("TD Fractl LINE");
pS =TroughBars(RSI(14),strength)==0;
PlotShapes(shapeSmallCircle*pS,colorYellow,0,L,0);
_SECTION_END();

_SECTION_BEGIN("Price Risistance");
RT=SelectedValue(ValueWhen(pR,H));
ST=SelectedValue(ValueWhen(pS,L));
Plot(RT,"",colorBlue,styleThick);
Plot(ST,"",colorYellow,styleThick);
_SECTION_END();

_SECTION_BEGIN("TD Fractl LINE");
pR=PeakBars(RSI(14),strength)==0;
pivothigh = Ref(pR,-1)<pR AND pR>Ref(pR,1);
y0=SelectedValue(ValueWhen(pivothigh,H,2));
y1=SelectedValue(ValueWhen(pivothigh,H,1));
x0=SelectedValue(ValueWhen(pivothigh,Cum( 1)-1,2));
x1=SelectedValue(ValueWhen(pivothigh,Cum( 1)-1,1));
LineA=LineArray(x0,y0,x1,y1,1);
Plot(LineA,"",colorWhite,4+8,styleNoLabel);
_SECTION_END();

_SECTION_BEGIN("TD Fractl LINE");
pS =TroughBars(RSI(14),strength)==0;
pivotlow = Ref(pS,-1)<pS AND pS>Ref(pS,1);
yt0=SelectedValue(ValueWhen(pivotlow,L,2));
yt1=SelectedValue(ValueWhen(pivotlow,L,1));
xt0=SelectedValue(ValueWhen(pivotlow,Cum( 1)-1,2));
xt1=SelectedValue(ValueWhen(pivotlow,Cum( 1)-1,1));
LineB=LineArray(xt0,yt0,xt1,yt1,1);
Plot(LineB,"",colorWhite,4+8,styleNoLabel);
_SECTION_END();

_SECTION_BEGIN("EMA1");
P = ParamField("Price field",-1);
_SECTION_END();

PI = atan(1.00) * 4;
periods = 30;
HighHigh = HHV(H, periods);
LowLow = LLV(L, periods);
range = 25 / (HighHigh - LowLow) * LowLow;
MA1= EMA(C,200);
x1_MA = 0;
x2_MA= 1;
y1_MA= 0;
y2_MA= (Ref(MA1, -1) - MA1) / Avg * range;
c_MA= sqrt((x2_MA- x1_MA)*(x2_MA- x1_MA) + (y2_MA- y1_MA)*(y2_MA- y1_MA));
angle_MA= round(180 * acos((x2_MA - x1_MA)/c_MA) / PI);
angle_MA= IIf(y2_MA> 0, - angle_MA, angle_MA);
Col=IIf(angle_MA>3,colorWhite,IIf(angle_MA<(-3),colorRed,colorBlack));
Plot(EMA( P,200), _DEFAULT_NAME(), Col, ParamStyle("Style") );
Buy1=Cross(C,LineA) AND RSI(14)>60 AND angle_MA>=1;
Buy2=Cross(C,RT)AND RSI(14)>60 AND angle_MA>=1;
Buy=Buy1 OR Buy2;
Sell1=Cross(LineB,C)AND RSI(14)<40 AND angle_MA<=(-1);
Sell2=Cross(RT,C)AND RSI(14)<40 AND angle_MA<=(-1);
Sell=Sell1 OR Sell2;
PlotShapes(IIf(Buy,shapeSmallUpTriangle,shapeNone),colorBlue,0,L,-20);
PlotShapes(IIf(Sell,shapeSmallDownTriangle, shapeNone),colorYellow,0,H,-20);

Saturday 30 August 2014

A AFL For Amibroker : Volume Adjusted Momentum

A AFL For Amibroker : Volume Adjusted Momentum   Like This ...




_SECTION_BEGIN(" ATR & Volume Adjusted Momentum");

SetChartBkColor(colorBlack);

p1=Param("First period",5,2,14,1);
p2=Param("Second Period",30,14,60,1);
momp=Param("Momentum Period",5,3,14,1);

Mtm = (C - Ref (C, -momp ))/ATR(momp);/// changed
AbsMtm = (abs ( mtm)+ abs(V-Ref(V,-momp))); //changed
///===============================================
Num_E = EMA ( EMA ( Mtm, P1 ), P2 );//changed
Den_E = EMA ( EMA ( AbsMtm, P1 ), p2 );//changed
///===============================================
Bensu = 100 * Nz ( Num_E / Den_E);


AA1=C/Ref(C,-8)*100;
AA2=C/Ref(C,-13)*100;
AA3=C/Ref(C,-21)*100;
a1=EMA(AA1,1);
a2=EMA(AA2,1);
a3=EMA(AA3,1);
b1=StDev(a1,8);
b2=StDev(a2,13);
b3=StDev(a3,21);
RMOV=((a1*b1)+(a2*b2)+(a3*b3))/(b1+b2+b3);
KK=EMA(EMA(RMOV,3),3);
_SECTION_END();

_SECTION_BEGIN("");



upcolor=ParamColor("UpCandleColor",colorBlack );
downcolor=ParamColor("DownCandleColor",colorBlack );



Volwma=WMA(Bensu,13);
Volchange=(((Bensu-Volwma)/Volwma)*100);
Vol=(ROC(Bensu,1));


GraphXSpace = Param("Xspace", 10, 2, 20, 1);

LBP = Param("Look Back", 15, 0, 150,1 );
Mean = MA(ln(Bensu),LBP);
StD = StDev(ln(Bensu),LBP);
xp3 = exp(mean + 2*std); //3 band
xp2 = exp(mean + 1.5*std); //2 nd band
xp1 = exp(mean + 1*std); // 1st band
xm = exp(mean); // avg
xn1 = exp(mean - 1*std); // -1 band
xn2 = exp(mean - 1.5*std); //-2 band
VolColor=IIf(KK>100,colorGold,colorCustom11);
Plot(Volwma, "Otithi Lozz", VolColor,ParamStyle("AvgStyle",styleLine|styleThick|styleDots,maskAll),1|4096);


Plot(xn1,"",colorBlue,1|4096);
Plot(xn2,"", 1,1|4096);

upbar = Bensu > Ref(Bensu,-1);
downbar = Bensu< Ref(Bensu,-1);
barcolor2=IIf(downbar,colorRed, IIf(upbar, 2,19) );

upbar = Bensu > Ref(Bensu,-1);
downbar =Bensu< Ref(Bensu,-1);

O = IIf(downbar, Bensu, 0);
C = IIf(downbar, 0,Bensu);
L=0;
H = Bensu;

ColorHighliter = IIf(upbar, upcolor,IIf(downbar, downcolor,colorDarkGreen));

pds = 10;
V1 = Bensu/MA(Bensu,13); V2 = Bensu/MA(Bensu,21);
V3 = Bensu/MA(Bensu,34);

barcolor = IIf(Bensu<MA(Bensu,pds),colorRed,colorWhite );
SetBarFillColor( barcolor );
PlotOHLC( O,H,L,C, "", barColor2, ParamStyle("CandleStyle",styleCandle,maskAll));


_SECTION_END();

_SECTION_BEGIN("Centered-StochRSI Line");
x=(( RSI(21) - LLV(RSI(21) ,21)) / ((HHV(RSI(21 ) ,21)) - LLV(RSI(21),21)))*100;
Value1=0.1*((x)-50);
Value2=WMA(Value1,7);
KK4=(exp(Value2)-1)/(exp(Value2)+1);

Plot(0,"",IIf(EMA(KK4,3)>0.50,colorBrightGreen,colorRed) ,4+styleNoLabel);
_SECTION_END();

Friday 29 August 2014

Amibroker Afl



I always try to help by shearing  many more useful Afl for Amibroker 
Just Keep in Touch
This blogs is updated day by day 
So wait and enjoy 
If Any One Need to Talk with 



Email : asfatul.alam@yahoo.com

https://mbasic.facebook.com/marketdeltainvestment

https://www.facebook.com/StocKanalysisBd


https://www.facebook.com/MarketDeltaInvestment

L.T.P trading System ...buffer_line Up and buffer_line Down

buffer_line Up and buffer_line Down







GfxSetOverlayMode(0);
GfxSelectFont("Tahoma", Status("pxheight")/56);
GfxSetTextAlign( 6 );// center alignment
GfxSetTextColor( colorLightGrey );
GfxSetBkMode(0); // transparent
GfxTextOut( Name(), Status("pxwidth")/1.2, Status("pxheight")/15 );
GfxTextOut( "http://www.facebook.com/StocKanalysisBd", Status("pxwidth")/1.2, Status("pxheight")/10 );



x = Ref(H,-1);
Y = Ref(L,-1);
a=x+5;
b=y-5;
uptrend=StochK(39,3) > StochD(39,3,3);
downtrend=StochK(39,3) < StochD(39,3,3);
Buy = Cover = H > a AND uptrend;
Sell = Short = L < b AND downtrend;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBrightGreen,0,L,-15);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
_SECTION_BEGIN("Price");
Graph0 = Close;
Graph0Style = 128;
barcolor = IIf( downtrend, 4, IIf( uptrend, 5, 1 ) );
Graph0BarColor = ValueWhen( barcolor != 0, barcolor );
SetBarFillColor( IIf( Close > Open, colorBlack, colorBlack ) );
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("Titleblock",colorLightGrey));
SetChartOptions(0,chartShowArrows|chartShowDates);

Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle |
ParamStyle("Style") | GetPriceStyle() );

///
_SECTION_BEGIN("super trend");

procedure calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendMode,CalcPrice)
{
global buffer_line_down;
global buffer_line_up;
buffer_line_down = Null;
buffer_line_up = Null;

PHASE_NONE = 0;
PHASE_BUY = 1;
PHASE_SELL = -1;

phase=PHASE_NONE;
band_upper = 0;band_lower = 0;
  
for(i = ATR_Period + 1; i < BarCount; i++)
{
    band_upper = CalcPrice[i] + ATR_Multiplier * tr[i];
    band_lower = CalcPrice[i] - ATR_Multiplier * tr[i];
    
    if(phase==PHASE_NONE)
    {
        buffer_line_up[i] = CalcPrice[i];
        buffer_line_down[i] = CalcPrice[i];
    }
    if(phase!=PHASE_BUY && Close[i]>buffer_line_down[i-1] && !IsEmpty(buffer_line_down[i-1]))
    {
        phase = PHASE_BUY;
        buffer_line_up[i] = band_lower;
        buffer_line_up[i-1] = buffer_line_down[i-1];
    }
    if(phase!=PHASE_SELL && Close[i]<buffer_line_up[i-1] && !IsEmpty(buffer_line_up[i-1]))
    {
        phase = PHASE_SELL;
        buffer_line_down[i] = band_upper;
        buffer_line_down[i-1] = buffer_line_up[i-1];
    }  
    if(phase==PHASE_BUY && ((TrendMode==0 && !IsEmpty(buffer_line_up[i-2])) || TrendMode==1) )
    {
        if(band_lower>buffer_line_up[i-1])
        {
            buffer_line_up[i] = band_lower;
        }
        else
        {
            buffer_line_up[i] = buffer_line_up[i-1];
        }
    }
    if(phase==PHASE_SELL && ((TrendMode==0 && !IsEmpty(buffer_line_down[i-2])) || TrendMode==1) )
    {
        if(band_upper<buffer_line_down[i-1])
        {
            buffer_line_down[i] = band_upper;
        }
        else
        {
            buffer_line_down[i] = buffer_line_down[i-1];
        }
    }
}
}

SetBarsRequired(sbrAll,sbrAll);

TrendMode = ParamToggle("TrendMode","Off|On",1);
ATR_Multiplier = Param("ATR_Multiplier",2,0.1,10,0.1);
ATR_Period = Param( "ATR_Period",5,1,20,1);
tr = ATR(ATR_Period);

CalcPrice = (H+L)/2;
calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendMode,CalcPrice);

SetChartOptions(0,chartShowDates);

Plot(buffer_line_up,"\ntu",ColorRGB(28,134,238),styleThick);
Plot(buffer_line_down,"\ntd",ColorRGB(205,51,51),styleThick);

Plot( 2,"",IIf(buffer_line_up,colorGreen,colorBlack),styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
Plot( 4,"",IIf(buffer_line_down,colorRed,colorBlack),styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );



Title = EncodeColor(colorYellow)+  Title = Name() + "    " + EncodeColor(2) + Date()+EncodeColor(11)  +
   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:  "+  WriteVal(C,format=1.2)+ 
   EncodeColor(55)+ "   Change:  "+ EncodeColor(colorRed)+ WriteVal(ROC(C,1),format=1.2)+ "%"+
                         
   EncodeColor(55)+ "   Volume: "+ EncodeColor(colorWhite)+ WriteVal(V,1);





_SECTION_END();

_SECTION_BEGIN("Display");
Display= ParamToggle("Display","Off|On",1);
if(Display==1)
{
x=Param("xposn",100,0,1000,1);
y=Param("yposn",569,0,1000,1);

GfxSetBkColor(ColorRGB(23,25,23));
GfxSelectFont( "Times New Roman",9,500, True);
GfxSetTextColor( colorGrey40); 
GfxTextOut("RSI: "+WriteVal(RSI(14),1.0)+" | MACD:  "+WriteVal(MACD(),1.2)+" | F(Ema): "+NumToStr(EMA(C,5),1.2)+" |9(Ema): "+NumToStr(EMA(C,9),1.2)+"
|15(EMA): "+NumToStr(EMA(C,15),1.2)+" |30(EMA): "+NumToStr(EMA(C,30),1.2)+" |50(EMA): "+NumToStr (EMA(C,50),1.2), x, y );

cx=Param("cxposn",537,0,1000,1);
cy=Param("cyposn",12,0,1000,1);

GfxSetBkColor(ColorRGB(23,25,23));
GfxSelectFont( "Bodoni MT",14,50, False);
GfxSetTextColor( colorWhite); 
GfxTextOut("LTP: "+C+" ", cx, cy );
 _SECTION_END();}

LINKON'S PIVOT TRADING SYSTEM AFL

Daily Support Daily Resistance also Pvot Point with Nice Modified  Band



_SECTION_BEGIN("ADX");
Col_bar = IIf(EMA(CCI(14),2) > Ref(EMA(CCI(14),2),-1),colorBrightGreen,colorRed);
Plot(Close,"price",col_bar,styleCandle);

_SECTION_END();

_SECTION_BEGIN("BB");
bb2top = BBandTop(Close,20,2.25);
bb1top = BBandTop(Close,20,1);
bb2bot = BBandBot(Close,20,2.25);
bb1bot = BBandBot(Close,20,1);

Plot (bb2top,"",IIf(bb2top > Ref(bb2top,-1) AND bb2bot < Ref(bb2bot,-1),colorBlue,colorGrey40),styleNoLabel);
Plot (bb2bot,"",IIf(bb2top > Ref(bb2top,-1) AND bb2bot < Ref(bb2bot,-1),colorBlue,colorGrey40),styleNoLabel);






_SECTION_BEGIN("SIMPLE_D-CAMS_SHOW");
//---- pivot points

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
HiDay = TimeFrameGetPrice("H", inDaily);
LoDay = TimeFrameGetPrice("L", inDaily);


TimeFrameSet( inDaily );

R6 = (DayH / DayL) * DayC * 1.002;
R5 = (DayH / DayL) * DayC;
R4 = (((DayH / DayL) + 0.83) / 1.83) * DayC;
R3 = ( ( (DayH / DayL) + 2.66) / 3.66) * DayC;
R2 = ( ( (DayH / DayL) + 4.5) / 5.5) * DayC;
R1 = ( ( (DayH / DayL) + 10) / 11) * DayC;
 
S1 = (2- ( ( (DayH / DayL) + 10) / 11)) * DayC;
S2 = (2-( (DayH / DayL) + 4.5) / 5.5) * DayC;
S3 = (2-(( DayH / DayL) + 2.66) / 3.66) * DayC;
S4 = (2-( (DayH / DayL) + 0.83) / 1.83) * DayC;
S5 = (2-( DayH / DayL)) * DayC;
S6 = (2-( DayH / DayL)) * DayC * 0.998;


ShowR5 = ParamToggle("R5", "No|Yes");
R5Color=ParamColor( "R5Color", colorGold );
ShowR4 = ParamToggle("R4", "yes|no");
R4Color=ParamColor( "R4Color", colorOrange );
ShowR3 = ParamToggle("R3", "yes|no");
R3Color=ParamColor( "R3Color", colorOrange );
ShowR2 = ParamToggle("R2", "No|Yes");
R2Color=ParamColor( "R2Color", colorDarkRed );
ShowR1 = ParamToggle("R1", "No|Yes");
R1Color=ParamColor( "R1Color", colorRed );

ShowS1 = ParamToggle("S1", "No|Yes");
S1Color=ParamColor( "S1Color", colorGreen );
ShowS2 = ParamToggle("S2", "No|Yes");
S2Color=ParamColor( "S2Color", colorBrightGreen );
ShowS3 = ParamToggle("S3", "yes|no");
S3Color=ParamColor( "S3Color", colorDarkGreen );
ShowS4 = ParamToggle("S4", "yes|no");
S4Color=ParamColor( "S4Color", colorDarkGreen );
ShowS5 = ParamToggle("S5", "No|Yes");
S5Color=ParamColor( "S5Color", colorAqua );

Shadowcolor = ParamColor("Shadow",ColorRGB(40,30,20));
Shadowcolor1 = ParamColor("Shadow1",ColorRGB(20,30,20));
Shadowcolor2 = ParamColor("Shadow2",ColorRGB(30,40,0));

style = styleDots | styleThick + styleNoRescale ;
style = styleLine + styleNoRescale ;


ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1)));
TimeFrameRestore();
_SECTION_END();

PlotOHLC(bb2top,bb2top,bb1top,bb1top,"",colorDarkGrey,styleCloud);
  PlotOHLC(bb1bot,bb1bot,bb2bot,bb1bot,"",colorDarkGrey,styleCloud);



_SECTION_BEGIN("Fibo for all bars");

TimeFrameSet( in15Minute*2 );
DH=Ref(H,-1);
DL=Ref(L,-1);
DC=Ref(C,-1);


pd = (O+ DH+ DL + DC )/4;
sd1 = (2*pd)-DH;
sd2 = pd -(DH - DL);
sd3 = Sd1 - (DH-DL);
rd1 = (2*pd)-DL;
rd2 = pd +(DH -DL);
rd3 = rd1 +(DH-DL);



Plot (pd,"Pivot",colorBlue,styleDots);


style = IIf(ParamList("Chart style", "styleCandle|styleBar")=="styleCandle",64,128+4);
Plot (C,Date ()+" close",1,style); //ENABLE THIS TO HAVE CANDLES AS WELL

TimeFrameRestore();


Title = EncodeColor(colorWhite)+ "LINKON'S PIVOT TRADING SYSTEM" + " - " +  Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
 "  - " + Date() +" - "
//+ WriteIf(Col_action==colorGreen, EncodeColor(colorGreen)+"stay LONG","")+ WriteIf(Col_action==colorRed, EncodeColor(colorRed)+"stay SHORT","")+  WriteIf(Col_action==colorBlack, EncodeColor(colorYellow)+"No Trend","")+"\n"
+ "Vol= "+ WriteVal(V) +WriteIf ( V > MA(V,26) ,EncodeColor(colorGreen)+"  UP "+ (V/MA(V,26))*100 + " %", EncodeColor(colorRed)+"  DOWN "+ (V/MA(V,26))*100 + " %")
+ EncodeColor(colorGreen)+   "\n Resistance 3 : "+ EncodeColor(colorWhite)+RD3
+ EncodeColor(colorGreen)+   "\n Resistance 2 : "+ EncodeColor(colorWhite)+RD2
+ EncodeColor(colorGreen)+   "\n Resistance 1 : "+ EncodeColor(colorWhite)+RD1+ EncodeColor(colorGreen)+   "     High Price : "+ EncodeColor(colorWhite)+H
+ EncodeColor(colorYellow)+   "\n Pivot Point  : "+ EncodeColor(colorWhite)+pd + EncodeColor(colorYellow)+   "      Open Price : "+ EncodeColor(colorWhite)+O+ EncodeColor(colorAqua)+   "      Close Price : "+ EncodeColor(colorBrightGreen)+C
+ EncodeColor(colorRed)+   "\n Support 1 : "+ EncodeColor(colorWhite)+SD1+ EncodeColor(colorRed)+   "            Low Price : "+ EncodeColor(colorWhite)+L
+ EncodeColor(colorRed)+   "\n Support 2 : "+ EncodeColor(colorWhite)+SD2
+ EncodeColor(colorRed)+   "\n Support 3 : "+ EncodeColor(colorWhite)+SD3
;

_SECTION_END();
_SECTION_BEGIN("swing00");
no=Param( "Swing", 2, 1, 55 );
tsl_col=ParamColor( "Color", colorCycle );

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);
tsl=IIf(avn==1,sup,res);



Buy=Cross(C,tsl);
Sell=Cross(tsl,C);
shape=Buy*shapeUpArrow + Sell*shapeDownArrow;
PlotShapes(shape,IIf(Buy,tsl_col,tsl_col),0,IIf(Buy,Low,High));
_SECTION_END();

Auto Trend Line With Buy And Sell Signal Support Resistance .

Auto Trend Line With Buy And Sell Signal Support Resistance ... HH..  LH .. LL .. HL..









_SECTION_BEGIN("KH_PriceChart");


bgTop = ParamColor("BgTop",    colorBlack);
bgBot = ParamColor("BgBottom", colorBlack);
SetChartBkGradientFill( bgTop ,bgBot, colorLightGrey);

pStyle = ParamList("Price Style", "Candle|Solid Candle|Bar|Line|Heikin-Ashi");
cBull = ParamColor("Price Bull", colorLime);
CBear = ParamColor("Price Bear", colorRed);
cLine = ParamColor("Price Line", colorWhite);



SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}}- {{INTERVAL}} {{DATE}} O= %g, H= %g, L= %g, C= %g (%.1f%%) V= " +WriteVal( V, 1.0 ) +"\n{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

ThisStyle = styleCandle;
ThisTitle = "";

_O=O; _C=C; _H=H; _L=L;

ThisColor = IIf( _C>_O, cBull, IIf(_C<_O, CBear, CLine));


switch (pStyle )
{

  case "Solid Candle":  
        SetBarFillColor( ThisColor );
        break;


  case "Bar":
       ThisStyle = styleBar;
       break;

  case "Line":
      ThisStyle = styleLine;
      ThisColor = cLine;
       break;


  case "Heikin-Ashi":
       _C = (O+H+L+C)/4;
          _O = AMA( Ref( _C, -1 ), 0.5 );
       _H = Max( H, Max( _C, _O ) );
       _L = Min( L, Min( _C, _O ) );

       ThisColor = IIf(_C >= _O,CBull, CBear);
       SetBarFillColor( ThisColor );

       ThisColor = IIf(_C >= _O,cLine, cLine);
          ThisTitle = "Heikin-Ashi";
       break;

  default:  
        SetBarFillColor( ThisColor );
        ThisColor = cLine;

       break;

}


   PlotOHLC( _O, _H, _L, _C, ThisTitle, ThisColor, ThisStyle);

  

GraphXSpace = 5;


//This Section is For HH HL LH LL //

Q = Param( "% Change", 2, 0.1, 10, 0.1 );
Z = Zig( C , q ) ;
HH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( z, q, 1 ) > Peak( Z, q, 2 ) ) );
LH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( Z, q, 1 ) < Peak( Z, q, 2 ) ) );
HL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) > Trough( Z, q, 2 ) ) );
LL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) < Trough( Z, q, 2 ) ) );
GraphXSpace = 5;
dist = 0.5 * ATR( 20 );

for ( i = 0; i < BarCount; i++ )
{
    if ( HH[i] )
        PlotText( "HH", i, H[ i ] + dist[i], colorYellow );

    if ( LH[i] )
        PlotText( "LH", i, H[ i ] + dist[i], colorYellow );

    if ( HL[i] )
        PlotText( "HL", i, L[ i ] - dist[i], colorPink );

    if ( LL[i] )
        PlotText( "LL", i, L[ i ] - dist[i], colorPink );

}








_SECTION_END();

_SECTION_BEGIN("MA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 500, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();





//PIVOTS
///////////

pivbuy=  Ref(L,-1)<Ref(L,-2) AND L>Ref(L,-1) AND Ref(H,-1)<Ref(H,-2) AND H>Ref(H,-1) AND C>Ref(C,-2) ;
pivsell= Ref(H,-1)>Ref(H,-2) AND H<Ref(H,-1) AND Ref(L,-1)>Ref(L,-2) AND L<Ref(L,-1) AND C<Ref(C,-2) ;

Buy  = pivbuy ;
Sell = pivsell ;

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

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,L,Offset=-10);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,Offset=-10);
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//PRICE
_SECTION_BEGIN("Price");
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 )) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
 ToolTip=StrFormat("Open: %g\nHigh:  %g\nLow:   %g\nClose:  %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C,
         SelectedValue( ROC( C, 1 )));
}
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

_SECTION_BEGIN("trending ribbon");
uptrend= PDI()>MDI() AND MACD()>Signal() ;
downtrend= MDI()>PDI() AND Signal()>MACD() ;
Plot( 2, /* defines the height of the ribbon in percent of pane width */"",
IIf( uptrend AND EMA(C,50)>=Ref(EMA(C,50),-1), colorLime, IIf( downtrend OR EMA(C,50)<Ref(EMA(C,50),-1),
     colorRed, colorAqua )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

_SECTION_BEGIN("Name");
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/8 );
GfxSetTextAlign( 6 );// center alignment
GfxSetTextColor( ColorHSB( 42, 42, 42 ) );
GfxSetBkMode(0); // transparent
GfxTextOut( Name(), Status("pxwidth")/2, Status("pxheight")/12 );
GfxSelectFont("Tahoma", Status("pxheight")/18 );
GfxTextOut( IndustryID(1), Status("pxwidth")/2, Status("pxheight")/4 );

GfxSelectFont("Tahoma", Status("pxheight")/18 );
GfxSelectFont("Tahoma", Status("pxheight")/36 );

_SECTION_END();

SetBarFillColor( IIf(O>C,colorDarkRed, colorBrightGreen ) );
Plot( C, "Price", IIf( O>C,colorRed, colorGreen ), styleCandle );

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("Resistance");

supres=ParamToggle("Sup_Res","No|Yes",1);
if(supres)
{


Prd1=Param("Res_Period1",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",  colorBrown,ParamStyle("ResStyle1",styleLine|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",  colorBrown,ParamStyle("ResStyle2",styleLine|styleNoTitle,maskAll));


MPKV3 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,3); //MajorPeakValue
MPKD3 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),3); //MajorPeakDate
SD3 = IIf(DateNum() < LastValue(MPKD3,lastmode = True ), Null, LastValue(MPKV3,Lastmode = True));//SelectedDate
Plot(SD3, "Resist3", colorBrown,ParamStyle("ResStyle3",styleLine|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",  colorBrown,ParamStyle("ResStyle4",styleLine|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",  colorBrown,ParamStyle("ResStyle5",styleLine|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", colorBrown ,ParamStyle("ResStyle6",styleLine|styleNoTitle,maskAll));




_SECTION_END();


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

Prd2=Param("Sup_Period1",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",  colorPlum,ParamStyle("SupportLine1",styleLine|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",  colorPlum,ParamStyle("SupportLine2",styleLine|styleNoTitle,maskAll));



MSPV3 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,3);
MSPD3 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),3);
SD3 = IIf(DateNum() < LastValue(MSPD3,lastmode = True ), Null, LastValue(MSPV3,Lastmode = True));
Plot(SD3,"Support3",  colorPlum,ParamStyle("SupportLine3",styleLine|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",  colorPlum,ParamStyle("SupportLine4",styleLine|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",  colorPlum,ParamStyle("SupportLine5",styleLine|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",  colorPlum,ParamStyle("SupportLine6",styleLine|stylehidden|styleNoTitle,maskAll));

}

_SECTION_END();

_SECTION_BEGIN("EMA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("EMA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("CandlePivots+trendline");
/////// advance trenlines with candle pivots ///////////////////
SetChartOptions(0, chartShowArrows | chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} ,{{VALUES}}", O, H, L, C, SelectedValue(ROC(C, 1))));
Plot(C, "", IIf(O >= C, colorOrange, colorGreen), styleCandle);
SetChartBkGradientFill(ParamColor("Inner panel upper", colorBlack), ParamColor("Inner panel lower", colorBlack));
_N(Title = EncodeColor(colorWhite) + StrFormat(" {{NAME}} - {{INTERVAL}} {{DATE}} Open:%g,high:%g,low:%g, Close:%g ,{{VALUES}}", O, H, L, C));
/////////////////////////////////////////////////////////////////////////////////////////////
farback = Param("How Far back to go", 100, 50, 5000, 10);
nBars = Param("Number of bars", 12, 5, 40);
aHPivs = H - H;
aLPivs = L - L;
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);
curBar = (BarCount - 1);
curTrend = "";
if (aLLVBars[curBar] < aHHVBars[curBar])
{
    curTrend = "D";
}

else
{
    curTrend = "U";
}

for (i = 0; i < farback; i++)
{
    curBar = (BarCount - 1) - i;
    if (aLLVBars[curBar] < aHHVBars[curBar])
    {
        if (curTrend == "U")
        {
            curTrend = "D";
            curPivBarIdx = curBar - aLLVBars[curBar];
            aLPivs[curPivBarIdx] = 1;
            aLPivLows[nLPivs] = L[curPivBarIdx];
            aLPivIdxs[nLPivs] = curPivBarIdx;
            nLPivs++;
        }
    }
    else
    {
        if (curTrend == "D")
        {
            curTrend = "U";
            curPivBarIdx = curBar - aHHVBars[curBar];
            aHPivs[curPivBarIdx] = 1;
            aHPivHighs[nHPivs] = H[curPivBarIdx];
            aHPivIdxs[nHPivs] = curPivBarIdx;
            nHPivs++;
        }
    }
}

curBar = (BarCount - 1);
candIdx = 0;
candPrc = 0;
lastLPIdx = aLPivIdxs[0];
lastLPL = aLPivLows[0];
lastHPIdx = aHPivIdxs[0];
lastHPH = aHPivHighs[0];
if (lastLPIdx > lastHPIdx)
{
    candIdx = curBar - aHHVBars[curBar];
    candPrc = aHHV[curBar];
    if (lastHPH < candPrc AND candIdx > lastLPIdx AND candIdx < curBar)
    {
        aHPivs[candIdx] = 1;
        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
{
    candIdx = curBar - aLLVBars[curBar];
    candPrc = aLLV[curBar];
    if (lastLPL > candPrc AND candIdx > lastHPIdx AND candIdx < curBar)
    {
        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++;
    }
}

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]);
}

a1 = ahpivs == 1;
a2 = alpivs == 1;
PlotShapes(a1 *shapeSmallCircle, colorRed, 0, H, Offset = 5);
PlotShapes(a2 *shapeSmallCircle, colorGreen, 0, L, Offset = -5);
//////////////////////////////////////////////////////

//Para = ParamToggle("Plot Parallel Lines","Off,n");

Para=ParamToggle("Plot Parallel Lines","No|Yes",1);
if(Para)
{
ColorS= ParamColor("Support",colorLime);
ColorR= ParamColor("Resistance",colorRed);
x = Cum(1);
s1 = L;
s11 = H;
pS = a2 == 1;



endt = LastValue(ValueWhen(ps,x,1));
startt = LastValue(ValueWhen(ps,x,2));
ends = LastValue(ValueWhen(ps,S1,1));
starts = LastValue(ValueWhen(ps,S1,2));
dtS = endt - startt;
aS = (endS - startS) / dtS;
bS = endS;
trendlineS = aS *(x - endt) + bS;
g3 = IIf(x > startt - 10, trendlineS,  Null);
Plot(g3, "", colors, styleThick);
pR = a1 == 1;
endt1 = LastValue(ValueWhen(pr,x,1));
startt1 = LastValue(ValueWhen(pr,x,2));
endr = LastValue(ValueWhen(pr,S11,1));
startr = LastValue(ValueWhen(pr,S11,2));
dtR = endt1 - startt1;
aR = (endR - startR) / dtR;
bR = endR;
trendlineR = aR *(x - endt1) + bR;
g4 = IIf(x > startT1 - 10, trendlineR,  Null);
Plot(g4, "", colorr, styleThick);

acd = log(endr/startr)/(endt1-startt1);
res1 = exp((x-endt1)*acd)*endr;
RRL = ROC(res1,1);
bcd = log(ends/starts)/(endt-startt);
sup1= exp((x-endt)*bcd)*ends;
RSL = ROC(sup1,1);

Low_Value = LastValue(Ref(LLV(L,endt1-startt1),-(x-endt1)));
x2 = LastValue(ValueWhen(L==Low_Value & x>startt1 & x<endt1,x));
PLL = IIf(LastValue(x)-x2>5,exp((x-x2)*acd)*Low_Value,Null);
Hi_Value = LastValue(Ref(HHV(H,endt-startt),-(x-endt)));
x3 = LastValue(ValueWhen(H==Hi_Value & x>startt & x<endt,x));
PHL = IIf(LastValue(x)-x3>5,exp((x-x3)*bcd)*Hi_Value,Null);
SLabs = sup1-Ref(sup1,-1); RLabs = res1-Ref(res1,-1);
ROC2SL = (SLabs/C)*100; ROC2RL = (RLabs/C)*100;
PLLd = abs((LastValue(C)/LastValue(PLL))-1)<0.01*100;
PHLd = abs((LastValue(C)/LastValue(PHL))-1)<0.01*100;
barvisible = Status("barvisible");
firstvisiblebar = barvisible & NOT
Ref(barvisible,-1);
HHvisible = LastValue(HighestSince(firstvisiblebar,High));
LLvisible = LastValue(LowestSince(firstvisiblebar,Low));
RaH = HHvisible *1.05; RaL = LLVisible *0.95;
AnZ= starts==0 OR ends==0 OR startr==0 OR endr==0;
PLplot = IIf(x-x2>=0 & abs(LastValue(L/PLL)-1) <abs(LastValue((100/1000)*ATR(14))) & PLL>RaL & PLL<RaH & NOT AnZ,PLL,IIf(x-x2>=0 & RaL==0 & PLLd & abs(LastValue(L/PLL)-1) <abs(LastValue((100/1000)*ATR(14)))& NOT AnZ,PLL,Null));
PHplot = IIf(x-x3>=0 & abs(LastValue(H/PHL)-1) <abs(LastValue((100/1000)*ATR(14))) & PHL>RaL & PHL<RaH & NOT AnZ,PHL,IIf(x-x3>=0 & RaL==0 & PHLd & abs(LastValue(H/PHL)-1) <abs(LastValue((100/1000)*ATR(14)))& NOT AnZ,PHL,Null));
Plot(IIf(Para,PLplot,Null)," ",colorr,styleDashed,maskDefault+styleNoRescale);
Plot(IIf(Para,PHplot,Null)," ",colors,styleDashed,maskDefault+styleNoRescale);
}
_SECTION_END();

Monday 25 August 2014

Pride System AFL For Amibroker




SetChartOptions(0,chartShowArrows|chartShowDates);

SetChartBkColor(ParamColor("Outer panel",colorBlack));

SetChartBkGradientFill( ParamColor("Inner panelupper",colorDarkGreen), ParamColor("Inner panel lower",colorTan));

Plot(C,"Price",IIf(O>C,32,34),64);

SetBarFillColor(IIf(O>C,24,19));



_SECTION_BEGIN("MID MA");

P = ParamField("Price field",-1);

Periods = Param("Periods", 100, 2, 400, 1 );

Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale );

_SECTION_END();



_SECTION_BEGIN("Long MA");

P = ParamField("Price field",-1);

Periods = Param("Periods", 200, 2, 400, 1 );

Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale );

_SECTION_END();



_SECTION_BEGIN("BBands");

P = ParamField("Price field",-1);

Periods = Param("Periods", 15, 2, 100, 1 );

Width = Param("Width", 2, 0, 10, 0.05 );

Color = ParamColor("Color", colorLightGrey );

Style = ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale;;

Plot( bbt = BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style );

Plot( bbb = BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style );

PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, colorDarkGrey, 0.9 ), styleNoLabel | styleCloud | styleNoRescale, Null, Null, Null, -1 );

_SECTION_END();



_SECTION_BEGIN("Magnified Price");

FS=Param("Font Size",15,11,100,1);

GfxSelectFont("Times New Roman", FS, 700, True );

GfxSetBkMode( colorWhite );

GfxSetTextColor( ParamColor("Color",colorYellow) );

Hor=Param("Horizontal Position",500,1,1200,1);

Ver=Param("Vertical Position",1,1,830,1);

GfxTextOut(""+C, Hor , Ver );

YC=TimeFrameGetPrice("C",inDaily,-1);

DD=Prec(C-YC,2);

xx=Prec((DD/YC)*100,2);

GfxSelectFont("Times New Roman", 11, 700, True );

GfxSetBkMode( colorWhite );

GfxSetTextColor(ParamColor("Color",colorYellow) );

GfxTextOut(""+DD+"  ("+xx+"%)", Hor , Ver+20 );

_SECTION_END();



_SECTION_BEGIN("5DMA - Stop & Reverse");

FS=Param("Font Size",15,11,100,1);

GfxSelectFont("Times New Roman", FS, 700, True );

GfxSetBkMode( colorWhite );

GfxSetTextColor( ParamColor("Color",colorYellow) );



Hor=Param("Horizontal Position",700,1,1200,1);

Ver=Param("Vertical Position",1,1,830,1);



TC=TimeFrameGetPrice("C",inDaily,0);

YYC=TimeFrameGetPrice("C",inDaily,-1);

DFYC=TimeFrameGetPrice("C",inDaily,-2);

DFYC1=TimeFrameGetPrice("C",inDaily,-3);

DFYC2=TimeFrameGetPrice("C",inDaily,-4);

SAR1=Prec((TC+YYC+DFYC+DFYC1+DFYC2)/5,5);

GfxTextOut("SAR="+SAR1, Hor , Ver );



SaaR = ParamToggle("SAR","Show|Hide",1);

if(SaaR==1)

{

   Plot (SAR1,"",colorYellow,styleDots|styleNoLine|styleNoRescale|styleNoTitle);

}

_SECTION_END();



_SECTION_BEGIN("Pride System");



periods = Param( "Periods", 8, 1, 200, 1 );

Ksmooth = Param( "%K avg", 4, 1, 200, 1 );

Dsmooth = Param( "%D avg", 3, 1, 200, 1 );



TimeFrameSet(in1Minute * 30);

k30 = StochK( periods , Ksmooth);

d30 = StochD( periods , Ksmooth, DSmooth );

TimeFrameRestore();



K = TimeFrameExpand(k30, in1Minute * 30);

D = TimeFrameExpand(d30, in1Minute * 30);



Hi = IIf(k > d, k, d);

Lo = IIf(k < d, k, d);



periods1 = Param( "Periods1", 8, 1, 200, 1 );

Ksmooth1 = Param( "%K avg", 4, 1, 200, 1 );

Dsmooth1 = Param( "%D avg", 3, 1, 200, 1 );



U = StochK( periods1 , Ksmooth1);

T = StochD( periods1 , Ksmooth1, DSmooth1 );



x = EMA(Close,5);

y = EMA(Close,13);



Buy=((K > D) AND (U > T) AND (U < 75 AND T < 75) AND (x>=y));

Sell=Cross(T,U) OR (T>=U);



Longa = Flip(Buy,Sell);

shrta = Flip(Sell,Buy);



Buy = ExRem(Buy,Sell);

Sell = ExRem(Sell,Buy);



Filter = Buy OR Sell;



AddTextColumn(FullName(),"Name");

AddColumn( Buy, "BUY" );

AddColumn( Sell, "SELL" );



t1= Flip(Buy,Sell);

t2= Flip(Sell,Buy);



BPrice=ValueWhen(t1 AND Ref(t1,-1)==0,C,1);

SPrice=ValueWhen(t2 AND Ref(t2,-1)==0,C,1);



Short=((D > K) AND (T > U) AND (U > 25 AND T > 25) AND (y>=x));

Cover=Cross(U,T) OR (T<=U);



Short = ExRem(Short,Cover);

Cover = ExRem(Cover,Short);



PlotShapes(IIf(Short, shapeHollowSmallCircle, shapeNone),colorYellow, 0,H, Offset=30);

PlotShapes(IIf(Cover, shapeHollowSmallSquare, shapeNone),colorBrightGreen, 0,L, Offset=-30);

GraphXSpace = 5;



AlertIf( Short, "SOUND C:\\Windows\\Media\\Ringin.wav", "Audio alert", 2 );

AlertIf( Cover, "SOUND C:\\Windows\\Media\\Ringin.wav", "Audio alert", 2 );





dist = 2*ATR(10);

dist1 = 3*ATR(10);



for( i = 0; i < BarCount; i++ )

{

    if( Buy[i] )

    {

 



        BuyStop2 = L[i]*0.9975;

        BuyTP1 = L[i]*1.005;



        GfxSetOverlayMode( mode = 0 );

        GfxSelectPen( colorBlue, 3 );

        GfxSelectSolidBrush( colorWhite );

        GfxRoundRect( 05, 210, 185, 265, 15, 15 );

        GfxSetBkMode(1);

        GfxSelectFont( "Arial", 10, 700, False );

        GfxSetTextColor( colorDarkBlue );

        GfxSetTextAlign(0);



        GfxTextOut( WriteIf(L[ i ], "Buy Above: "+L[ i ],""), 30, 215);

        GfxTextOut( WriteIf(BuyTP1, "Buy Target: "+(BuyTP1),""), 30, 230);

        GfxTextOut( WriteIf(BuyStop2, "Long SL: "+(BuyStop2),""), 30, 245);

     

    }

    if( Sell[i] )

    {

   

        SellStop2 = H[i]*1.0025;

        SellTP1 = H[i]*0.995;

     

        GfxSetOverlayMode( mode = 0 );

        GfxSelectPen( colorRed, 3 );

        GfxSelectSolidBrush( colorPink );

        GfxRoundRect( 05, 210, 185, 265, 15, 15 );

        GfxSetBkMode(1);

        GfxSelectFont( "Arial", 10, 700, False );

        GfxSetTextColor( colorYellow );

        GfxSetTextAlign(0);

        GfxTextOut( WriteIf(H[ i ], "Sell Below: "+H[ i ],""), 30, 215);

        GfxTextOut( WriteIf(SellTP1, "Short Target: "+(SellTP1),""), 30, 230);

        GfxTextOut( WriteIf(SellStop2, "Short SL: "+(SellStop2),""), 30, 245);

       

    }



}





PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-10);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-20);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-15);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=10);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=20);

PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-15);

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

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

_SECTION_END();



_SECTION_BEGIN("Signal Panel");



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



showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);

if (showsl == 1)

{Plot(s5d,"Stop Loss",colorCustom14,styleDots);}



exitlong = Cross(s5d, H);

PlotShapes(exitlong * shapeNone, colorBlack,0,H,-10);

exitshort = Cross(L, s5d);

PlotShapes(exitshort * shapeNone, colorBlack,0,L,-15);



Buy = exitshort;

Sell = exitlong;





Buy = ExRem(Buy,Sell);

Sell = ExRem(Sell,Buy);



AlertIf( Buy, "", "BUY @ " + C, 1 );

AlertIf( Sell, "", "SELL @ " + C, 2 );



for(i=BarCount-1;i>1;i--)

{

if(Buy[i] == 1)

{

entry = C[i];

sig = "BUY";

sl = s5d[i];

tar1 = entry + (entry * .0050);

tar2 = entry + (entry * .0092);

tar3 = entry + (entry * .0179);



bars = i;

i = 0;

}

if(Sell[i] == 1)

{

sig = "SELL";

entry = C[i];

sl = s5d[i];

tar1 = entry - (entry * .0050);

tar2 = entry - (entry * .0112);

tar3 = entry - (entry * .0212);





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



}





_SECTION_BEGIN("VSA by Mr.Karthik");

DTL=Param("Linear regression period",60,10,100,10);

wbf=Param("WRB factor",1.5,1.3,2.5,.1);

nbf=Param("NRB factor",0.7,0.3,0.9,0.1);

TL=LinRegSlope(MA(C, DTL),2);

 Vlp=Param("Volume lookback period",30,20,300,10);

Vrg=MA(V,Vlp);

St = StDev(Vrg,Vlp);

Vp3 = Vrg + 3*st;

Vp2 = Vrg + 2*st;;

Vp1 = Vrg + 1*st;;

Vn1 = Vrg -1*st;

Vn2 = Vrg -2*st;

rg=(H-L);

arg=Wilders(rg,30);

wrb=rg>(wbf*arg);

nrb=rg<(nbf*arg);

Vl=V<Ref(V,-1) AND V<Ref(V,-2);

upbar=C>Ref(C,-1);

dnbar=C<Ref(C,-1);

Vh=V>Ref(V,-1) AND Ref(V,-1)>Ref(V,-2);

Cloc=C-L;

x=rg/Cloc;

x1=IIf(Cloc==0,arg,x);

Vb=V>Vrg OR V>Ref(V,-1);

ucls=x1<2;

dcls=x1>2;

mcls=x1<2.2 AND x1>1.8 ;

Vlcls=x1>4;

Vhcls=x1<1.35;

j=MA(C,5);

TLL=LinRegSlope(j,40) ;

Tlm=LinRegSlope(j,15) ;

tls=LinRegSlope(j,5);

mp=(H+L)/2;



Pp1=Param("NumberOfDays",30,1,200,1);

Pp2=Param("VolOfDays",15,1,200,1);



numDays = Pp1;

dwWideSpread = 1.8;

dwNarrowSpread = 0.8;

dwSpreadMiddle = 0.5;

dwHighClose = 0.7;

dwLowClose = 0.3;



volNumDays = Pp2;

dwUltraHighVol = 2;

dwVeryHighVol = 1.75; // was 1.8

dwHighVol = 1.75; // was 1.8

dwmoderateVol = 1.10; // was 1.8

dwLowVol = 0.75; // was 0.8




upBar = C > Ref(C,-1);

downBar = C < Ref(C,-1);

spread = H-L;

avgRange = Sum(spread, numDays) / numDays;

wideRange = spread >= (dwWideSpread * avgRange);

narrowRange = spread <= (dwNarrowSpread * avgRange);

testHighClose = L + (spread * dwHighClose);

testLowClose = L + (spread * dwLowClose);

testCloseMiddle = L + (spread * dwSpreadMiddle);



upClose = C > testHighClose;

downClose = C < testLowClose;

middleClose = C >= testLowClose AND C <= testHighClose;



avgVolume = EMA(V, volNumDays);



highVolume = V > (avgVolume * dwHighVol);

moderateVol= V > (avgVolume * dwmoderateVol);

veryHighVolume = V > (avgVolume * dwVeryHighVol);

ultraHighVolume = V > (avgVolume * dwUltraHighVol);

LowVolume = V < (avgVolume * dwLowVol);






upThrustBar = downClose AND H > Ref(H,-1) AND (C == L) AND downClose AND (NOT narrowRange);

noDemandBar = narrowRange AND LowVolume AND upBar AND (NOT upClose);


noSupplyBar = narrowRange AND LowVolume AND downBar AND (V < Ref(V,-1)) AND (V < Ref(V,-2));

absorption = Ref(downbar, -1) AND Ref(highVolume, -1) AND upBar;

support = Ref(downBar,-1) AND (NOT Ref(downClose,-1)) AND Ref(highVolume,-1) AND upBar;

stoppingVolume = Ref(downBar,-1) AND Ref(highVolume,-1) AND C > testCloseMiddle AND (NOT downBar);

bullishsign=moderateVol+UpThrustBar;





weakness = upThrustBar OR noDemandBar OR (narrowRange AND (H > Ref(H,-1)) AND highVolume) OR (Ref(highVolume,-1) AND Ref(upBar,-1) AND downBar AND (H < Ref(H,-1)));





C1 = Ref(C, -1);

uc = C > C1; dc = C <= C1;

ud = C > O; dd = C <= O;



green = 1; blue = 2; yellow = 3; red = 4; white = 5;

VType = IIf(ud, IIf(uc, green, yellow), IIf(dd,IIf(dc, red, blue), white));





gv = IIf(VType == green, V, 0);



yv = IIf(VType == yellow, V, 0);



rv = IIf(VType == red, V, 0);



bv = IIf(VType == blue, V, 0);



uv = gv + bv; uv1 = Ref(uv, -1);

dv = rv + yv; dv1 = Ref(dv, -1);





VolPer = Param("Adjust Vol. MA per.", 34, 1, 255, 1);

ConvPer = Param("Adjust Conv. MA per.", 9, 1, 255, 1);





MAuv = TEMA(uv, VolPer ); mauv1 = Ref(mauv, -1);

MAdv = TEMA(dv, VolPer ); madv1 = Ref(madv, -1);

MAtv = TEMA(V, VolPer );




OscillatorOnly = Param("Show Oscillator Only", 0, 0, 1, 1);

CompareBullVolume = Param("Show Bull Level", 1, 0, 1, 1);

if(CompareBullvolume AND !OscillatorOnly){


}



CompareBearVolume = Param("Show Bear Level", 1, 0, 1, 1);

if(CompareBearVolume AND !OscillatorOnly){


}




bullvolume = Param("Show Bull Volume", 1, 0, 1, 1);

bearvolume = Param("Show Bear Volume", 1, 0, 1, 1);

totalvolume = Param("Show Total Volume", 1, 0, 1, 1);




bearToFront = Param("Show Bear Vol in Front", 0, 0, 1, 1);

if(bearToFront AND !OscillatorOnly){


}

if(bullvolume AND !OscillatorOnly){


}

if(bearvolume AND !OscillatorOnly){



}

if(totalVolume AND !OscillatorOnly){



}

if(bullvolume AND !OscillatorOnly){



}

if(bearvolume AND !OscillatorOnly){



}





Converge = (TEMA(MAuv - MAdv, ConvPer));

Converge1 = Ref(Converge, -1);

ConvergeUp = Converge > Converge1;

ConvergeOver = Converge > 0;

rising = ConvergeUp AND ConvergeOver;

falling = !ConvergeUp AND ConvergeOver;




convergenceOscillator = Param("Show Oscillator", 0, 0, 1, 1);

if(convergenceOscillator OR OscillatorOnly){


}





riseFallColor = IIf(rising, 14,15);




riseFallShadows = Param("Show RiseFallShadows", 0, 0, 1, 1);

if(riseFallShadows){


}

_SECTION_END();



_SECTION_BEGIN("GANN Levels");




Op=TimeFrameGetPrice("O",inDaily,0);



order=Param("Order",0.15,0.001,0.1,sincr = 0);



level1 = 1.25;

level2 = 2.50;

level3 = 3.33;

level4 = 5;

level5 = 6.66;

level6 = 7.5;

level7 = 10;



level1 = level1 * order;

level2 = level2 * order;

level3 = level3 * order;

level4 = level4 * order;

level5 = level5 * order;

level6 = level6 * order;

level7 = level7 * order;



bAboveI=(sqrt(Op)+level1)*(sqrt(Op)+level1);

bAbove = round(bAboveI);                    



sBelowI=(sqrt(Op)-level1)*(sqrt(Op)-level1);

sBelow = round(sBelowI);



Sstop= bAbove ;

Bstop= sBelow ;






BTgt1 = round((sqrt(Op)+level2)*(sqrt(Op)+level2));

BTgt2 = round((sqrt(Op)+level3)*(sqrt(Op)+level3));

BTgt3 = round((sqrt(Op)+level4)*(sqrt(Op)+level4));

BTgt4 = round((sqrt(Op)+level5)*(sqrt(Op)+level5));

BTgt5 = round((sqrt(Op)+level6)*(sqrt(Op)+level6));

BTgt6 = round((sqrt(Op)+level7)*(sqrt(Op)+level7));






STgt1 = round((sqrt(Op)-level2)*(sqrt(Op)-level2));

STgt2 = round((sqrt(Op)-level3)*(sqrt(Op)-level3));

STgt3 = round((sqrt(Op)-level4)*(sqrt(Op)-level4));

STgt4 = round((sqrt(Op)-level5)*(sqrt(Op)-level5));

STgt5 = round((sqrt(Op)-level6)*(sqrt(Op)-level6));

STgt6 = round((sqrt(Op)-level7)*(sqrt(Op)-level7));



GfxSetBkMode( 1 );

GfxSelectFont("Arial", 9, 900 );

GfxSetTextColor( colorYellow );

GfxSelectPen( colorBlack, 1, 0) ;

GfxSelectSolidBrush( colorBlue );



BTgtext = "Buy Targets : " + NumToStr(btgt1,1.2,False) + " - " + NumToStr(btgt2,1.2,False) + " - " + NumToStr(btgt3,1.2,False)+ " - " + NumToStr(btgt4,1.2,False) + " - " + NumToStr(btgt5,1.2,False) + " - " + NumToStr(btgt6,1.2,False);

STgtext = "Short Targets : " + NumToStr(stgt1,1.2,False) + " - " + NumToStr(stgt2,1.2,False) + " - " + NumToStr(stgt3,1.2,False)+ " - " + NumToStr(stgt4,1.2,False) + " - " + NumToStr(stgt5,1.2,False) + " - " + NumToStr(stgt6,1.2,False);




GfxTextOut("Buy Above : " + WriteIf(TimeNum()>092900, NumToStr(bAbove,1.2,False) + " SL : " + NumToStr(sBelow,1.2,False),"Waiting for Signal"), 10, 270);

GfxTextOut(WriteIf(TimeNum()>092900,BTgtext,""), 10, 285);



GfxSetBkMode( 1 );

GfxSelectFont("Arial", 9, 900 );

GfxSetTextColor( colorBlack );

GfxSelectPen( colorBlack, 1, 0) ;

GfxSelectSolidBrush( colorBlue );



GfxTextOut("Short Below : " + WriteIf(TimeNum()>092900, NumToStr(sBelow,1.2,False) + " SL : " + NumToStr(bAbove,1.2,False),"Waiting for Signal"), 10, 305);

GfxTextOut(WriteIf(TimeNum()>092900,STgtext,""), 10, 320);



BuySignal = (Cross(H,babove)OR Cross(C,babove) OR (H>babove AND L<=babove)) AND Op<babove ;

ShortSignal = (Cross(Sbelow,L) OR Cross(Sbelow,C) OR (H>=sbelow AND L<sbelow))AND Op>sbelow ;



BuySignal = ExRem(BuySignal,ShortSignal);

ShortSignal = ExRem(ShortSignal,BuySignal);



ShortProfitStop= (STgt1 AND L<=Stgt1 AND C>Stgt1) OR (STgt2 AND L<=Stgt2 AND C>Stgt2) OR (STgt3 AND L<=Stgt3 AND C>Stgt3) OR (STgt4 AND L<=Stgt4 AND C>Stgt4) OR (STgt5 AND L<=Stgt5 AND C>Stgt5) OR (STgt6 AND L<=Stgt6 AND C>Stgt6);

BuyProfitStop= (Btgt1 AND H>=btgt1 AND C<Btgt1) OR (Btgt2 AND H>=Btgt2 AND C<btgt2) OR (Btgt3 AND H>=Btgt3 AND C<btgt3) OR (Btgt4 AND H>=Btgt4 AND C<btgt4) OR (Btgt5 AND H>=Btgt5 AND C<btgt5) OR (Btgt6 AND H>=Btgt6 AND C<btgt6);



SetOption("MaxOpenPositions", 1 );

SetPositionSize(100,spsShares);



AlertIf( Buy, "", "BUY @ " + C, 1 );

AlertIf( Sell, "", "SELL @ " + C, 2 );



numbars = LastValue(Cum(Status("barvisible")));

hts  = -33.5;



gl = ParamToggle("GANN Levels","Show|Hide",0);

if(gl==1) {



Plot(sstop,"BUY Zone",colorDarkGreen,styleDots|styleNoLine|styleNoRescale|styleNoTitle );

Plot(bstop,"SELL Zone",colorDarkRed,styleDots|styleNoLine|styleNoRescale|styleNoTitle );



Plot(BTgt1,"BUY TGT1",colorOrange,styleDots|styleNoLine|styleNoRescale|styleNoTitle );

Plot(BTgt2,"BUY TGT2",colorOrange,styleDots|styleNoLine|styleNoRescale|styleNoTitle );

Plot(BTgt3,"BUY TGT3",colorOrange,styleDots|styleNoLine|styleNoRescale|styleNoTitle );

Plot(BTgt4,"BUY TGT4",colorOrange,styleDots|styleNoLine|styleNoRescale|styleNoTitle );

Plot(BTgt5,"BUY TGT5",colorOrange,styleDots|styleNoLine|styleNoRescale|styleNoTitle );

Plot(BTgt6,"BUY TGT6",colorOrange,styleDots|styleNoLine|styleNoRescale|styleNoTitle );



Plot(STgt1,"SELL TGT1",colorLime,styleDots|styleNoLine|styleNoRescale|styleNoTitle);

Plot(STgt2,"SELL TGT1",colorLime,styleDots|styleNoLine|styleNoRescale|styleNoTitle);

Plot(STgt3,"SELL TGT1",colorLime,styleDots|styleNoLine|styleNoRescale|styleNoTitle);

Plot(STgt4,"SELL TGT1",colorLime,styleDots|styleNoLine|styleNoRescale|styleNoTitle);

Plot(STgt5,"SELL TGT1",colorLime,styleDots|styleNoLine|styleNoRescale|styleNoTitle);

Plot(STgt6,"SELL TGT1",colorLime,styleDots|styleNoLine|styleNoRescale|styleNoTitle);



PlotText(" BUY Zone" ,    LastValue(BarIndex())-(numbars/Hts), LastValue(sstop,1), colorDarkGreen);

PlotText(" SELL Zone" ,    LastValue(BarIndex())-(numbars/Hts), LastValue(bstop,1), colorDarkRed);



PlotText(" BUY TGT1" ,    LastValue(BarIndex())-(numbars/Hts), LastValue(BTgt1,1), colorOrange);

PlotText(" BUY TGT2" ,    LastValue(BarIndex())-(numbars/Hts), LastValue(BTgt2,1), colorOrange);

PlotText(" BUY TGT3" ,    LastValue(BarIndex())-(numbars/Hts), LastValue(BTgt3,1), colorOrange);

PlotText(" BUY TGT4" ,    LastValue(BarIndex())-(numbars/Hts), LastValue(BTgt4,1), colorOrange);

PlotText(" BUY TGT5" ,    LastValue(BarIndex())-(numbars/Hts), LastValue(BTgt5,1), colorOrange);

PlotText(" BUY TGT6" ,    LastValue(BarIndex())-(numbars/Hts), LastValue(BTgt6,1), colorOrange);



PlotText(" SELL TGT1" ,    LastValue(BarIndex())-(numbars/Hts), LastValue(STgt1,1), colorLime);

PlotText(" SELL TGT2" ,    LastValue(BarIndex())-(numbars/Hts), LastValue(STgt2,1), colorLime);

PlotText(" SELL TGT3" ,    LastValue(BarIndex())-(numbars/Hts), LastValue(STgt3,1), colorLime);

PlotText(" SELL TGT4" ,    LastValue(BarIndex())-(numbars/Hts), LastValue(STgt4,1), colorLime);

PlotText(" SELL TGT5" ,    LastValue(BarIndex())-(numbars/Hts), LastValue(STgt5,1), colorLime);

PlotText(" SELL TGT6" ,    LastValue(BarIndex())-(numbars/Hts), LastValue(STgt6,1), colorLime);



}



_SECTION_END();



_SECTION_BEGIN("Ribbon");

no=Param( "Swing", 10, 1, 55 );

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

tsl=IIf(avn==1,sup,res);



Plot( 2, "Ribbon",IIf(C>tsl,colorBlue,colorRed),styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

_SECTION_END();



_SECTION_BEGIN("BREAK OUTS");




CodeName = "Joy's Breakouts";

SetFormulaName("Joy's Breakouts");





SetChartOptions(0,chartShowArrows | chartShowDates | chartWrapTitle);

if (ParamToggle("Tooltip shows", "All Values|Only Prices"))

{

  ToolTip = StrFormat("Open: %g\nHigh:  %g\nLow:   %g\nClose:  %g (%.1f%%) \nVolume: " + NumToStr(V, 1), O, H, L, C, SelectedValue(ROC(C, 1)));

}



space = Param("Space on Chart", 20,  - 15, 50, 1);

GraphXSpace = space;





H0 = H;

L0 = L;

C0 = C;

O0 = O;



Lookback = Param("LookBack", 10, 10, 50, 1);
shift = Param("Shift", 5, 1, 50, 1);

x0 = LastValue(Cum(1));

x1 = x0 - shift;

H = Ref(H,  - shift + 1);

L = Ref(L,  - shift + 1);

H1 = LastValue(Ref(HHV(H, Lookback),  - 1));

L1 = LastValue(Ref(LLV(L, Lookback),  - 1));



Plot(H1, "H1", colorYellow);

Plot(L1, "L1", colorYellow);



H = H0;

L = L0;

C = C0;

O = O0;



up = Cross(H, H1)AND Cum(1) > x1;

dn = Cross(L1, L)AND Cum(1) > x1;



Plot(C, "Close", IIf(Cum(1) > x1 - Lookback AND Cum(1) <= x1, colorBlue, IIf(Up, colorBrightGreen, IIf(Dn, colorRed, IIf(C > O, colorGreen, colorRed)))), 64);

PlotShapes(shapeDownArrow *(Cum(1) == x1 + 1), colorBlue);




TRIGGER = ParamToggle("Trigger ", "CLOSE|HIGH OR LOW");





XH1 = Cross(C, H1);

XL1 = Cross(L1, C);

XH2 = Cross(H, H1);

XL2 = Cross(L1, L);



if (TRIGGER == 0)

{

  Buy = XH1;

  Sell = XL1;

}



else

{

  Buy = XH2;

  Sell = XL2;

}





TradeDisplay = ParamToggle("Remove Extra Trades?", "No|Yes");



if(TradeDisplay != 0){

   Buy = ExRem(Buy, Sell);

  Sell = ExRem(Sell, Buy);
}



Filter = Buy OR Sell;

Action = WriteIf(Buy, "BUY", WriteIf(Sell, "SELL", "   "));



AddTextColumn(IndustryID(1), "Industry Sector  ", 30.0, colorGold, colorYellow);

AddColumn(C, "Last ", 2.2, colorWhite, colorGold);

AddTextColumn(Action, "Action", 8.0, IIf(XH1, colorDarkGreen, colorDarkRed), colorWhite);

AddColumn(IIf(XH1, H1, L1), "BREAKOUT LEVEL", 3.2, colorYellow, IIf(XH1, colorDarkGreen, colorDarkRed));



_SECTION_END();





_SECTION_BEGIN("Volume At Price");

PlotVAPOverlay(Param("Lines", 1000, 100, 1000, 10), Param("Width", 15, 1, 100, 1), ParamColor("Color", colorGold), ParamToggle("Side", "Left|Right", 1) | 4 *ParamToggle("Z-order", "On top|Behind", 1));



_SECTION_END();



_SECTION_BEGIN("Title");



dec = (Param("Decimals",2,0,7,1)/10)+1;



TimeFrameSet(inDaily);

DayH = LastValue(H);

DayL = LastValue(L);

TimeFrameRestore();



if( Status("action") == actionIndicator )

(Title = EncodeColor(colorYellow)+ "Pride System" + "     " + EncodeColor(55)+  Name() + "     " + EncodeColor(32) + Date() + "      " + EncodeColor(5) + "{{INTERVAL}}  " + EncodeColor(55)+ "    Volume = "+ EncodeColor(52)+ WriteVal(V,1) + "\n" +

   EncodeColor(55)+ "Open = "+ EncodeColor(52)+ WriteVal(O,dec) +

   EncodeColor(55)+ "     High = "+ EncodeColor(5) + WriteVal(H,dec) +

   EncodeColor(55)+ "      Low = "+ EncodeColor(32)+ WriteVal(L,dec) +

   EncodeColor(55)+ "    Close = "+ EncodeColor(52)+ WriteVal(C,dec) + "\n" +

   EncodeColor(55)+ "Today`s High= " + EncodeColor(colorBlue) + DayH + EncodeColor(55)+ "     Today`s Low= " + EncodeColor(colorBlue) + DayL +"\n"+



EncodeColor(colorPink)+"----------------------------------------"

+"\n"+EncodeColor(07)+"Volume: "+WriteIf(V>Vp2,EncodeColor(colorLime)+"Very High",WriteIf(V>Vp1,EncodeColor(colorLime)+" High",WriteIf(V>Vrg,EncodeColor(colorLime)+"Above Average",

WriteIf(V<Vrg AND V>Vn1,EncodeColor(colorRed)+"Less than Average",WriteIf(V<Vn1,EncodeColor(colorRed)+"Low","")))))



+"\n"+EncodeColor(colorYellow)+"Spread: "+WriteIf(rg >(arg*2),EncodeColor(colorLime)+" Wide",WriteIf(rg>arg,EncodeColor(colorLime)+" Above Average",EncodeColor(colorRed)+" Narrow"))



+"\n"+(EncodeColor(colorYellow)+"Close: ")+WriteIf(Vhcls,EncodeColor(colorLime)+"Very High",WriteIf(ucls,EncodeColor(colorLime)+"High",WriteIf(mcls,EncodeColor(colorYellow)+"Mid",

WriteIf(dcls,EncodeColor(colorRed)+"Down","Very Low"))))



+"\n"+EncodeColor(colorYellow) + "Zone : " +WriteIf(rising , EncodeColor(colorBrightGreen) + "Accumulation",WriteIf(falling , EncodeColor(colorCustom12) + "Distirbution",EncodeColor(colorAqua) + "Flat")) + " "

+"\n"+

EncodeColor(colorYellow) + "Status : " +

WriteIf(Weakness , EncodeColor(colorRed) + "Weak",

WriteIf(stoppingVolume , EncodeColor(colorCustom12) + "StoppingVol",

WriteIf(noSupplyBar , EncodeColor(colorLightOrange) + "NoSupply",

WriteIf(support , EncodeColor(colorLightBlue) + "SupportVol",

WriteIf(noDemandBar , EncodeColor(colorPink) + "NoDemand",

WriteIf(absorption, EncodeColor(colorSkyblue) + "Absorption",

WriteIf(upThrustBar, EncodeColor(colorBlue) + "Upthrust",

WriteIf(bullishsign, EncodeColor(colorPaleGreen) + "STRONG",

EncodeColor(colorTan) + "Neutral")))))))) + " "

+"\n"+EncodeColor(colorPink)+"----------------------------------------"+"\n"+



   EncodeColor(colorLime)+WriteIf (Buy , "GO LONG / Reverse Signal at "+C+"  ","")+

   EncodeColor(colorRed)+WriteIf (Sell , "EXIT LONG / Reverse Signal at "+C+"  ","")+"\n"+

   EncodeColor(colorWhite)+WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BPrice)+"","")+

   WriteIf(Buy  , "Total Profit/Loss for the Last trade Rs."+(SPrice-C)+"","")+"\n"+

   WriteIf(Longa AND NOT Buy, "Trade : Long - Entry price Rs."+(BPrice),"")+

   WriteIf(shrta AND NOT Sell, "Trade : Short - Entry price Rs."+(SPrice),"")+"\n"+

   WriteIf(Longa AND NOT Buy, "Current Profit/Loss Rs."+(C-BPrice)+"","")+

   WriteIf(shrta AND NOT Sell, "Current Profit/Loss Rs."+(SPrice-C)+"",""));



_SECTION_END();



_SECTION_BEGIN("Linear Regression");

Lrc = ParamToggle("Linear Regression Channel","Show|Hide",0);

if(Lrc==1) {




P = ParamField("Price field",-1);



Length = 150;



Daysback = Param("Period for Liner Regression Line",Length,1,240,1);

shift = Param("Look back period",0,0,240,1);




x = Cum(1);

lastx = LastValue( x ) - shift;

aa = LastValue( Ref(LinRegIntercept( p, Daysback), -shift) );

bb = LastValue( Ref(LinRegSlope( p, Daysback ), -shift) );

y = Aa + bb * ( x - (Lastx - DaysBack +1 ) );






LRColor = ParamColor("LR Color", colorCycle );

LRStyle = ParamStyle("LR Style");



LRLine =  IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );



LRStyle = ParamStyle("LR Style");

Angle = Param("Angle", 0.05, 0, 1.5, 0.01);


LRLine = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );



Pi = 3.14159265 * atan(1); // Pi

SlopeAngle = atan(bb)*(180/Pi);



LineUp = SlopeAngle > Angle;

LineDn = SlopeAngle < - Angle;



if(LineUp)

{

Plot(LRLine, "Lin. Reg. Line Up", IIf(LineUp, colorBrightGreen, colorWhite), LRStyle);

}

else

{

Plot(LRLine, "Lin. Reg. Line Down", IIf(LineDn, colorDarkRed, colorWhite), LRStyle);

}






SDP = Param("Standard Deviation", 1.5, 0, 6, 0.1);

SD = SDP/2;



width = LastValue( Ref(SD*StDev(p, Daysback),-shift) );
SDU = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width , Null ) ;

SDL = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width , Null ) ;



SDColor = ParamColor("SD Color", colorCycle );

SDStyle = ParamStyle("SD Style");



Plot( SDU , "\nUpper Lin Reg", colorWhite,SDStyle );
Plot( SDL , "Lower Lin Reg", colorWhite,SDStyle );




SDP2 = Param("2d Standard Deviation", 2.0, 0, 6, 0.1);

SD2 = SDP2/2;



width2 = LastValue( Ref(SD2*StDev(p, Daysback),-shift) );
SDU2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width2 , Null ) ;

SDL2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width2 , Null ) ;



SDColor2 = ParamColor("2 SD Color", colorCycle );

SDStyle2 = ParamStyle("2 SD Style");



Plot( SDU2 , "Upper Lin Reg", colorWhite,SDStyle2 );
Plot( SDL2 , "Lower Lin Reg", colorWhite,SDStyle2 );

Trend = IIf(LRLine > Ref(LRLine,-1),colorGreen,colorRed);


Plot( LRLine , "LinReg", Trend, LRSTYLE );



}

_SECTION_END();

Sunday 24 August 2014

Pivot High Pivot Low for Amibroker (AFL)



/*This indicator is useful in Daily, Weekly n Intraday charts to find top n bottoms.  
Very useful for Investment as well Intraday trading.  (Plugin Required – download below link www.mediafire.com/?znmwud2jdwt[/url] )  
Copy paste JurikLib.dll and kpami.dll */

_SECTION_BEGIN("Pivot High Pivot Low");


//user parameters
parmPlotScoreCard = ParamToggle("Plot KPScoreCard", "No|Yes", 1);
parmPlotA900AutoStop = ParamToggle("Plot A900/AutoStop", "No|Yes", 1);
parmA900Color = ParamColor("A900 Color", colorWhite);
parmA900Style = ParamStyle("A900 Style", styleLine, maskAll);
parmAutoStopColor = ParamColor("AutoStop Color", colorYellow);
parmAutoStopStyle = ParamStyle("AutoStop Style", styleLine, maskAll);
parmPPTextColor = ParamColor("PP Text color", colorBlack);
parmPPTrndColorUp = ParamColor("PP Trend Up color", ColorRGB(167,224,243) );
parmPPTrndColorDn = ParamColor("PP Trend Dwn color", ColorRGB(255,192,203) );
parmPPTextOffSet = Param("PP OffSet", 0.60, 0.40, 1.5, 0.1);
parmTickMultipler = Param("M/W tick allowance", 1, 0, 10, 1);
parmA900AutoStopX = ParamToggle("Plot A900/AutoStop Cross", "No|Yes");
parmA900AutoStopColorX = ParamColor("A900/AutoStop Cross Color", colorBlack);
ParmSCThreshold = Param("ScoreCard Threshold", 3, 1, 9, 1);
parmVoice = ParamToggle("Voice 123 Setups", "No|Yes", 0);
parmAlert = ParamToggle("Alert 123 Setups", "No|Yes", 0);
parmPivotPop = ParamToggle("PivotPop", "No|Yes", 1);
parmBarCancel = Param("Bar Cancel", 7, 1, 20, 1);
parmWaterLevelColor = ParamColor("WalterLevel Color", ColorRGB(127,255,212));
parmWaterLevelStyle = ParamStyle("WaterLevel Style", styleLine, maskAll);
parmBBPeriod = Param("Bollinger Band Period", 10, 2, 30, 1);
parmBBSD = Param("bollinger Band SD", 0.8, 0.2, 3.0);
ParmPlotPPIndicators = ParamToggle("Plot Pivot Pop indicators", "No|Yes", 0);
parmBBColor = ParamColor("BBands Color", colorBlack);
parmBBStyle = ParamStyle("BBands Style", styleLine, maskAll);

ParmDebug = ParamToggle("Debug", "No|Yes", 0);

// constants
_N(PaneName = Name() + Interval(2)+ _SECTION_NAME());
_N(NewBarName = "NewBar" + PaneName);

//functions
function NewBarP()
{
PrevDT = StaticVarGet( NewBarName);
DT = LastValue(DateTime());
StaticVarSet( NewBarName,DT);
return DT != PrevDT;
}
function MRoundP(Number, Multiple )
{
if(Multiple == 0 )
{

xMultiple = 0.01; }
else
{
xMultiple = Multiple;
}
Divided = Number / xMultiple;
intDivided = int(Divided);
intDivided = intDivided + round(Divided - intDivided);
return intDivided * xMultiple;
}

//miscellaneous setups
ObjAB = CreateObject("Broker.Application");
ticker = objAB.Stocks(Name() );
if(ticker.TickSize == 0)
{
TickValue = 0.01; //set TickValue to a penney
}
else
{
TickValue = ticker.TickSize; // use Tick Size for this symbol
}
NewBarSignal = NewBarP();
// KP Indicators
KPA900 = E_TSKPA900(Close);
KPAutoStop = E_TSKPAUTOSTOP(High,Low,Close);
Ctmpl = E_TSKPCOLORTMPL(Open,High,Low,Close,Volume); //ScoreCard
KPScoreCard = 0;
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd0 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd1 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd2 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd3 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd4 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd5 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd6 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd7 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd8 > 0, 1, -1);

if(parmDebug == 1)
{
printf("a900: %0.6f% \nAutoStop: %0.6f%\nScoreCard: %0.0f%\n", KPA900, KPAutoStop, KPScoreCard);
}
if(parmPlotScoreCard == 1)
{
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g% (%0.4f%) {{VALUES}}", O, H, L, C, SelectedValue( C - Ref(C, -1)) ));
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.2f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
}
Color = IIf(KPScoreCard >= parmSCThreshold, colorBlue, IIf(KPScoreCard <= -parmSCThreshold, colorRed, colorYellow) );
Plot( C, "Close", Color , styleNoTitle | ParamStyle("OHLC Style",styleBar | styleThick) | GetPriceStyle() );
}
//user want A900/AutoStop plotted
if(parmPlotA900AutoStop == 1)
{
Plot(KPA900, "A900", parmA900Color, parmA900Style);
Plot(KPAutoStop, "AutoStop", parmAutoStopColor, parmAutoStopStyle);
}
// find A900/AutoStop cross over/under with ScoreCard confirmation.
XOUp = (KPA900 > KPAutoStop) AND (KPScoreCard >= parmSCThreshold); // New Pivot Low
XODn = (KPA900 < KPAutoStop) AND (KPScoreCard <= -parmSCThreshold); // New Pivot High
if(parmDebug == 1)
{
printf(WriteIf(XOUp, "before= XOUp: True", "before= XOUp: False") + WriteIf(XODn, " XODn: True\n", " XODn: False\n") );
}
//remove duplicate signals
XOUp = ExRem(XOUp, XODn);
XODn = ExRem(XODn, XOUp);

if(parmDebug == 1)
{
printf(WriteIf(XOUp, "after= XOUp: True", "after= XOUp: False") + WriteIf(XODn, " XODn: True\n", " XODn: False\n") );
}
//find the current Pivot Points - PL and PH
//remember XOUp = 1 means a PL and XODn =1 means a PH
PLBars = IIf(XOUp, LowestSinceBars(XODn, L ,1), 0); //find the bar that produced the Lowest Low
PHBars = IIf(XODn, HighestSinceBars(XOUp, H, 1),0); //find the bar that produced the Highest High
//PLPrice = IIf(XOUp, Ref(L, -PLBars), 0);
//PHPrice = IIf(XODn, Ref(H, -PHBars),0);
PLPrice = Ref(L, -PLBars);
PHPrice = Ref(H, -PHBars);

//keep track of the previous Pivot Points
PrevPLBars = Ref(BarsSince(XOUp), -1) +1;
PrevPHBars = Ref(BarsSince(XODn), -1) +1;
PrevPLPrice = Ref(PLPrice, -prevPLBars);
PrevPHPrice = Ref(PHPrice, -PrevPHBars );
PivotsCloseEnough = TickValue * parmTickMultipler;
PLDifference = MroundP(PLPrice - PRevPLPrice, ticker.TickSize);
PHDifference = MroundP(PHPrice - PrevPHPrice, ticker.TickSize);
PPTrend = IIf(XOUp AND (PLDifference > PivotsCloseEnough) AND PrevPHPrice > PrevPLPrice AND PRevPHPrice > PLPrice, 1,
IIf(XOUp AND (PLDifference < - PivotsCloseEnough) AND PRevPHPrice > PrevPLPrice AND PrevPHPrice > PLPrice, -1,
IIf(XODn AND (PHDifference > PivotsCloseEnough) AND PrevPLPrice < PrevPHprice AND PrevPLPrice < PHPrice, 1,
IIf(XODn AND (PHDifference < -PivotsCloseEnough) AND PrevPLPrice < PrevPHPrice AND PrevPLPrice < PHPrice, -1,
IIf(XOUp AND (abs(PLDifference) <= PivotsCloseEnough) AND PrevPHPrice > PrevPLPrice AND PRevPHPrice > PLPrice, 2,
IIf(XODn AND (abs(PHDifference) <= PivotsCloseEnough) AND PrevPLPrice < PrevPHPrice AND PrevPLPrice < PHPrice, -2, 0)))) ));
if(ParmDebug)
{
printf("Current PH Bar: %g% /Price: %g%\n", PHBars, PHPrice);
printf("Current PL Bar: %g% /Price: %g%\n", PLBars, PLPrice);
printf("Previous PH Bar: %g% /Price: %g%\n", PrevPHBars, PrevPHPrice);
printf("Previous PL Bar: %g% /Price: %g%\n", PrevPLBars, PrevPLPrice) ;
printf("PP Trend: %g%\n", PPTrend);
printf("PHPrice - PrevPHPrice: %g%\nPLPrice - PrevPLPrice: %g%\nPivotsCloseEnough: %g%", PHDifference, PLDifference, PivotsCloseEnough);
}
//PLot pivots as text
dist = parmPPTextOffSet * ATR(10);
//for( i = 0; i < BarCount -1; i++)
for( i = 0; i < BarCount ; i++)
{
if(XOUp[i ] == 1 AND abs(PPTrend[i]) != 2) //cross up -plot the Pivot Low
{
PlotText("PL", i - PLBars[i], PLPrice[i] - dist[i] , parmPPTextColor, IIf(PPTrend[i] == 1, parmPPTrndColorUp, IIf(PPTrend[i] == -1, parmPPTrndColorDn, colorYellow) ));
}
if(XODn[i ] == 1 AND abs(PPTrend[i]) != 2) //cross down - plot the pivot high
{
PlotText("PH", i - PHBars[i], PHPrice[i] + dist[i], parmPPTextColor, IIf(PPTrend[i] == 1, parmPPTrndColorUp, IIf(PPTrend[i] == -1, parmPPTrndColorDn, colorYellow) ));
}
if(XOUp[i ] == 1 AND (PPTrend[i]) == 2) // the Pivot Low is a W Bottom
{
PlotText("PW", i - PLBars[i], PLPrice[i] - dist[i] , parmPPTextColor, colorYellow) ;
}
if(XODn[i ] == 1 AND PPTrend[i] == -2) //cross down - pivot high is a M Top
{
PlotText("PM", i - PHBars[i], PHPrice[i] + dist[i], parmPPTextColor, colorYellow) ;
}
} //end For
_SECTION_END();