Code: Select all
{****MOVINGAVERAGE CROSS ENTRY****}
inputs: Price( Close ), FastLength( 9 ), SlowLength( 18 ) ;
variables: FastAvg( 0 ), SlowAvg( 0 ) ;
FastAvg = AverageFC( Price, FastLength ) ;
SlowAvg = AverageFC( Price, SlowLength ) ;
if CurrentBar > 1 and FastAvg crosses over SlowAvg then
Buy ( "MA2CrossLE" ) next bar at market ;
if CurrentBar > 1 and FastAvg crosses under SlowAvg then
Sell Short ( "MA2CrossSE" ) next bar at market ;
{****SCALING OUT EXITS****}
inputs:
TargetAmt1( 20 points ) ,
FullPosition( 2 { contracts } ) ,
HalfPosition( 1 { contract } ) ;
variables:
ProfTarget1( 0 ) ,
ProfTarget2( 0 ) ;
if MarketPosition = 1 and BarsSinceEntry = 0 then
begin
ProfTarget1 = EntryPrice + TargetAmt1 ;
end ;
if MarketPosition = 1 then
begin
if CurrentShares = FullPosition then
sell HalfPosition contracts next bar at ProfTarget1 limit ;
end;
if MarketPosition = -1 and BarsSinceEntry = 0 then
begin
ProfTarget1 = EntryPrice - TargetAmt1 ;
end;
if MarketPosition = -1 then
begin
if CurrentShares = FullPosition then
buy to cover HalfPosition contracts next bar at ProfTarget1 limit ;
end;
setexitonclose;