Pivot Points (Amibroker And Tradestation Code)
The original article can be found here.
CPP= ( Ref(H,-1)+Ref(L,-1) + Ref(C,-1) ) / 3; //Central pivot point
R1 = (2*CPP)-Ref(L,-1) ;//FirstResistance
S1= (2*CPP)-Ref(H,-1) ; //First support
R2 = CPP + (R1 – S1) ; //Second resistance
S2 = CPP – (R1 – S1) ; //second support
Plot(CPP,”CPP”, colorRed,styleLine);
Plot(R1,”R1″, colorBlack,styleLine);
Plot(S1,”S1″, colorBlue,styleLine);
Plot(R2,”R2″, colorYellow,styleLine);
Plot(S2,”S2″, colorGreen,styleLine);
Amibroker code:
First strategy:
gapdiff=(O-Ref(C,-1))/Ref(C,-1) ;
Buy= gapdiff>0 AND L<S2 ;
buyPrice= S2;
Sell= C>0;
sellPrice= Close ;
Second strategy:
Buy= gapdiff<0 AND Open>s2 AND L<S2 ;
buyPrice= S2;
Sell= C>0;
sellPrice= Close ;
Third strategy:
Short= gapdiff<0 AND H>R1 ;
shortPrice= R1;
Cover= C>0;
coverPrice= Close ;
Fourth strategy:
short= gapdiff>0 AND Open<R1 AND H>R1 ;
shortPrice= r1;
cover= C>0;
coverPrice= Close ;
Fifth strategy:
Short= Open<s1 AND H>s1 ;
shortPrice= s1;
Cover= C>0;
coverPrice= Close ;
Sixth strategy:
buy= Open>r1 AND L<r1 ;
buyPrice= r1;
sell= C>0;
sellPrice= Close ;
Tradestation code:
{
Pivot point trading strategy (Strategy 101_EXIT)
It is not possible to combine next bar's open price and on close order in the same Strategy (Error #30215).
For this reason this strategy defines exit rule only.
To backtest properly add one of the strategies: 101A_ENTRY to 101F_ENTRY together with 101_EXIT strategy to the list and then run the backtest.
}
if Marketposition(0) > 0 then sell this bar on close;
if Marketposition(0) < 0 then buytocover this bar on close;
Strategy 1:
{
Pivot point trading strategy (Strategy 101A_ENTRY)
The market opens above yesterday’s close and drops to the first pivod point support.
Entry is the first support pivot point and exit is at the close.
It is not possible to combine next bar's open price and on close order in the same Strategy (Error #30215).
For this reason this strategy defines entry rule only.
To backtest properly add the both 101A_ENTRY and 101ABF_EXIT strategies to the list and then run backtest.
}
Vars:
CPP(0),
R1(0),
R2(0),
S1(0),
S2(0),
GapDiff(0);
CPP = (High + Low+ Close) / 3; //Central pivot point
R1 = (2 * CPP) - Low; //FirstResistance
S1 = (2 * CPP) - High; //First support
R2 = CPP + (R1 - S1); //Second resistance
S2 = CPP - (R1 - S1); //second support
GapDiff=(Open next bar - Close) / Close;
if GapDiff > 0 then buy next bar at S2 limit;
Strategy 2:
{
Pivot point trading strategy (Strategy 101B_ENTRY)
The market opens below yesterday’s close, but above the first pivot point support, and drops to the first pivot point support.
Entry is first support pivot point and exit is on the close.
It is not possible to combine next bar's open price and on close order in the same Strategy (Error #30215).
For this reason this strategy defines entry rule only.
To backtest properly add the both 101B_ENTRY and 101_EXIT strategies to the list and then run the backtest.
}
Vars:
CPP(0),
R1(0),
R2(0),
S1(0),
S2(0),
GapDiff(0);
CPP = (High + Low+ Close) / 3; //Central pivot point
R1 = (2 * CPP) - Low; //FirstResistance
S1 = (2 * CPP) - High; //First support
R2 = CPP + (R1 - S1); //Second resistance
S2 = CPP - (R1 - S1); //second support
GapDiff=(Open next bar - Close) / Close;
if GapDiff < 0 and Open next bar > S2 then buy next bar at S2 limit;
Strategy 3:
{
Pivot point trading strategy (Strategy 101C_ENTRY)
The market opens below yesterday’s close and rises to the first pivot point resistance.
Entry is first resistance pivot point and exit is on the close.
Of course, this is a short strategy.
It is not possible to combine next bar's open price and on close order in the same Strategy (Error #30215).
For this reason this strategy defines entry rule only.
To backtest properly add the both 101C_ENTRY and 101_EXIT strategies to the list and then run the backtest.
}
Vars:
CPP(0),
R1(0),
R2(0),
S1(0),
S2(0),
GapDiff(0);
CPP = (High + Low+ Close) / 3; //Central pivot point
R1 = (2 * CPP) - Low; //FirstResistance
S1 = (2 * CPP) - High; //First support
R2 = CPP + (R1 - S1); //Second resistance
S2 = CPP - (R1 - S1); //second support
GapDiff=(Open next bar - Close) / Close;
if GapDiff < 0 then Sellshort next bar at R1 limit;
Strategy 4:
{
Pivot point trading strategy (Strategy 101D_ENTRY)
The market opens above yesterday’s close, but below the first pivot point resistance, and rises to the first pivot point resistance.
Entry is first resistance pivot point and exit is on the close.
Of course, this is a short strategy.
It is not possible to combine next bar's open price and on close order in the same Strategy (Error #30215).
For this reason this strategy defines entry rule only.
To backtest properly add the both 101D_ENTRY and 101_EXIT strategies to the list and then run the backtest.
}
Vars:
CPP(0),
R1(0),
R2(0),
S1(0),
S2(0),
GapDiff(0);
CPP = (High + Low+ Close) / 3; //Central pivot point
R1 = (2 * CPP) - Low; //FirstResistance
S1 = (2 * CPP) - High; //First support
R2 = CPP + (R1 - S1); //Second resistance
S2 = CPP - (R1 - S1); //second support
GapDiff=(Open next bar - Close) / Close;
if GapDiff > 0 and Open next bar < R1 then Sellshort next bar at R1 limit;
Strategy 5:
{
Pivot point trading strategy (Strategy 101E_ENTRY)
The market opens below first support. First pivot point support now becomes resistance and
first pivot point support is now an entry for short. The exit is on close.
Of course, this is a short strategy.
It is not possible to combine next bar's open price and on close order in the same Strategy (Error #30215).
For this reason this strategy defines entry rule only.
To backtest properly add the both 101E_ENTRY and 101_EXIT strategies to the list and then run the backtest.
}
Vars:
CPP(0),
R1(0),
R2(0),
S1(0),
S2(0);
CPP = (High + Low+ Close) / 3; //Central pivot point
R1 = (2 * CPP) - Low; //FirstResistance
S1 = (2 * CPP) - High; //First support
R2 = CPP + (R1 - S1); //Second resistance
S2 = CPP - (R1 - S1); //second support
if Open next bar < S1 then Sellshort next bar at S1 limit;
Strategy 6:
{
Pivot point trading strategy (Strategy 101F_ENTRY)
The market opens above the first pivot point resistance.
First pivot point resistance now becomes support and first pivot point resistance is now long entry.
Exit on close.
It is not possible to combine next bar's open price and on close order in the same Strategy (Error #30215).
For this reason this strategy defines entry rule only.
To backtest properly add the both 101F_ENTRY and 101_EXIT strategies to the list and then run the backtest.
}
Vars:
CPP(0),
R1(0),
R2(0),
S1(0),
S2(0);
CPP = (High + Low+ Close) / 3; //Central pivot point
R1 = (2 * CPP) - Low; //FirstResistance
S1 = (2 * CPP) - High; //First support
R2 = CPP + (R1 - S1); //Second resistance
S2 = CPP - (R1 - S1); //second support
if Open next bar > R1 then buy next bar at R1 limit;
