Announcement

Collapse
No announcement yet.

code question?

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

  • code question?

    I have 2 question if anyone could help me with these.

    First:

    If I use this example code below the efs executes fine

    Code:
    close() < (high(-1)+low(-1))/2
    But if I use this, the code will not work:

    Code:
    close() < (high(-1)+low(-1))/1.5
    Second:

    Lets say I have a code where I want 2 possible long triggers and 2 possible sell triggers. If one long trigger is true the other would be false and would not be able to trigger until one of the 2 sell triggers was true.

    Any help would be appreciated.

    Fibbgann
    Last edited by FibbGann; 09-07-2004, 07:31 AM.
    Excellent book on JavaScript for beginners

  • #2
    FibbGann,

    in your code examples...are these "if" statements? Could you post the whole line?

    As for the second part of your question, just add a state variable that will be set to 1 if you are long, -1 if short and 0 if flat. Then check to verify that it isn't 1 when your long condition is true and isn't -1 when your short condition is true.

    ie:

    var nTradeState = 0;

    function main(){
    .
    .
    .
    if (nShortMA > nLongMA && nTradeState != 1){
    nTradeState = 1;
    .
    .
    .
    if (nShortMA < nLongMA && nTradeState != -1){
    nTradeState = -1;
    .
    .
    .


    Garth
    Garth

    Comment


    • #3
      Yes they are "if" and "else if" statements, and that was the whole line. hehe

      It seems that when using decimals in divisions efs does'nt want to recognize it.

      Code:
      if (
      close() > (open(-1)+close(-1))/2
              ) onAction1()
      using

      /2

      is ok

      using

      /1.5

      is not

      Thanks,

      Garth
      Last edited by FibbGann; 09-07-2004, 08:41 AM.
      Excellent book on JavaScript for beginners

      Comment


      • #4
        FibbGann,

        By the whole line, I mean the "if" part and the associated "(" and ")"'s.

        I do A LOT of ratio math in my EFS's and don't have a problem doing decimal divides. So unless the problem is that you are using a litteral (ie: 1.5) whereas I am using variables (usually the result of some other ratio calculation) I don't think that this is the problem. Therefore I suspect it is someplace else.

        This would be easy to check on your side...just define:

        var OneAndAHalf = 1.5;

        and use the var instead. But I really suspect the problem is elsewhere.

        Garth
        Garth

        Comment


        • #5
          More help...

          Fibb,

          Try adding () around all of your statements - like this..

          if (close() < ((high(-1)+low(-1))/2)) {
          }

          if (close() < ((high(-1)+low(-1))/1.5)) {
          }

          Sometimes, being more specific about the ORDER of your math functions plays an important role in the outcome of your code. I try to force myself to do this ALL THE TIME.

          Second:

          Lets say I have a code where I want 2 possible long triggers and 2 possible sell triggers. If one long trigger is true the other would be false and would not be able to trigger until one of the 2 sell triggers was true.

          This gets a little tricky - because there are two types of situations that can happen.

          1. We are waiting for both triggers to happen on the same bar (and only on the same bar)
          2. We are waiting for both triggers to be active at the same time (but can be generated from previous bars). Meaning trigger #1 could turn bullish 15 bars ago and trigger #2 turned bullish on the current bar - thus BUY.

          #1 is easy, just use an if ((trigger1) && (trigger2)) { function.

          #2 is a bit more tricky, you have to check for the trigger setups (as variables) and track these conditions. Next, you need a control variable (are we LONG(1), SHORT(-1) or FLAT(0)) - we'll call this TrendDirection. This will help direct the systems actions.

          Now, you would use a similar "if" statement to generate your triggers.

          if ((trigger1) && (trigger2) && (TrendDirection <=0)) {
          // if both BUY triggers and we are not currently long.

          This is the basic structure for the variable timed multiple entry trigger strategy.

          Hope this helps..

          B
          Brad Matheny
          eSignal Solution Provider since 2000

          Comment


          • #6
            FibbGann,

            FYI,

            A simple test EFS to show that you can divide by a decimal litteral is attached. Run with no problem and produces the correct answer.

            Garth
            Attached Files
            Garth

            Comment


            • #7
              Thanks alot guys, I will play with this over the next few days.
              Attached Files
              Excellent book on JavaScript for beginners

              Comment

              Working...
              X