Announcement

Collapse
No announcement yet.

switch (Step)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • switch (Step)

    Anyone know of any good examples showing the use of the

    switch (Step)

    function?

    I have seen one at

    http://www.dynaorder.com/esExamples/doFollowPL.asp

    and I wrote this one

    http://share.esignal.com/download.js...witchDemo1.efs

    to color the bars based on the close above a ma but I still don't quite get the idea

  • #2
    David:

    It's just an alternative to if/then loops... makes the code a little easier to manage and read.

    var DayOfWeek;

    DayOfWeek = retrieveDay();

    switch( DayOfWeek ) {
    case 1: doSundayTask(); break;
    case 2: doMondayTask(); break;
    case 3: doTuesdayTask(); break;
    case 4: doWednesdayTask(); break;
    default: doSomeOtherTask(); break;
    }

    Chris

    Comment


    • #3
      thanks Chris, I am getting the hang of it now...

      var Step = 0;

      function preMain()
      { setStudyTitle("SwitchDemo2");
      debugClear();
      setPriceStudy(true);
      }

      function main()
      { if (getCurrentBarIndex()==0)
      {
      switch(Step)
      {
      case 0:
      setPriceBarColor(Color.yellow);
      debugPrintln("case "+Step+": yellow bars");
      Step++;
      break;

      case 1:
      setPriceBarColor(Color.lime);
      debugPrintln("case "+Step+": lime bars");
      Step++;
      break;

      case 2:
      setPriceBarColor(Color.red);
      debugPrintln("case "+Step+": red bars");
      Step=0;
      break;
      }
      }
      }

      Comment

      Working...
      X