NexusFi: Find Your Edge


Home Menu

 





Switch Statement


Discussion in Platforms and Indicators

Updated
      Top Posters
    1. looks_one Letmein with 2 posts (2 thanks)
    2. looks_two sr114 with 2 posts (0 thanks)
    3. looks_3 Big Mike with 1 posts (0 thanks)
    4. looks_4 DonStar with 1 posts (0 thanks)
    1. trending_up 6,383 views
    2. thumb_up 2 thanks given
    3. group 4 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
Search this Thread
  #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?
Without Pulisic, USA 61.5% Live vs. Australia -- France …
Prediction Markets & Event Contracts
CFTC Approves First US Bitcoin Perpetual Futures -- Kals …
Traders Hideout
Post-Summit Scorecard: $36M in May 15 Bets Settle Near-Z …
Prediction Markets & Event Contracts
Thursday May 28: GDP + Core PCE + Jobless Claims All at …
Traders Hideout
Hormuz Completely Closed: US Strikes Day 2, Iran Shoots …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
8 thanks
Darmok and Jalad at Tanagra
1 thanks
  #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,669 since Jun 2009
Thanks Given: 33,669
Thanks Received: 102,577

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 X 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: 845


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


© 2026 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 - Downloads - Top
no new posts