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?
Learning SWITCH / CASE
- TJ
- Posts: 7746
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2225 times
- TJ
- Posts: 7746
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2225 times
- ABC
- Posts: 723
- Joined: 16 Dec 2006
- Location: www.abctradinggroup.com
- Has thanked: 125 times
- Been thanked: 410 times
- Contact:
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:
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
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;
Hope this helps.
Regards,
ABC
- TJ
- Posts: 7746
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2225 times
- ABC
- Posts: 723
- Joined: 16 Dec 2006
- Location: www.abctradinggroup.com
- Has thanked: 125 times
- Been thanked: 410 times
- Contact:
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:
Regards,
ABC
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