Learning SWITCH / CASE

Questions about MultiCharts and user contributed studies.
User avatar
TJ
Posts: 6572
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 968 times
Been thanked: 1902 times

Learning SWITCH / CASE

Postby TJ » 31 Jul 2008

I want to Learn how to use SWITCH / CASE.

I am looking for programming examples,

Do you know of any strategy or indicator that uses these keywords?

khalaad
Posts: 314
Joined: 07 Jan 2007
Location: Lahore, Pakistan
Has thanked: 63 times
Been thanked: 57 times

Postby khalaad » 01 Aug 2008

TJ,

Please find a simple example of SWITCH here:

http://www.tssupport.com/support/base/? ... le&id=1129

Khalid

User avatar
TJ
Posts: 6572
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 968 times
Been thanked: 1902 times

Postby TJ » 01 Aug 2008

This is great!
Many thanks for the link.

User avatar
ABC
Posts: 520
Joined: 16 Dec 2006
Has thanked: 111 times
Been thanked: 295 times
Contact:

Postby ABC » 01 Aug 2008

TJ,
I have done a simple switch/case thing inside an indicator that I run on the very first bar to identify the BarType and Store a name inside a variable for further use:


Code: Select all

   Switch(BarType_ex) begin
      Case 1: BarTyp = "Ticks";
      Case 2: BarTyp = "Minutes";
      Case 3: BarTyp = "Hours";
      Case 4: BarTyp = "Days";
      Case 5: BarTyp = "Weeks";
      Case 6: BarTyp = "Months";
      Case 7: BarTyp = "Years";
      Case 8: BarTyp = "Volume";
      Case 9: BarTyp = "Seconds";
      Case 10: BarTyp = "Quarters";
      Case 11: BarTyp = "Points";
      Case 12: BarTyp = "Change";
      Case 13: BarTyp = "Points (original)";
      Default: BarTyp = "";
   end;


BarType_ex will return numeric values from 1 to 13, so each return value is assigned to a Case. The last thing is a default value that will be used if none of the Switch Values will match a Case value.

Hope this helps.

Regards,
ABC

User avatar
TJ
Posts: 6572
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 968 times
Been thanked: 1902 times

Postby TJ » 01 Aug 2008

ABC:

This is more than an example, this is useful code.
Thanks.

TJ

User avatar
ABC
Posts: 520
Joined: 16 Dec 2006
Has thanked: 111 times
Been thanked: 295 times
Contact:

Postby ABC » 01 Aug 2008

TJ,
I am happy if I could help a bit and even more if you can put the code piece to some use for yourself.

Switch must not necessarily have continuous values from 0 to X, this would also be okay:

Code: Select all

Switch(Value1)
Begin
  Case 1 to 5:
     Value2 = Value2 + 1;

    Case 10, 20, 30:

        Value3 = Highest(High,10);

    Case is > 40:

        Value3 = Value3 + 1;

    Default:
     Value5 = Value5 + 1;
End;



Regards,

ABC


Return to “MultiCharts”