//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 ) ;
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 ) ;
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 ;
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 ) ;
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) ;
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 ) ;
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 ;