NexusFi: Find Your Edge


Home Menu

 





Switch Statement


Discussion in Platforms and Indicators

Updated
      Top Posters
    1. looks_one sr114 with 2 posts (0 thanks)
    2. looks_two Letmein with 2 posts (2 thanks)
    3. looks_3 vegasfoster with 1 posts (0 thanks)
    4. looks_4 rohitmf with 1 posts (0 thanks)
    1. trending_up 5,507 views
    2. thumb_up 2 thanks given
    3. group 4 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
Search this Thread

Switch Statement

  #1 (permalink)
 
DonStar's Avatar
 DonStar 
Dallas, TX
 
Experience: Intermediate
Platform: ToS, TradeGuider, eSignal, AmiBroker
Broker: TD Ameritrade/eSignal
Trading: Stocks
Posts: 77 since Dec 2011
Thanks Given: 28
Thanks Received: 43

Hi All and a Happy and Properous 2012 to us all!

I want to enhance the Title section of my charts by inserting the day of the week in front of the date: Friday, 12/30/2011.

The DayOfWeek() returns a number. So I need to convert the number to text that says what day it is.

Here is the code I have so far:

for( n = 0; n < 10; n++ )
{
printf("Current n = %f\n", n );

varDayOfWeek = DayOfWeek();

switch(varDayOfWeek)
{
case 0:
varDayOnChart == "Sunday";
printf("Day of week is ") + varDayOnChart + "\n";
break;
case 1:
varDayOnChart == "Monday";
printf("Day of week is ") + varDayOnChart + "\n";
break;
case 2:
varDayOnChart == "Tuesday";
printf("Day of week is ") + varDayOnChart + "\n";
break;
case 3:
varDayOnChart == "Wednesday";
printf("Day of week is ") + varDayOnChart + "\n";
break;
case 4:
varDayOnChart == "Thursday";
printf("Day of week is ") + varDayOnChart + "\n";
break;
}

The error occurs on the last line. The "}" is highlighted and the error message is : Syntax error, unexpected send. Is there semicolon missing at end of the previous line?"

Anyone who can help shed some light on fixing this?

Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
About a successful futures trader who didn´t know anyth …
Psychology and Money Management
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
What broker to use for trading palladium futures
Commodities
MC PL editor upgrade
MultiCharts
Cheap historycal L1 data for stocks
Stocks and ETFs
 
  #2 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,463 since Jun 2009
Thanks Given: 33,239
Thanks Received: 101,662

I typically use with { }

So:

switch (varDayOfWeek)
{

case 0:
{
varDayOnChart == "Sunday";
printf("Day of week is ") + varDayOnChart + "\n";
break;
}

}

But don't have AmiBroker or a C++ compiler, so can't say for sure if that is the syntax problem.

It has been a while since I used C++, but you should check strftime and you can format the time and just use a single deceleration with no switch statement.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #3 (permalink)
 vegasfoster 
las vegas
 
Experience: Intermediate
Platform: Sierra Chart
Broker: Velocity/IB
Trading: 6E
Posts: 1,145 since Feb 2010
Thanks Given: 304
Thanks Received: 844


Also, I don't see a close bracket for the open bracket below the for statement, unless you just aren't showing it.

Reply With Quote
  #4 (permalink)
 Letmein 
London, UK
 
Posts: 36 since Jul 2012

@OP,

you don't need switch

Instead use this function and put it to the Include folder of Amibroker e.g. as DayOfWeekName.afl or whatever name

 
Code
function DayOfWeekName()
{
	dow = DayOfWeek();
	dayStr = 
		WriteIf(dow == 0, "Sunday", 
		WriteIf(dow == 1, "Monday",
		WriteIf(dow == 2, "Tuesday",
		WriteIf(dow == 3, "Wednesday",
		WriteIf(dow == 4, "Thursday",
		WriteIf(dow == 5, "Friday",
		WriteIf(dow == 6, "Saturday", "Unknown")))))));

	return dayStr;
}


then in your main code call that function
 
Code
#include <DayOfWeekName.afl>;

dow = DayOfWeekName();

.
.
.
.


then the title of that main code could look as follows

 
Code
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} - " + dow + " {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

OR

you could use something completely different (so forget about the above one)

like this

 
Code
DayName = StrExtract("Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", SelectedValue(DayOfWeek()));

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} - " + DayName + " {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

Reply With Quote
  #5 (permalink)
sr114
Kolkata+India
 
Posts: 27 since Aug 2012
Thanks Given: 10
Thanks Received: 1

Letmein

Hello, i have a question, can the Step MA v7.2 of Igor can be ported in amibroker from MT4 ?

if yes can u pls do it - its an request

regards
sr114

Reply With Quote
  #6 (permalink)
 Letmein 
London, UK
 
Posts: 36 since Jul 2012


sr114 View Post
Letmein

Hello, i have a question, can the Step MA v7.2 of Igor can be ported in amibroker from MT4 ?

Yes, it can.


sr114 View Post
if yes can u pls do it

No. I have no time and no interest currently.

Reply With Quote
  #7 (permalink)
sr114
Kolkata+India
 
Posts: 27 since Aug 2012
Thanks Given: 10
Thanks Received: 1


Letmein View Post
Yes, it can.



No. I have no time and no interest currently.

thanx for the reply

sr

Reply With Quote
  #8 (permalink)
rohitmf
indore + india
 
Posts: 1 since Jun 2012
Thanks Given: 0
Thanks Received: 0


sr114 View Post
thanx for the reply

sr

Have Any other member converted Stepma v7.2.mt4 to Amibroker Afl ???

plz give a reply..

Reply With Quote




Last Updated on August 20, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts