Welcome to the Traders Laboratory Forums.
Coding Forum Collaborate, receive help, or discuss coding related issues.

Reply
Old 07-21-2009, 12:49 AM   #1

Tams's Avatar

Join Date: Sep 2008
Location: Geelong
Posts: 3,779
Ignore this user

Thanks: 2,084
Thanked 1,474 Times in 912 Posts

Switch/Case (EasyLanguage)

This thread is about the EasyLanguage keywords Switch and Case.


Switch/Case (EasyLanguage)


Reserved word used to transfer control to an associated Case or Default statement.


Syntax

Switch ( expression )
Begin
Case case-expression: statements;
Default: statements;
End;


Control passes to the statements whose case-expression matches the value of the switch ( expression ).

The switch statement can include any number of case instances,
but no two case constants within the same switch statement can have the same constant value.


Note Once the statements associated with a matching case are evaluated,
control passes to the end of the switch statement.
This is an implied break and is different than a similar structure found in some other languages that require an explicit break.


Remarks

A single case statement can carry multiple values,
as the following example shows:

Case 1, 2, 3, 4, 5, 6, 20: Value1 = Lowest(Close,3);

Ranges like this are also valid:

Case 1 to 6, 20: Value2 = Highest(High,5);

In both of the above examples,
if case-expression equals any number between 1 and 6 or equal to 20,
a function is called and assigned to a value.

In addition,
logical operators may be used with case statements including: >, <, >=, <=, <> and =.

Case > Average( Close, 50 ): Value1 = Close ;

The “is” keyword is an EasyLanguage skip keyword and can be use for better clarity as in the following:

Case is < Average( High, 75 ): Value1 = High ;


Example

Code:
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;

The above switch statement Increments Value2 when the switch expression (Value1) is a value from 1 to 5;
assigns Value3 to the highest high of 10 bars ago when the switch expression is either 10, 20 or 30;
increments Value4 for all switch expression values above 40;
and increments Value5 for any other values of the switch expression.



Source: EasyLanguage manual
Tams is offline  
Reply With Quote
The Following 3 Users Say Thank You to Tams For This Useful Post:
aaa (11-07-2009), Blu-Ray (07-21-2009), iwannatoscript (10-28-2010)
Old 07-21-2009, 01:18 AM   #2

Tams's Avatar

Join Date: Sep 2008
Location: Geelong
Posts: 3,779
Ignore this user

Thanks: 2,084
Thanked 1,474 Times in 912 Posts

Re: Switch/Case (EasyLanguage)

Example...

Code:
switch (BarType)
begin

   case 0:
      {this is a Tick or Contract chart}

   case 1:
      {this is a Decond, Minute, or Hourly chart}

   case  2:
      {this is a Daily chart}

   case  3:
      {this is a Weekly chart}

   case 4:
      {this is a Months, Quarters, or Yearly chart}

   case 5: 
      {this is a Points or Changes chart}

end; // end of switch
Tams is offline  
Reply With Quote
Old 11-03-2009, 01:06 AM   #3

Tams's Avatar

Join Date: Sep 2008
Location: Geelong
Posts: 3,779
Ignore this user

Thanks: 2,084
Thanked 1,474 Times in 912 Posts

Re: Switch/Case (EasyLanguage)

The above code is a lot more elegant than the traditional way of filtering:

Code:
if BarType = 0 then
begin
      {this is a Tick or Contract chart}
end
else
if BarType = 1 then
begin
      {this is a Second, Minute, or Hourly chart}
end
else
if BarType = 2 then
begin
      {this is a Daily chart}
end
else
if BarType = 3 then
begin
      {this is a Weekly chart}
end
else
if BarType = 4 then
begin
      {this is a Months, Quarters, or Yearly chart}
end
else
if BarType = 5 then
begin
      {this is a Points or Changes chart}
end; 

// end of filtering
__________________



Only an idiot would reply to a stupid post
Tams is offline  
Reply With Quote
The Following User Says Thank You to Tams For This Useful Post:
aaa (11-07-2009)

Reply

Tags
case, switch

Thread Tools
Display Modes Help Others By Rating This Thread
Help Others By Rating This Thread:


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trendline (EasyLanguage) Tams Coding Forum 43 07-09-2011 12:36 AM
A Case for @ES Double Bottom... suriNotes Technical Analysis 17 11-08-2009 01:37 AM
[ER2] Why Traders Should Not Switch to the ICE to trade the Russell 2000 in September forsearch E-mini Futures Trading Laboratory 4 08-14-2008 11:26 AM
A Case for a Mid-Term Equity Bottom atto Market Analysis 18 08-13-2008 12:11 PM
Some EasyLanguage Help Please jjthetrader Coding Forum 8 06-02-2008 04:20 PM

All times are GMT -4. The time now is 01:32 PM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
CS to VB integration by DeskLancer
©2006-2011 Traders Laboratory, All Rights Reserved.