Announcement

Collapse
No announcement yet.

strategy using trend strength indicator

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

  • strategy using trend strength indicator

    I have downloaded the Trend strength indicator (TII.efs) and want to backtest it using a strategy of selling the close when the Trend indicator hits 0 and selling the close of the bar when the trend indcator hits 100. Can someone show me how to change the code to accomplish this. If possible i want to implement a 2 point stop in the strategy also.
    Thank
    yoda

  • #2
    eyeBdaJudge

    I can take a look at that if you tell me where I can find TII.efs

    Comment


    • #3
      Hi dloomis,
      If you go to the efs studies thread started by tssupport and you scroll down the page you will see a link to the tii.efs im talkking about. It will be a post called Trend strength indicator.
      Thanks

      Comment


      • #4
        I see

        Trend Intensity Index

        Is that it?

        Comment


        • #5
          try this in bacttest mode and see what happens, you may need to adjust the stop numbers, I am unclear how they are calculated

          /************************************************** *****************
          Description : This Indicator plots Trend Intensity Index indicator
          Provided By : Developed by TS Support, LLC for eSignal. (c) Copyright 2002
          ************************************************** ******************/

          function preMain() {

          setStudyTitle("Trend Intensity Index");
          setCursorLabelName("TII");
          setStudyMin(-1);
          setStudyMax(101);

          addBand(20, PS_SOLID, 1, Color.black);
          addBand(80, PS_SOLID, 1, Color.black);
          }

          var nLengthMA = 60;
          var nLengthTII = 30;

          function main() {
          var vMA = call("/Library/MA.efs", nLengthMA);

          var arC = close(0, -nLengthTII);
          if(arC == null)
          return;

          var i;
          var dSDP = 0, dSDM = 0;

          for(i = 0; i < nLengthTII; i++) {
          if(arC[i] > vMA) {
          dSDP +=arC[i] - vMA;
          } else if(arC[i] < vMA) {
          dSDM += vMA - arC[i];
          }
          }
          var tii= (dSDP / (dSDP + dSDM)) * 100;

          if(tii<=1){
          Strategy.doShort("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
          Strategy.setStop(close()+2);
          }

          if(tii>=99){
          Strategy.doLong("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
          Strategy.setStop(close()-2);
          }


          return (dSDP / (dSDP + dSDM)) * 100;
          }
          Last edited by dloomis; 03-01-2003, 08:31 AM.

          Comment


          • #6
            dloomis,
            Thanks
            Do you know of a way to code a strategy where you sell if low of trigger bar is taken out on next bar and buy if high of trigger bar is taken out. I say this becasue my actual stategy is buying if the TII hits 0 and the high of that bar is taken out on the next bar and vice versa for shorts
            Yoda

            Comment


            • #7
              David
              Something is amiss. I am getting odd results in backtest although the indicator is plotting correctly. Also the Buy/Sell are not at the values yoda indicated.
              Alex
              Last edited by ACM; 03-02-2003, 06:19 AM.

              Comment


              • #8
                alexis,
                I think the reason if that the strategy is long when tti<=1 and is short when tii>=99. the code has it reversed.
                Ps you will never find me ever criticizing anything here you guys are awesome

                Comment


                • #9
                  In your code I changed strategy .market to strategy .close so that the strategy buys on close of bar not open as that is unrealistic. Now since this is not an sar system i want to put in a profit objective of 1.5 points.
                  So would i simply add another strategy statement setting a stop in the other direction.
                  Yoda

                  Comment


                  • #10
                    Or you could leave strategy market and change thisbar to nextbar which I think is the method suggested by some.
                    Alex
                    Last edited by ACM; 03-01-2003, 09:39 AM.

                    Comment


                    • #11
                      Try this...

                      / **************************************************
                      *****************
                      Description : This Indicator plots Trend Intensity Index indicator
                      Provided By : Developed by TS Support, LLC for eSignal. (c) Copyright 2002
                      **************************************************
                      ******************/
                      var PTLevel = 1.50;
                      var PTPrice = 0;

                      function preMain() {

                      setStudyTitle("Trend Intensity Index");
                      setCursorLabelName("TII");
                      setStudyMin(-1);
                      setStudyMax(101);

                      addBand(20, PS_SOLID, 1, Color.black);
                      addBand(80, PS_SOLID, 1, Color.black);
                      }

                      var nLengthMA = 60;
                      var nLengthTII = 30;

                      function main() {
                      var vMA = call("/Library/MA.efs", nLengthMA);

                      var arC = close(0, -nLengthTII);
                      if(arC == null)
                      return;

                      var i;
                      var dSDP = 0, dSDM = 0;

                      for(i = 0; i < nLengthTII; i++) {
                      if(arC[i] > vMA) {
                      dSDP +=arC[i] - vMA;
                      } else if(arC[i] < vMA) {
                      dSDM += vMA - arC[i];
                      }
                      }
                      var tii= (dSDP / (dSDP + dSDM)) * 100;

                      // test for Profits
                      if ((Strategy.isLong()) && (high() >= PTPrice)) {
                      Strategy.doSell(, Strategy.LIMIT, Strategy.THISBAR, PTPrice);
                      }
                      if ((Strategy.isShort()) && (low() <= PTPrice)) {
                      Strategy.doCover(, Strategy.LIMIT, Strategy.THISBAR, PTPrice);
                      }


                      if(tii<=1){
                      Strategy.doShort("", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
                      Strategy.setStop(close()+2);
                      PTPrice = open(1) - PTLevel;
                      }

                      if(tii>=99){
                      Strategy.doLong("", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
                      Strategy.setStop(close()-2);
                      PTPrice = open(1) + PTLevel;
                      }


                      return (dSDP / (dSDP + dSDM)) * 100;
                      }
                      Brad Matheny
                      eSignal Solution Provider since 2000

                      Comment


                      • #12
                        Oops. Bug fix...

                        Try This....

                        / **************************************************

                        *****************
                        Description : This Indicator plots Trend Intensity Index indicator
                        Provided By : Developed by TS Support, LLC for eSignal. (c) Copyright 2002
                        **************************************************

                        ******************/
                        var PTLevel = 1.50;
                        var PTPrice = 0;

                        function preMain() {

                        setStudyTitle("Trend Intensity Index");
                        setCursorLabelName("TII");
                        setStudyMin(-1);
                        setStudyMax(101);

                        addBand(20, PS_SOLID, 1, Color.black);
                        addBand(80, PS_SOLID, 1, Color.black);
                        }

                        var nLengthMA = 60;
                        var nLengthTII = 30;

                        function main() {
                        var vMA = call("/Library/MA.efs", nLengthMA);

                        var arC = close(0, -nLengthTII);
                        if(arC == null)
                        return;

                        var i;
                        var dSDP = 0, dSDM = 0;

                        for(i = 0; i < nLengthTII; i++) {
                        if(arC[i] > vMA) {
                        dSDP +=arC[i] - vMA;
                        } else if(arC[i] < vMA) {
                        dSDM += vMA - arC[i];
                        }
                        }
                        var tii= (dSDP / (dSDP + dSDM)) * 100;

                        // test for Profits
                        if ((Strategy.isLong()) && (high() >= PTPrice)) {
                        Strategy.doSell(Strategy.LIMIT, Strategy.THISBAR, PTPrice);
                        }
                        if ((Strategy.isShort()) && (low() <= PTPrice)) {
                        Strategy.doCover(Strategy.LIMIT, Strategy.THISBAR, PTPrice);
                        }


                        if(tii<=1){
                        Strategy.doShort("", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
                        Strategy.setStop(close()+2);
                        PTPrice = open(1) - PTLevel;
                        }

                        if(tii>=99){
                        Strategy.doLong("", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
                        Strategy.setStop(close()-2);
                        PTPrice = open(1) + PTLevel;
                        }


                        return (dSDP / (dSDP + dSDM)) * 100;
                        }
                        Brad Matheny
                        eSignal Solution Provider since 2000

                        Comment


                        • #13
                          Thanks
                          Now to make this comprable to the actual method i am using i want to know if it is possible to code the strategy so that when
                          the TII closes>=99 that i enter a market order long only if the next bars price exceeds the high of the trigger bar(the bar on which the tii>=99) rather than just buying the open of the next bar.
                          For shorts the next bars price must exceed the low of the trigger bar then i enter a short order at market.
                          Once again thank you for your help here its greatly apprecaited

                          Comment


                          • #14
                            Brad,
                            When i implemented your version of the efs my indictator window shows nothing in it. does it have anything to do with the order in which the code is written.
                            i.e. should i put the test for entries before the tests for profits and stops
                            Thanks
                            Yoda

                            Comment


                            • #15
                              doji or any of you other efs gurus out there,

                              When i implement your code I now can get data for tii. However when i run a backtest/strategy analysis it shows losses greater than the stop loss. So if i understand this correctly the code as you have written it has me sell for a stop on the close of any bar that closes below my stop loss of 2 points. Is there a way that the backtest can show all my losses as 2 points regardless of where the bar i got stopped on closes not based on value of the close of the bar.
                              I also attempted to implement the code you wrote in the stategies thread so i can test exit strategies. However whenever i try to put in a code for testing for stops or profits i get no data on my screen at all for the tii indicator.
                              Does there need to be a ! everytime there is a strategy statement or maybe im doing something incorrect.
                              Basically i want the entry strategy to buy or sell the open of the next bar using a dual exit strategy of 1.5 point profit objective and 2 point stop and show all my wins as 1.5 points and all my losses as 2 points when i run the backtest.
                              In reality my actual system will only enter if the next bar prints above the high of the trigger bar for longs or prints below the low of the trigger bar for shorts. I dont know though if that is possible to program in an efs
                              Once again thanks for all your help

                              Comment

                              Working...
                              X