Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

PIVOT TRADING SYSTEM for Amibroker (AFL)

Copy & Paste Friendly
_SECTION_BEGIN("Pivot Trading System");
// User defined parameters. 
GraphXSpace = 10; //defines how much extra space should be added above and below graph line (in percent).
dist = 0.25*ATR(10); 
Capital=Param("Total capital",100000,10000,1000000,1000);
drawdown=Param("Max. loss per trade as % of Capital", 1.0,0.5,25.0,0.1);
room=Param("Room for S/L as % of Pivot value",0.001,0.001,0.02,0.001);
PH= ValueWhen(
(Ref(H,-2) > Ref(H, -4)) AND
(Ref(H,-2) > Ref(H, -3)) AND
(Ref(H,-2) > Ref(H, -1)) AND
(Ref(H,-2) > H), Ref(H,-2));
PL= ValueWhen(
(Ref(L,-2) <= Ref(L, -4)) AND
(Ref(L,-2) <= Ref(L, -3)) AND
(Ref(L,-2) <= Ref(L, -1)) AND
(Ref(L,-2) <= L), Ref(L,-2));
phfilter=PH+(room*PH);
plfilter=PL-(room*PL);
Plot(Ref(PH,2), "UpPivot", ParamColor("UpPivot Color",colorRed), styleDashed);
Plot(Ref(PL,2), "DownPivot",ParamColor("DownPivot Color",colorGreen), styleDashed);
Plot(Ref(Phfilter,2), "Upfilter", ParamColor("upfilter Color",colorRed), styleLine);
Plot(Ref(Plfilter,2), "Downfilter",ParamColor("dnfilter Color",colorGreen), styleLine);
for (a=4;a<BarCount;a++)
{
if ((H[a-2] >= H[a-4]) AND
(H[a-2] >= H[a-3]) AND
(H[a-2] >= H[a-1]) AND
(H[a-2] >= H[a]))
PlotText("PH", a-2, H[a-2], colorGreen);
if ((L[a-2] <= L[a-4]) AND
(L[a-2] <= L[a-3]) AND
(L[a-2] <= L[a-1]) AND
(L[a-2] <= L[a]))
PlotText("PL", a-2, L[a-2]-dist[a-2], colorRed);
}
//Condition for buy : Enter when Close crosses latest pivot high.
Buy = C> (PH+(room*PH));
initialStopBuy=Ref(PL,2)-(Ref(PL,2)*room/100);
trailStopBuy=IIf(C>PH,Ref(initialStopBuy,-1),initialStopBuy);
newStopBuy=trailStopBuy;
BuyLimitCapital=int(Capital/C);
SLbuy=round(C-initialStopBuy);
BuyLimitSL=int((Capital*drawdown)/(100*SLbuy));
//Condition for sell : Exit when previous pivot low is cracked.
Sell = C< (PL-(room*PL));
Buy = ExRem(Buy,Sell);
Sell= ExRem(Sell,Buy);
Short = Sell;
Cover = Buy;
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ),0, IIf( Buy, Low, High ) );
_SECTION_END();
_SECTION_BEGIN("Macd coloured price");
//============================================candle sticks=======================
a = Param("fast macd period",3,1,100,1);
b = Param("slow macd period",34,1,100,1);
Up_MACD_TRIX = MACD( a, b ) > Ref(MACD(a,b),-1);
Down_MACD_TRIX = MACD( a, b ) < Ref(MACD(a,b),-1);
Colormacd = IIf(Up_MACD_TRIX,colorLime,IIf(Down_MACD_TRIX,colorRed,colorCustom12)); 
PlotOHLC( Open, High, Low, Close, "", Colormacd, styleBar ); 
_SECTION_END();

_SECTION_BEGIN("Background_Setting");
SetChartBkGradientFill( ParamColor("BgTop", colorCustom14),
ParamColor("BgBottom", colorLightGrey),ParamColor("titleblock",colorYellow)); 
_SECTION_END();

