I am writing a system to generate Forex trades using the ADX. I want to initiate a trade when today's ADX is greater than yesterday's ADX by some amount ADXGrowth. In testing the system generates trades, seemingly, without regard to the ADX. I added a Print statement and the values displayed do not match the values displayed on the chart of the Directional Movement System.
Would you help me understand the differences in what I'm seeing?
Thanks,
Bob
Sub BJ_DMI_ADX_ATR (ADXMinGrowth As Double, DMILen As Integer, DMISpread As Double)
' (0.5, 14, 0 )
Dim BuyAge As Integer
Dim SellAge As Integer
Dim ADXPrevious As Double
Dim ADXToday As Double
Dim ATR As Double
Dim ATRStopFactor As Double
Dim EntryPoint As Double
Dim LastTrailingATR As Double
Dim PrtDate As String
Dim barTrailingATR As BarArray
PrtDate = FormatDateTime(Date)
ATR = Average(TrueRange, 20, 0)
BuyAge = BarsSinceEntryPlus("LongEntry")
SellAge = BarsSinceEntryPlus("ShortEntry")
ADXToday = ADX(18, 0)
ADXPrevious = ADX(18, 1) + ADXMinGrowth
If BarNumber > 250 Then Print "2 Date=", PrtDate, " Today=", ADXToday, " Previous=", ADXPrevious
If (BuyAge < 0) And (SellAge < 0) Then 'If no orders are open, see if we want to open one.
If ADXToday > ADXPrevious Then 'Have we got a good, increasing ADX?
If DMIPlus(DMILen, 0) > (DMIMinus(DMILen, 0) + DMISpread) Then 'Let's think about a Long Buy
Buy("LongEntry",1,0,Market,Day)
EntryPoint = Open 'Replace with GetEntryPrice function
barTrailingATR = EntryPoint - (ATRStopFactor * ATR) ' Set Initial Trailing ATR stop loss
End If
If DMIMinus(DMILen, 0) > (DMIPlus(DMILen, 0) + DMISpread) Then 'Let's think about a Short Sell
Sell("ShortEntry",1,0,Market,Day)
EntryPoint = Open 'Replace with GetEntryPrice function
barTrailingATR = EntryPoint + (ATRStopFactor * ATR) ' Set Initial Trailing ATR stop loss
End If
End If
Else |