 Registered User Joined: 6/15/2008 Posts: 1,356
|
Hi,
I'm trying to program the "TD-setup squence of the TD-Sequential DeMark indicator.
parameters are as follows:
we need to see a "Bearish flip", defined as follows:
closing price has to be lower then closing price 4 bars ago And;
Yesterdays closing price has to be higher then closing bar 4 bars ago (relative to yesterdays bar).
if this holds true we can start the TD- buy setup. defined as follows.
note : the bar that passed the bearish flip willbe the first bar of the TD-buy setup.
there must be 9 consecutive closes, each one less then the corresponding close 4 bars earlier.
I have created some real-code, using the CASE statement :
Static DayCount As Integer
Static TDcount As Integer
' first check if we start at the 5th bar
If isFirstBar Then
plot = Single.NaN
DayCount = 0
TDcount = 0
Else
DayCount += 1
End If
' we're on the 5th bar, or higher
If daycount >= 5 Then
Select Case tdcount
'this is the Bearish TD price flip, which if true, puts us on the first bar of the TD-Buy setup
Case 0
If Price.Close < price.Close(4) AndAlso _
Price.Close(1) > price.Close(5) Then
TDcount += 1
label = tdcount
plot = tdcount
End If
Case 1
If Price.Close < price.Close(4) Then
TDcount += 1
label = tdcount
plot = tdcount
Else
tdcount = 0
End If
Case 2
If Price.Close < price.Close(4) Then
TDcount += 1
label = tdcount
plot = tdcount
Else
tdcount = 0
End If
Case 3
If Price.Close < price.Close(4) Then
TDcount += 1
label = tdcount
plot = tdcount
Else
tdcount = 0
End If
Case 4
If Price.Close < price.Close(4) Then
TDcount += 1
label = tdcount
plot = tdcount
Else
tdcount = 0
End If
Case 5
If Price.Close < price.Close(4) Then
TDcount += 1
label = tdcount
plot = tdcount
Else
tdcount = 0
End If
Case 6
If Price.Close < price.Close(4) Then
TDcount += 1
label = tdcount
plot = tdcount
Else
tdcount = 0
End If
Case 7
If Price.Close < price.Close(4) Then
TDcount += 1
label = tdcount
plot = tdcount
Else
tdcount = 0
End If
Case 8
If Price.Close < price.Close(4) Then
TDcount += 1
label = tdcount
plot = tdcount
tdcount = 0
End If
End Select
Else
setindexinvalid
End If
It seems to work ok, but I have some cases were it skips a few bars between the 8'th and 9th count. see pic.
I don't understand why.

|
Registered User Joined: 12/31/2005 Posts: 2,499
|
case 8 needs
else
TDCount = 0
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
Also you case statement can be simplified
Static TDcount As Integer
' first check if we start at the 5th bar
If isFirstBar Then
plot = Single.NaN
TDcount = 0
End If
' we're on the 5th bar, or higher
If currentIndex >= 5 Then
Select Case tdcount
'this is the Bearish TD price flip, which if true, puts us on the first bar of the TD-Buy setup
Case 0
If Price.Close < price.Close(4) AndAlso _
Price.Close(1) > price.Close(5) Then
TDcount += 1
label = tdcount
plot = tdcount
End If
Case Else
If Price.Close < price.Close(4) Then
TDcount += 1
label = tdcount
plot = tdcount
Else
tdcount = 0
End If
End Select
Else
setindexinvalid
End If
If tdCount = 9 Then
tdCount = 0
End If
|
 Registered User Joined: 6/15/2008 Posts: 1,356
|
Thx jas0501, I see the oversight.
however after I changed it, it flatlines. it stays at 0.
|
 Registered User Joined: 6/15/2008 Posts: 1,356
|
your code is working, thanks a lot.
this is just a start on the TD-sequential indicator.
There are a lot more permutations I'd like to add, which I'll post later.
|
 Registered User Joined: 6/15/2008 Posts: 1,356
|
"Case Else" !!! didn't know that one. cool!.
|