Sub MovAveXoverSystem06 (SLen As Integer, LLen As Integer,
ATRLen As Integer, ExSL As Integer, ExPT As Integer)
'SLen is the Short Moving Average number of previous bars.
'LLen is the Long Moving Average number of previous bars.
'ATRLen is the ATR number of previous bars.
'ExSL is the ATR multiple for the Stop Loss.
'ExPT is the ATR multiple for the Profit Target.
'Calculate ATR on bar prior to Entry Bar
Dim ATROnEntry As BarArray
If MarketPosition<>MarketPosition[1] Then
ATROnEntry=Average(TrueRange,ATRLen,1)
End If
'Calculate Moving Averages
Dim ShortAve As BarArray
Dim LongAve As BarArray
ShortAve=Average(Close,SLen,0)
LongAve=Average(Close,LLen,0)
'Calculate Long Entry Stop Loss and Profit Targets
Dim LongTarget As BarArray
Dim LongStop As BarArray
LongTarget=EntryPrice+(ExPT*ATROnEntry)
LongStop=EntryPrice-(ExSL*ATROnEntry)
'Calculate Short Entry Stop Loss and Profit Targets
Dim ShortTarget As BarArray
Dim ShortStop As BarArray
ShortTarget=EntryPrice-(ExPT*ATROnEntry)
ShortStop=EntryPrice+(ExSL*ATROnEntry)
'Search for a Long Entry Signal
If CrossesOver(ShortAve,LongAve) Then
Buy("BuyEntry",1,0,Market,Day)
End If
'Set Long Target
If Close > LongTarget Then
Sell("LongTarget",1,0,Limit,Day)
Else
'Set Long Stop
If Close < LongStop Then
Sell("LongStop",1,0,Market,Day)
End If
'Search for a Short Entry Signal
If CrossesUnder(ShortAve,LongAve) Then
Sell("SellEntry",1,0,Market,Day)
End If
'Set Short Target
If Close < ShortTarget Then
Buy("ShortTarget",1,0,Limit,Day)
Else
'Set Short Stop
If Close > ShortStop Then
Buy("ShortStop",1,0,Market,Day)
End If
End Sub