Download MetaTrader 5
To add comments, please log in or register
Documentation is available in CHM and PDF. Download it in any convenient form!
Mihai Ionescu
Mihai Ionescu 2015.06.03 18:15 

I have the following code:


switch (_ap) {
      case PRICE_CLOSE: s = "Close Price";
      case PRICE_OPEN: s = "Open Price";
      case PRICE_HIGH: s = "High Price";
      case PRICE_LOW: s = "Low Price";
      case PRICE_MEDIAN: s = "Median Price";
      case PRICE_TYPICAL: s = "Typical Price";
      case PRICE_WEIGHTED: s = "Weighted Price";
      default: s = "";
//now s=="Weighted Price"
//is this normal?


 Initially, I didn't put any break, i thought it was ok.

But now I'm confused, even after I read docs about switch command. 

Drazen Penic
Drazen Penic 2015.06.03 19:17  

Here is excerpt from help on switch operator:

"The case keyword with a constant are just labels, and if operators are executed for some case variant, the program will further execute the operators of all subsequent variants until the break operator occurs. It allows to bind a sequence of operators with several variants."


Switch jumps to the first case that matches value and executes all subsequent orders until break or end of switch block.

Mihai Ionescu
Mihai Ionescu 2015.06.05 12:51  

Thank you for clarification.


I read that in docs, but now it sounded clearer from you.

To add comments, please log in or register