- 精华
- 0
- 在线时间
- 1023 小时
- UID
- 38411
- 积分
- 669
- 帖子
- 160
- 阅读权限
- 60
- 注册时间
- 2011-5-8
- 最后登录
- 2023-10-4
- 精华
- 0
- UID
- 38411
- 积分
- 669
- 帖子
- 160
- 主题
- 17
- 阅读权限
- 60
- 注册时间
- 2011-5-8
- 最后登录
- 2023-10-4
|
input:trials(500),entrymethod(1);
var: LongShort(0);
Var: BarstoNext(0);
Var:ATRexitL(-99999.),ATRexitS(99999.),ATRx(0);
if entrymethod=1 then begin //random entry
//Entry logic
Longshort=random(1); //chose a random number between 0 and 1
BarstoNext=intportion(random(15))+1; //entry should occur at BarsToNext bars after previous exit
if (totaltrades=0 or BarsSinceExit(1)>=BarsToNext) and marketposition=0 then begin
if LongShort<.5 then buy next bar at market;
if LongShort>.5 then sellshort next bar at market;
end;
end; //exit method 1
if entrymethod=2 and marketposition=0 then begin //Bollinger Band entry
inputs: Length( 20 ), NumDevsDn( 2 ) ;
variables: LowerBand( 0 ),UpperBand( 0 ) ;
LowerBand = BollingerBand( Close, Length, -NumDevsDn ) ;
UpperBand = BollingerBand( Close, Length, NumDevsDn ) ;
if CurrentBar > 1 and Low crosses over LowerBand then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
If close>=LowerBand then buy next bar at market;
if CurrentBar > 1 and High crosses under UpperBand then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
If Close<=Upperband then sellshort next bar at market;
//SellShort ( "BBandSE" ) next bar at UpperBand stop ;
end;//entry method 2
if entrymethod=3 and marketposition=0 then begin
inputs: FastLength( 12 ) ;
variables: MyMACD( 0 ), MACDAvg( 0 ), MACDDiff( 0 ),slowLength(0),MACDLength(0) ;
variables: MyMACD2( 0 ), MACDAvg2( 0 ), MACDDiff2( 0 ) ;
SlowLength=2.*FastLength;
MACDLength=FastLength;
MyMACD = MACD( Close, FastLength, SlowLength ) ;
MACDAvg = XAverage( MyMACD, MACDLength ) ;
MACDDiff = MyMACD - MACDAvg ;
if CurrentBar > 2 and MACDDiff crosses over 0 then { CB > 2 check used to
avoid spurious cross confirmation at CB = 2 (at CB = 1, MyMACD and MACDAvg will be
the same) }
Buy ( "MacdLE" ) next bar at market ;
MyMACD2 = MACD( Close, FastLength, SlowLength ) ;
MACDAvg2 = XAverage( MyMACD2, MACDLength ) ;
MACDDiff2 = MyMACD2 - MACDAvg2 ;
if CurrentBar > 2 and MACDDiff2 crosses under 0 then { CB > 2 check used to
avoid spurious cross confirmation at CB = 2 (at CB = 1, MyMACD and MACDAvg will be
the same) }
Sell Short ( "MacdSE" ) next bar at market ;
end; //entry method 3 (MACD)
if entrymethod=4 and marketposition=0 then begin //(momentum)
inputs: Price( Close ), MomeLength( 12 ) ; ;
variables: Mom( 0 ), Accel( 0 ) ;
Mom = Momentum( Price, MomeLength ) ;
Accel = Momentum( Mom, 1 ) ; { 1 bar acceleration }
if Mom > 0 and Accel > 0 then
If high>high[1] then buy next bar at market;
if Mom < 0 and Accel < 0 then
If low<low[1] then sellshort next bar at market;
end; //entry 4
if entrymethod=5 and marketposition=0 then begin //2 mov avg
inputs: xPrice( Close ), MAFastLength( 9 );
variables: MAFastAvg( 0 ), MASlowAvg( 0 ),MAslowlength(0) ;
MASlowLength=2*MAFastLength;
MAFastAvg = AverageFC( xPrice, MAFastLength ) ;
MASlowAvg = AverageFC( xPrice, MASlowLength ) ;
if CurrentBar > 1 and MAFastAvg crosses over MASlowAvg then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
Buy ( "MA2CrossLE" ) next bar at market ;
if CurrentBar > 1 and MAFastAvg crosses under MASlowAvg then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
Sell Short ( "MA2CrossSE" ) next bar at market ;
end; //dual ma entry
if entrymethod=6 and marketposition=0 then begin
inputs: RSILength( 14 ), OverSold( 30 ),overbought(70) ;
variables: MyRSI( 0 ) ;
MyRSI = RSI( Close, Length ) ;
if Currentbar > 1 and MyRSI crosses over OverSold then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
Buy ( "RsiLE" ) next bar at market ;
if Currentbar > 1 and MyRSI crosses under OverBought then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
Sell Short ( "RsiSE" ) next bar at market ;
end;//RSi entry
var:ExitBar(0);
//exit method
ExitBar=intportion(random(20))+1;
if BarssinceEntry>=ExitBar then begin
sell next bar market;
Buytocover next bar market;
end;
REVERSE ENTRIES –Bollinger Bands and RSI
if entrymethod=2 and marketposition=0 then begin //reverse Bollinger Band entry
inputs: Length( 20 ), NumDevsDn( 2 ) ;
variables: LowerBand( 0 ),UpperBand( 0 ) ;
LowerBand = BollingerBand( Close, Length, -NumDevsDn ) ;
UpperBand = BollingerBand( Close, Length, NumDevsDn ) ;
if CurrentBar > 1 and Low crosses over LowerBand then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
If close>=LowerBand then sellshort next bar at market;
if CurrentBar > 1 and High crosses under UpperBand then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
If Close<=Upperband then buy next bar at market;
end;//entry method 2r
if entrymethod=6 and marketposition=0 then begin //reverse RSI entry
inputs: RSILength( 14 ), OverSold( 30 ),overbought(70) ;
variables: MyRSI( 0 ) ;
MyRSI = RSI( Close, Length ) ;
if Currentbar > 1 and MyRSI crosses over OverSold then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
SellShort( "RsiSE" ) next bar at market ;
if Currentbar > 1 and MyRSI crosses under OverBought then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
Buy ( "RsiLE" ) next bar at market ;
end;//RSi entry 6r |
|