When Gold Gaps Up Or Down (Amibroker And Tradestation Code)
The strategy in plain English:
Unfortunately, this strategy doesn’t seem to work as it once did. This is a day trade that enters at the open and exits at the close.
- GLD must open above the high of the last 5 days.
- GLD must gap up at least 1.5 times the 25 day average of the opening gap.
- Buy on open, exit on close.
Click here for the original article.
Amibroker code:
gapdiff=(O-Ref(C,-1))/Ref(C,-1) ;
AvgGap=MA( abs( (O-ref(C,-1))/Ref(C,-1) ),25);
Buy= O>Ref(hhV(H,5),-1) AND gapdiff>(AvgGap*1.5);
buyPrice= O;
Sell= c>0; //force exit
sellPrice= C ;
Tradestation code:
{
When Gold Gaps Up (Strategy 30_ENTRY)
GLD must open above the high of the last 5 days.
GLD must gap up at least 1.5 times the 25 day average of the opening gap.
Buy on open, 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 30_ENTRY and 30_EXIT strategies to the list and then run backtest.
}
Inputs:
AvgGapLookback(25),
HighestHighLookback(5),
AvgGapMultiplier(1.5);
Variables:
GapDiff(0),
HighestHigh(0),
AvgGap(0);
GapDiff=(Open next bar - Close) / Close;
AvgGap=Average(Absvalue(GapDiff), AvgGapLookback);
HighestHigh = Highest(High, HighestHighLookback);
if Open next bar > HighestHigh and GapDiff > AvgGap * AvgGapMultiplier then
Buy on next bar open;
{
When Gold Gaps Up (Strategy 30_EXIT)
GLD must open above the high of the last 5 days.
GLD must gap up at least 1.5 times the 25 day average of the opening gap.
Buy on open, 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 exit rule only.
To backtest properly add the both 30_ENTRY and 30_EXIT strategies to the list and then run backtest.
}
if Marketposition = 1 Then
Sell this bar on close;
Disclosure: We are not financial advisors. Please do your own due diligence and investment research or consult a financial professional. All articles are our opinions – they are not suggestions to buy or sell any securities.
