Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

problem with "CASE" statement. Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
pthegreat
Posted : Sunday, March 28, 2010 2:36:55 PM

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.

jas0501
Posted : Sunday, March 28, 2010 10:47:44 PM
Registered User
Joined: 12/31/2005
Posts: 2,499
case 8 needs

else
   TDCount = 0
jas0501
Posted : Sunday, March 28, 2010 11:11:49 PM
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

pthegreat
Posted : Sunday, March 28, 2010 11:12:46 PM

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.
pthegreat
Posted : Sunday, March 28, 2010 11:22:24 PM

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.
pthegreat
Posted : Sunday, March 28, 2010 11:33:55 PM

Registered User
Joined: 6/15/2008
Posts: 1,356

"Case Else"   !!!  didn't know that one.  cool!.

Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.