// Paste the code below to your price chart somewhere and green ribbon means both
// both MACD and ADX trending up so if the red ribbon shows up the MACD and the ADX 
// are both trending down.
_SECTION_BEGIN("trending ribbon");
uptrend=PDI()>MDI()AND Signal()<MACD();
downtrend=MDI()>PDI()AND Signal()>MACD();
Plot( 2, /* defines the height of the ribbon in percent of pane width*/"ribbon",
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, 0 )), /* choose color */styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();
_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",30,30,100,1);
GfxSelectFont("Arial", FS, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorBlack) );
Hor=Param("Horizontal Position",750,800,800,800);
Ver=Param("Vertical Position",27,27,27,27);
GfxTextOut(""+C,Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Arial", 12, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorYellow) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor+5, Ver+45 );
_SECTION_END();

///////////////////////////candle stick reader
_SECTION_BEGIN("Candle Identification");
O1 = Ref(O,-1);O2 = Ref(O,-2);
H1 = Ref(H,-1);H2 = Ref(H,-2);
L1 = Ref(L,-1);L2 = Ref(L,-2);
C1 = Ref(C,-1);C2 = Ref(C,-2);
function CandlePattern(P)
{
global PatternName;
if(P == 0) { PatternName = "NearDoji"; Pv = (abs(O-C)<= ((H-L)*0.1)); }
else if(P == 1) { PatternName = "BlackCandle"; Pv = (O>C); }
else if(P == 2) { PatternName = "LongBlackCandle"; Pv = (O>C AND
(O-C)/(.001+H-L)>.6); }
else if(P == 3) { PatternName = "SmallBlackCandle"; Pv = ((O>C) AND
((H-L)>(3*(O-C)))); }
else if(P == 4) { PatternName = "WhiteCandle"; Pv = (C>O); }
else if(P == 5) { PatternName = "LongWhiteCandle"; Pv = ((C>O) AND
((C-O)/(.001+H-L)>.6)); }
else if(P == 6) { PatternName = "SmallWhiteCandle"; Pv = ((C>O) AND
((H-L)>(3*(C-O)))); }
else if(P == 7) { PatternName = "BlackMaubozu"; Pv = (O>C AND H==O AND
C==L); }
else if(P == 8) { PatternName = "WhiteMaubozu"; Pv = (C>O AND H==C AND
O==L); }
else if(P == 9) { PatternName = "BlackClosingMarubozu"; Pv = (O>C AND
C==L); }
else if(P == 10) { PatternName = "WhiteClosingMarubozu"; Pv = (C>O AND
C==H); }
else if(P == 11) { PatternName = "BlackOpeningMarubozu"; Pv = (O>C AND
O==H); }
else if(P == 12) { PatternName = "WhiteOpeningMarubozu"; Pv = (C>O AND
O==L); }
else if(P == 13) { PatternName = "HangingMan"; Pv = (((H-L)>4*(O-C)) AND
((C-L)/(.001+H-L)>= 0.75) AND ((O-L)/(.001+H-L)>= 0.75)); }
else if(P == 14) { PatternName = "Hammer"; Pv = (((H-L)>3*(O-C)) AND
((C-L)/(.001+H-L)>0.6) AND ((O-L)/(.001+H-L)>0.6)); }
else if(P == 15) { PatternName = "InvertedHammer"; Pv = (((H-L)>3*(O-C))
AND ((H-C)/(.001+H-L)>0.6) AND ((H-O)/(.001+H-L)>0.6)); }
else if(P == 16) { PatternName = "ShootingStar"; Pv = (((H-L)>4*(O-C))
AND ((H-C)/(.001+H-L)>= 0.75) AND ((H-O)/(.001+H-L)>= 0.75)); }
else if(P == 17) { PatternName = "BlackSpinningTop"; Pv = ((O>C) AND
((H-L)>(3*(O-C))) AND (((H-O)/(.001+H-L))<.4) AND
(((C-L)/(.001+H-L))<.4)); }
else if(P == 18) { PatternName = "WhiteSpinningTop"; Pv = ((C>O) AND
((H-L)>(3*(C-O))) AND (((H-C)/(.001+H-L))<.4) AND
(((O-L)/(.001+H-L))<.4)); }
else if(P == 19) { PatternName = "BearishAbandonedBaby"; Pv = ((C1 == O1)
AND (C2>O2) AND (O>C) AND (L1>H2) AND (L1>H)); }
else if(P == 20) { PatternName = "BearishEveningDojiStar"; Pv = ((C2>O2)
AND ((C2-O2)/(.001+H2-L2)>.6) AND (C2<O1) AND (C1>O1) AND
((H1-L1)>(3*(C1-O1))) AND (O>C) AND (O<O1)); }
else if(P == 21) { PatternName = "DarkCloudCover"; Pv = (C1>O1 AND
((C1+O1)/2)>C AND O>C AND O>C1 AND C>O1 AND (O-C)/(.001+(H-L)>0.6)); }
else if(P == 22) { PatternName = "BearishEngulfing"; Pv = ((C1>O1) AND
(O>C) AND (O>= C1) AND (O1>= C) AND ((O-C)>(C1-O1))); }
else if(P == 23) { PatternName = "ThreeOutsideDownPattern"; Pv = ((C2>O2)
AND (O1>C1) AND (O1>= C2) AND (O2>= C1) AND ((O1-C1)>(C2-O2)) AND (O>C) AND
(C<C1)); }
else if(P == 24) { PatternName = "BullishAbandonedBaby"; Pv = ((C1 == O1)
AND (O2>C2) AND (C>O) AND (L2>H1) AND (L>H1)); }
else if(P == 25) { PatternName = "BullishMorningDojiStar"; Pv = ((O2>C2)
AND ((O2-C2)/(.001+H2-L2)>.6) AND (C2>O1) AND (O1>C1) AND
((H1-L1)>(3*(C1-O1))) AND (C>O) AND (O>O1)); }
else if(P == 26) { PatternName = "BullishEngulfing"; Pv = ((O1>C1) AND
(C>O) AND (C>= O1) AND (C1>= O) AND ((C-O)>(O1-C1))); }
else if(P == 27) { PatternName = "ThreeOutsideUpPattern"; Pv = ((O2>C2)
AND (C1>O1) AND (C1>= O2) AND (C2>= O1) AND ((C1-O1)>(O2-C2)) AND (C>O) AND
(C>C1)); }
else if(P == 28) { PatternName = "BullishHarami"; Pv = ((O1>C1) AND (C>O)
AND (C<= O1) AND (C1<= O) AND ((C-O)<(O1-C1))); }
else if(P == 29) { PatternName = "ThreeInsideUpPattern"; Pv = ((O2>C2)
AND (C1>O1) AND (C1<= O2) AND (C2<= O1) AND ((C1-O1)<(O2-C2)) AND (C>O) AND
(C>C1) AND (O>O1)); }
else if(P == 30) { PatternName = "PiercingLine"; Pv = ((C1<O1) AND
(((O1+C1)/2)<C) AND (O<C) AND (O<C1) AND (C<O1) AND
((C-O)/(.001+(H-L))>0.6)); }
else if(P == 31) { PatternName = "BearishHarami"; Pv = ((C1>O1) AND (O>C)
AND (O<= C1) AND (O1<= C) AND ((O-C)<(C1-O1))); }
else if(P == 32) { PatternName = "ThreeInsideDownPattern"; Pv = ((C2>O2)
AND (O1>C1) AND (O1<= C2) AND (O2<= C1) AND ((O1-C1)<(C2-O2)) AND (O>C) AND
(C<C1) AND (O<O1)); }
else if(P == 33) { PatternName = "ThreeWhiteSoldiers"; Pv = (C>O*1.01)
AND (C1>O1*1.01) AND (C2>O2*1.01) AND (C>C1) AND (C1>C2) AND (O<C1) AND
(O>O1) AND (O1<C2) AND (O1>O2) AND (((H-C)/(H-L))<.2) AND
(((H1-C1)/(H1-L1))<.2) AND (((H2-C2)/(H2-L2))<.2); }
else if(P == 34) { PatternName = "DarkCloudCover"; Pv = (C1>O1*1.01) AND
(O>C) AND (O>H1) AND (C>O1) AND (((C1+O1)/2)>C) AND (C>O1) AND
(MA(C,13)-Ref(MA(C,13),-4)>0); }
else if(P == 35) { PatternName = "ThreeBlackCrows"; Pv = (O>C*1.01) AND
(O1>C1*1.01) AND (O2>C2*1.01) AND (C<C1) AND (C1<C2) AND (O>C1) AND (O<O1)
AND (O1>C2) AND (O1<O2) AND (((C-L)/(H-L))<.2) AND (((C1-L1)/(H1-L1))<.2)
AND (((C2-L2)/(H2-L2))<.2); }
else if(P == 36) { PatternName = "doji"; Pv = (O == C); }
else if(P == 37) { PatternName = "GapUp"; Pv = GapUp(); }
else if(P == 38) { PatternName = "GapDown"; Pv = GapDown(); }
else if(P == 39) { PatternName = "BigGapUp"; Pv = L>1.01*H1; }
else if(P == 40) { PatternName = "BigGapDown"; Pv = H<0.99*L1; }
else if(P == 41) { PatternName = "HugeGapUp"; Pv = L>1.02*H1; }
else if(P == 42) { PatternName = "HugeGapDown"; Pv = H<0.98*L1; }
else if(P == 43) { PatternName = "DoubleGapUp"; Pv = GapUp() AND
Ref(GapUp(),-1); }
else if(P == 44) { PatternName = "DoubleGapDown"; Pv = GapDown() AND
Ref(GapDown(),-1); }
return Pv;
}
PatternNameList = "";
for(Cp=0; Cp<=44; Cp++)
{
VarSet("Pattern"+NumToStr(Cp,1.0),CandlePattern(cP));
PatternNameList = PatternNameList +PatternName+","; 
}
BI = BarIndex();
SelectedBar = SelectedValue(BI) -BI[0];
//Selectedbar = Status("lastvisiblebar")-1;
PStr="";
for(Cp=0; Cp<=44; Cp++)
{
Temp = VarGet("Pattern"+NumToStr(Cp,1.0));
if(temp[SelectedBar]) Pstr=Pstr+"#"+NumToStr(Cp,1.0)+" - "+StrExtract(PatternNameList,Cp)+"\n";
}
FS=Param("Font Size",11,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True ); 
GfxSetBkMode( colorWhite ); 
GfxSetTextColor( ParamColor("Color",colorWhite) ); 
Hor=Param("Horizontal Position",237,1,1200,1);
Ver=Param("Vertical Position",50,1,830,1); 
GfxTextOut("Candle Reader= "+Pstr, Hor , Ver );
_SECTION_END();

_SECTION_BEGIN("Robert's Pivot Points");
 
//---------------------------------------------------------------------------
//                              Pivot Pointer
//---------------------------------------------------------------------------
//  Now a days each and every trader wants pivot levels for thier day 
//  trading.But the main feature in this afl is you can get all types of 
//  pivot point in a single afl, Some of the traders use Woodie pivot, 
//  caramilla pivot, Fibonacci pivot and most of them used Classical 
//  pivot, i think this afl will solve all your needs.
//---------------------------------------------------------------------------
 
//---------------------------------------------------------------------------
//  Please write your comments to arokiaraj_robert@yahoo.com
//---------------------------------------------------------------------------
 
//---------------------------------------------------------------------------
// This section gets whether they want pivot level for intraday or thier eod 
//---------------------------------------------------------------------------
 
_N(ioreod =ParamList("Pivot Levels for ",  "Intraday|EOD"));
 
if (ioreod=="Intraday") 
    {
        yh = TimeFrameGetPrice( "H", inDaily, -1 );
        yl = TimeFrameGetPrice( "L", inDaily, -1 );
        yc = TimeFrameGetPrice( "C", inDaily, -1 );
    }
else
    {
        yh = TimeFrameGetPrice( "H", inDaily, 0 );
        yl = TimeFrameGetPrice( "L", inDaily, 0 );
        yc = TimeFrameGetPrice( "C", inDaily, 0 );
    }
 
//---------------------------------------------------------------------------
//                       To calculate the Pivot Levels 
//---------------------------------------------------------------------------
 
to = TimeFrameGetPrice( "O", inDaily, 0 );
pivot = (yh + yl + yc) / 3;
range = yh - yl;
_N(pist =ParamList("Select Pivot Type ", "Classical Pivot|Woodie Pivot|Caramilla Pivot|Fibonacci Pivot"));
 
if (pist =="Classical Pivot" )
    {
        r1 = (2 * pivot) - yl ;
        s1 = (2 * pivot) - yh ;
        r2 = pivot - s1 + r1;
        s2 = pivot - (r1 - s1) ;
        r3 = 2 * (pivot - yl) + yh ;
        s3 = yl - (2 * (yh - pivot));
    }
 
else if(pist =="Woodie Pivot" )
    {
        pivot = (yh + yl + yc + to) / 4;
        r1 = (2 * pivot) - yl;
        r2 = pivot + range;
        r3 = yh + 2 * (pivot - yl);
        r4 = r3 + range;
        s1 = (2 * pivot) - yh;
        s2 = pivot - range;
        s3 = yl - 2 * (yh - pivot);
        s4 = S3 - range;
    }
 
else if(pist =="Caramilla Pivot" )
    {
        r4 = yc + range * 1.1/2;
        r3 = yc + range * 1.1/4;
        r2 = yc + range * 1.1/6;
        r1 = yc + range * 1.1/12;
        s1 = yc - range * 1.1/12;
        s2 = yc - range * 1.1/6;
        s3 = yc - range * 1.1/4;
        s4 = yc - range * 1.1/2;
    }
 
else
    {
        r3 = pivot + 1.000 * (yh - yl);
        r2 = pivot + 0.618 * (yh - yl);
        r1 = pivot + 0.382 * (yh - yl); 
        s1 = pivot - 0.382 * (yh - yl); 
        s2 = pivot - 0.618 * (yh - yl); 
        s3 = pivot - 1.000 * (yh - yl);
    }
 
//---------------------------------------------------------------------------
//                      To Plot Pivot Levels in the screen 
//---------------------------------------------------------------------------
 
_N(dsr =ParamList("Draw Intraday Pivot Levels ",  "None|Both|Support|Resistance"));
 
if (dsr =="Support" OR  dsr == "Both")
{
    Plot(pivot, "\n Pivot - ",colorGreen,1);
    Plot(r1, "Resistance 1 - ",colorDarkRed,1);
    Plot(r2, "Resistance 2 - ",colorDarkRed,1);
    Plot(r3, "Resistance 3 - ",colorDarkRed,1);
    Plot((pivot+r1)/2, "Mid Value of R1 & Pivot  ",colorLightBlue,1);
    Plot((r3+r2)/2, "Mid Value of R2 & R3 -  ",colorLightBlue,1);
    Plot((r1+r2)/2, "Mid Value of R1 & R2 - ",colorLightBlue,1);
}
 
if( dsr == "Resistance" OR  dsr == "Both")
{
    Plot(pivot, "\n Pivot - ",colorGreen,1);
    Plot(s3, "Support 2 - ",colorDarkGreen,1);
    Plot(s2, "Support 2 - ",colorDarkGreen,1);
    Plot(s1, "Support 1 - ",colorDarkGreen,1);
    Plot((s3+s2)/2, "Mid Value of S2 & S3 ",colorWhite,1);
    Plot((s1+s2)/2, "Mid Value of S1 & S2 -  ",colorWhite,1);
    Plot((pivot+s1)/2, "Mid Value of S1 & Pivot  ",colorWhite,1);
}
 
//---------------------------------------------------------------------------
//               Printing the pivot level in interpretation window
//---------------------------------------------------------------------------
 
 
printf(Name()+ "\n\nResistance - 3  |  %g\nResistance - 2  |  %g\nResistance - 1  |  %g\n" + 
"Pivot                |  %g\nSupport - 1      |  %g\nSupport - 2      |  %g\nSupport - 3      |  %g",
r3,r2,r1,pivot,s1,s2,s3);
 
 
//---------------------------------------------------------------------------
//                      This section is for Exploration 
//---------------------------------------------------------------------------
 
Filter = 1;
AddColumn(r3,"Resistance 3");
AddColumn(r2,"Resistance 2");
AddColumn(r1,"Resistance 1");
AddColumn(Pivot,"Pivot");
AddColumn(s1,"Support 1");
AddColumn(s2,"Support 2");
AddColumn(s3,"Support 3");
 
//---------------------------------------------------------------------------
//                      Add Pivot levels along with the title
//---------------------------------------------------------------------------
 
_N(Title = EncodeColor(colorBrown)+ StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g(%.1f%%)\n"+
    EncodeColor(4)+"Resistance 3 -=- %g ::::: Resistance 2 -=- %g ::::: Resistance 1 -=- %g :::::"+
    EncodeColor(colorGreen)+" Pivot -=- %g"+
    EncodeColor(29)+"\nSupport 1 -=- %g ::::: Support 2 -=- %g ::::: Support 3 -=- %g\n ",
 O, H, L, C,SelectedValue( ROC( C, 1 ) ),r3,r2,r1,pivot,s1,s2,s3));
 
//---------------------------------------------------------------------------
//                              End of Pivot Point 
//---------------------------------------------------------------------------
 
_SECTION_END();

_SECTION_BEGIN("Bollinger Bands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style");
Plot( BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style ); 
Plot( BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style ); 
_SECTION_END();
Back