Thursday, September 6, 2012

[STAD_01] Opening Gap

If Opening Price is lower than yesterday low then buy
If Opening Price is higher than yesterday's high then buy
This is in some way a price reversioon technique.


input : P1(20), p2(40);
input : HLperiod(20), ARmult(4), Div(40);
Var: StopPrice(0), BullTrend(false), BearTrend(true);
Var: SellOnSwingHigh(false), BuyOnSwingLow(false), MP(0);
var : sumV1(0), sumV2(0), ShortDayAvg(0), LongDayAvg(0), count(0);

sumV1 = 0;
sumV2 = 0;
for count = 0 to p2-1 {
if count < p1 then
sumV1 = sumV1 + DayClose(count);
if count < p2 then
sumV2 = sumV2 + DayClose(count);
}
ShortDayAvg = sumV1 / P1;
LongDayAvg = sumV2 / P2;
##

BullTrend = ShortDayAvg >= LongDayAvg;
BearTrend = ShortDayAvg < LongDayAvg;

If Date <> Date[1] then {
SellOnSwingHigh = False;
BuyOnSwingLow = False;

If BullTrend then {
If Close < dayLow(1) and C > dayOpen then {
Buy();
BuyOnSwingLow = True;
}
If Close > dayHIgh(1) then
SellOnSwingHigh = True;
}
If BearTrend then {
If Close > dayHIgh(1) and C < dayOPen then {
Sell();
SellOnSwingHigh = True;
}
If Close < dayLow(1) then
BuyOnSwingLow = True;
}
}

If date == date[1] Then {
If SellOnSwingHigh then
Sell("Sell",atstop, lowest(L,HLPeriod));;
If BuyOnSwingLow then
Buy("Buy",atstop,highest(H,HLPeriod));
If MarketPosition == -1 then
SellOnSwingHigh = false;
If MarketPosition == 1 then
BuyOnSwingLow = false;
}

MP = MarketPosition;
if MP == 1 and MP[1] <> 1 then
StopPrice = low - ma(range,40)*ARmult;

if MP == -1 and MP[1] <> -1 then
StopPrice = High + ma(range,40)*ARmult;

If MP == 1 then {
exitlong ("ExitLong", atstop, stopprice );
stopprice = stopprice + (low-stopprice)/Div;
}
If MP == -1 then {
exitshort ("ExitShort",atstop, stopprice );
stopprice = stopprice - (stopprice-high)/Div;
}

setstoploss(2.0);
SetStopEndofday(1500);

No comments:

Post a Comment