Announcement

Collapse
No announcement yet.

A strategy using combined signals

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

  • A strategy using combined signals

    I am wondering if someone could help with this problem which I have struggled with for a few days? I have several criteria that I am combining to then set a boolean variable which, in turn, is used in combination with other boolean variables to decide to doShort, doCover, doLong or doSell.

    For example :-


    // vSlowXAP Bearish colour change
    if (vSlowXAP_Current < (vSlowXAP_Previous-vRangeDiff)) {
    setBarFgColor(Color.red,1);
    bSlowXAP_Bearish = true;
    }

    // vFastXAP Bearish colour change
    if (vFastXAP_Current < (vFastXAP_Previous-vRangeDiff)) {
    setBarFgColor(Color.red,0);
    bFastXAP_Bearish = true;
    }

    When both booleans are set to true, I'd like the strategy to doShort or else to exit (doCover) to close the trade :-

    if (bSlowXAP_Bearish == true && bFastXAP_Bearish == true) {
    if (Strategy.isShort() == false) {
    Strategy.doShort("XAP Short", Strategy.OPEN, Strategy.NEXTBAR);
    }
    } else {
    if (Strategy.isShort() == true) {
    Strategy.doCover("XAP Short Close", Strategy.OPEN, Strategy.NEXTBAR);
    }
    }

    Quite simply this isn't generating any trades although the lines are set as the correct colour if I comment out the Strategy setting section.

    Any help would be appreciated.
    Last edited by daborn-fox; 05-02-2010, 03:58 PM.

  • #2
    Hi,
    try to reset booleans like this:

    // vSlowXAP Bearish colour change
    if (vSlowXAP_Current < (vSlowXAP_Previous-vRangeDiff)) {
    setBarFgColor(Color.red,1);
    bSlowXAP_Bearish = true;
    }

    // vFastXAP Bearish colour change
    if (vFastXAP_Current < (vFastXAP_Previous-vRangeDiff)) {
    setBarFgColor(Color.red,0);
    bFastXAP_Bearish = true;
    }

    When both booleans are set to true, I'd like the strategy to doShort or else to exit (doCover) to close the trade :-

    if (bSlowXAP_Bearish == true && bFastXAP_Bearish == true) {
    if (Strategy.isShort() == false) {
    Strategy.doShort("XAP Short", Strategy.OPEN, Strategy.NEXTBAR);
    }
    bSlowXAP_Bearish = false;
    bFastXAP_Bearish = false;
    } else {
    if (Strategy.isShort() == true) {
    Strategy.doCover("XAP Short Close", Strategy.OPEN, Strategy.NEXTBAR);
    }
    bSlowXAP_Bearish = false;
    bFastXAP_Bearish = false;
    }

    Let me know.
    Massimo

    Comment


    • #3
      Thank you, Massimo, but that didn't seem to change the outcome. I had set the initialisation values at the start of the execution sequence, although I accept this was not shown in the except I displayed. I have modified the code, as you suggest, and here's a slightly more revealing edition :-

      // vFastXAP Bullish colour change
      if (vFastXAP_Current > (vFastXAP_Previous+vRangeDiff)) {
      setBarFgColor(Color.green,0);
      bFastXAP_Bullish = true;
      }

      // vFastXAP Bearish colour change
      if (vFastXAP_Current < (vFastXAP_Previous-vRangeDiff)) {
      setBarFgColor(Color.red,0);
      bFastXAP_Bearish = true;
      }

      // vSlowXAP Bullish colour change
      if (vSlowXAP_Current > (vSlowXAP_Previous+vRangeDiff)) {
      setBarFgColor(Color.green,1);
      bSlowXAP_Bullish = true;
      }

      // vSlowXAP Bearish colour change
      if (vSlowXAP_Current < (vSlowXAP_Previous-vRangeDiff)) {
      setBarFgColor(Color.red,1);
      bSlowXAP_Bearish = true;
      }

      if (bSlowXAP_Bullish == true && bFastXAP_Bullish == true) {
      if (Strategy.isLong() == false) {
      Strategy.doLong("XAP Long", Strategy.OPEN, Strategy.NEXTBAR);
      }
      bSlowXAP_Bullish = false;
      bFastXAP_Bullish = false;
      } else {
      if (Strategy.isLong() == true) {
      Strategy.doSell("XAP Long Close", Strategy.OPEN, Strategy.NEXTBAR);
      }
      bSlowXAP_Bullish = false;
      bFastXAP_Bullish = false;
      }

      if (bSlowXAP_Bearish == true && bFastXAP_Bearish == true) {
      if (Strategy.isShort() == false) {
      Strategy.doShort("XAP Short", Strategy.OPEN, Strategy.NEXTBAR);
      }
      bSlowXAP_Bearish = false;
      bFastXAP_Bearish = false;
      } else {
      if (Strategy.isShort() == true) {
      Strategy.doCover("XAP Short Close", Strategy.OPEN, Strategy.NEXTBAR);
      }
      bSlowXAP_Bearish = false;
      bFastXAP_Bearish = false;
      }

      Comment


      • #4
        Sorry daborn-fox,
        but your example is not enough for me to understand and check the logic of conditions.
        It could be necessary to use if...else conditions or to reset booleans in a different way or position.
        Please give more informations.
        Massimo

        Comment


        • #5
          Massimo,

          Many thanks for your help, you were actually correct about the re-initialisation of the booleans. The remaining problem seemed to be that I was using Strategy.OPEN, Strategy.NEXTBAR rather than Strategy.CLOSE, Strategy.NEXTBAR

          It seems to be working now but I will need to find out how to enter the trade at the OPEN of the following bar rather than at the CLOSE.

          Thanks for your help and my apologies for not giving you enough information to help fully.

          Many thanks,

          Comment

          Working...
          X