Announcement

Collapse
No announcement yet.

efs coding for "or"

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

  • efs coding for "or"

    Hi,

    This efs prgramming works fine when drawing a line on an individual basis for each x-rate:

    if ( sSym == "JPY A0-FX") {
    drawTextRelative..............
    }

    if ( sSym == "EURJPY A0-FX") {
    drawTextRelative.....................
    }




    To simplify things, is the following efs coding possible, so i can add as many x-rate symbols as i need into one line of coding:

    if ( sSym == "JPY A0-FX or "EURJPY A0-FX" or "CADJPY A0-FX") {
    drawTextRelative..............
    }


    Thanks,
    Paul

  • #2
    Hi Paul,

    Find info on logical operators at:



    Specifically, try:
    PHP Code:
    if ( sSym == "JPY A0-FX" || sSym == "EURJPY A0-FX" || sSym ==  "CADJPY A0-FX") {
    drawTextRelative..............

    Wayne

    Comment


    • #3
      Paul,

      There are several ways to do what you want with JavaScript (the language EFS uses). Some of them are:

      - Use a logical OR ("||") as Wayne has shown.
      - Put the strings you want to match in an array and scan the array, testing for a match.
      - Use a regular expression to test part of the string for a match.

      Since it seems what you want is to detect any string ending in " A0-FX", a regular expression would do what you want, detecting ANY symbol ending in " A0-FX":
      PHP Code:
      var isSymAMatch false;
      var 
      endingStringToMatch " A0-FX";

      function 
      main() {
          if (
      getBarState() == BARSTATE_ALLBARS) {
              
      // Test the end of the symbol to see if it matches:
              // (No need to do it on every call, just do it on ALLBARS.)
              
      var re = new RegExpendingStringToMatch "$""i" );
              
      isSymAMatch re.test getSymbol() );
          }

          
      // print out the result on every call, as if doing real processing.
          
      if (isSymAMatch) {
              
      debugPrintlngetSymbol() + " ends in [" endingStringToMatch "]" );
          } else {
              
      debugPrintlngetSymbol() + " does NOT end in [" endingStringToMatch "]" );
          }

      The "$" means the match must occur at the end of the string. The "i" means it is case insensitive (lower or uppercase doesn't matter).

      If you want, you could probably replace " A0-FX" with just "-FX" in the code above.
      Last edited by shortandlong; 02-13-2010, 07:57 PM.

      Comment


      • #4
        Hi wayne and shortandlong,

        I wanted to have different text displayed for Japanese Yen X-Rates only, so I have used the logical OR ("||"), which has worked great and saved me a lot of time and effort.

        Many thanks,
        Paul

        Comment

        Working...
        X