What do my switch always return last value?

 
Hi,

I am using this switch in my initialization function to set currency quotes for automatic lot-size calculation.

Unfortunately it always returns 1.01 as in case #7.
What is wrong here?

---
int init() {

string BaseCurrency = StringSubstr(Symbol(),0,3);
string CrossCurrency = StringSubstr(Symbol(),3,3);
string sQCQ;

if (CrossCurrency == "GBP") { QCQ = 1;sQCQ = "GBPUSD"; } if (CrossCurrency == "USD") { } // SET QUOTE CURRENCY FOR CALC IF NEEDED LATER
if (CrossCurrency == "EUR") { QCQ = 2;sQCQ = "EURUSD"; } if (CrossCurrency == "CHF") { QCQ = 5; sQCQ = "USDCHF"; }
if (CrossCurrency == "JPY") { QCQ = 3; sQCQ = "USDJPY"; } if (CrossCurrency == "AUD") { QCQ = 6; sQCQ = "AUDUSD"; }
if (CrossCurrency == "NZD") { QCQ = 4; sQCQ = "NZDUSD"; } if (CrossCurrency == "CAD") { QCQ = 7; sQCQ = "USDCAD"; }
if (BaseCurrency != "USD" && CrossCurrency != "USD")
{
if (IsVisualMode() == 1) // IF TESTER = TRUE (CANT READ VALUE FROM OTHER PAIR)
{
switch (QCQ)
{
case 1 : QCQPrice = 1.52 ;
case 2 : QCQPrice = 1.35 ;
case 3 : QCQPrice = 94.6 ;
case 4 : QCQPrice = 0.705;
case 5 : QCQPrice = 1.06 ;
case 6 : QCQPrice = 0.92 ;
case 7 : QCQPrice = 1.01 ;
default: Print("Quote calculation error during initialization");
}
PipValue = Point * DigitMultiplier / QCQPrice;
}
else // ELSE IF NOT TESTER READ QUOTE FROM PAIR
{
PipValue = Point * DigitMultiplier / iOpen(sQCQ,1,0);
} }

if (BaseCurrency == "USD") { PipValue = Point * DigitMultiplier / PriceNow; sQCQ = "Not needed for calc"; }
if (CrossCurrency == "USD") { PipValue = Point * DigitMultiplier; sQCQ = "Not needed for calc"; }
Print("McKeen EA v0.1b initialized for Currency trading on "+Pair+" chart using "+BrokerDigits+" digits");
Print("Pointvalue is "+DoubleToStr(NormalizeDouble(PipValue,2),2)+"$ / lot, sQCQ: "+sQCQ+" @ "+QCQPrice+" QCQ: "+QCQ); // THIS IS WHERE QCQPrice ALWAYS IS PRINTED AS 1.01 - WHAT IS WRONG WITH SWITCH ABOVE???
}
----
Thanks in advance for any suggestions...

/ McKeen


 
You need a break statement in every "branch" of the switch or deliberately order the cases in a way that makes use of its behavior. The switch is internally working like a GOTO to certain labels, each case is a label and it will jump to that label but then move on to the following labels (fall-through) until it encounters a break which will let it jump to the end of the switch.
 
7bit:
You need a break statement in every "branch" of the switch or deliberately order the cases in a way that makes use of its behavior. The switch is internally working like a GOTO to certain labels, each case is a label and it will jump to that label but then move on to the following labels (fall-through) until it encounters a break which will let it jump to the end of the switch.


Thanks alot, explains it all very well!

/ McKeen
 

Why are you even using the switch? Why write a value to a variable, just to use that variable as the switch to write another varibale. Why not just write the QCQPrice when you do the CrossCurrency check?