Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

Sign in to follow this  
Tams

Switch/Case (EasyLanguage)

Recommended Posts

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

 

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

Share this post


Link to post
Share on other sites

Example...

 

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

Share this post


Link to post
Share on other sites

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

 

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Topics

  • Posts

    • NFLX Netflix stock watch for a breakout above 691.3, target 736-739 area, https://stockconsultant.com/?NFLX
    • Date: 5th July 2024. NFP Is Here! How Will Today’s NFP Impact The NASDAQ Labour win UK Elections, receiving an unconditional majority of seats in the House of Commons (410 out of 650). The British Pound and FTSE100 increase in value as Labour wins an outright majority. The Japanese Yen sharply increases in value as the US Dollar underperforms ahead of the US employment data. Investors turn their attention to today’s NFP release and Unemployment Data! USA100 The NASDAQ quickly increases in value as the Asian Market opens and the US bank holiday ends. Investors now turn their attention to this afternoon’s employment data. This morning the price quickly rose 0.48%, continuing the trend of the past week. The “bullish” momentum that accelerated throughout the week as positions in the US Dollar weakened is gradually slowing down ahead of today’s release of the June labor market report. This report could influence the US Federal Reserve’s decision on reducing borrowing costs by the end of the year. Earlier in the week, Fed Chair Jerome Powell delivered a speech, and the June meeting minutes were released. The market reacted with a higher risk appetite, even though officials reiterated the need for further evidence of inflation reduction to the target 2.0% before initiating a monetary easing program. Investors also continue to position themselves for the upcoming earnings data and an interest rate cut in September 2024. An ideal NFP release for the stock market will be a slightly worser reading. For example, NFP to come in as expected but for the unemployment rate to rise to 4.1%. This afternoon’s employment data is likely to trigger significantly higher volatility. However, investors will also be concerned if the price of oil continues to rise as it has over the past 4 weeks. If the NFP data triggers higher oil prices, investors will be cautious that it does not apply upward pressure on US inflation. Analysts expect the NFP to add a further 191,000 employed individuals. Currently the price is trading at an all-time high and is witnessing buy signals. The price forms a bullish crossover and trades significantly above most moving averages. However, the price is not yet thought to be overpriced based on the RSI. All global indices trade higher, which indicates a strong sentiment towards the equity markets. Lastly, of the top 5 most influential stocks for the NASDAQ, 4 are trading higher in pre-trading hours. This includes Microsoft, Apple, Alphabet and Amazon. Currently, NVIDIA trades 0.15% lower. Always trade with strict risk management. Your capital is the single most important aspect of your trading business. Please note that times displayed based on local time zone and are from time of writing this report. Click HERE to access the full HFM Economic calendar. Want to learn to trade and analyse the markets? Join our webinars and get analysis and trading ideas combined with better understanding on how markets work. Click HERE to register for FREE! Click HERE to READ more Market news. Michalis Efthymiou Market Analyst HFMarkets Disclaimer: This material is provided as a general marketing communication for information purposes only and does not constitute an independent investment research. Nothing in this communication contains, or should be considered as containing, an investment advice or an investment recommendation or a solicitation for the purpose of buying or selling of any financial instrument. All information provided is gathered from reputable sources and any information containing an indication of past performance is not a guarantee or reliable indicator of future performance. Users acknowledge that any investment in FX and CFDs products is characterized by a certain degree of uncertainty and that any investment of this nature involves a high level of risk for which the users are solely responsible and liable. We assume no liability for any loss arising from any investment made based on the information provided in this communication. This communication must not be reproduced or further distributed without our prior written permission.
    • CROX Crocs stock attempting to move higher off the 146.82 triple support area, price target 162-166 area, https://stockconsultant.com/?CROX
    • TTD Trade Desk stock narrow range breakout watch, https://stockconsultant.com/?TTD
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.