Loading ...
Sorry, an error occurred while loading the content.

Counting bars since a specific event

Expand Messages
  • Erik
    Anyone know how to count the number of bars in ThinkScript from an event? Specifically, what I m trying to do is trigger a buy signal from 3 higher closing
    Message 1 of 3 , Mar 4 10:51 PM
    • 0 Attachment
      Anyone know how to count the number of bars in ThinkScript from an
      event?

      Specifically, what I'm trying to do is trigger a buy signal from 3
      higher closing bars. Easy enough, but I don't want them to have to
      be all in a row. I want to allow the stock to chop around a while,
      and still fire a signal on the 3rd high close.
      Also, any price below the low of the first bar in the sequence should
      reset everything, and start counting over.

      There seems to be a requirement of an "ELSE" parameter in an IF
      statement with ThinkScript. So after the first higher close sets the
      appropriate trigger price/stopout price, the next bar (if it doesn't
      make another higher high) will reset the thing, because my IF close >
      close[1] statement will be false, and the ELSE kicks in, resetting it
      to zero.

      If I could reference "close[NumberOfBars]" via a counter of some
      sort, I could reference back to the first bar, no matter how long it
      takes.

      Alternatively, if I could say "IF blah-blah, ELSE don't do a damn
      thing", that would also work.

      Any thoughts? It certainly feels like I'm missing something very,
      very simple, but I'm going nuts here.

      Thanks,
      Erik
    • mdb770
      There are two things you could try to employ: 1. Count bars from the beginning: def currBar = TotalSum(1); 2. Use freeze command to preserve this count when
      Message 2 of 3 , May 29, 2008
      • 0 Attachment
        There are two things you could try to employ:

        1. Count bars from the beginning:
        def currBar = TotalSum(1);

        2. Use "freeze" command to preserve this count when the event
        triggers. The difference between the two could give you "BarsSince"


        --- In TOS_thinkscript@yahoogroups.com, "Erik" <erikc@...> wrote:
        >
        > Anyone know how to count the number of bars in ThinkScript from an
        > event?
        >
        > Specifically, what I'm trying to do is trigger a buy signal from 3
        > higher closing bars. Easy enough, but I don't want them to have to
        > be all in a row. I want to allow the stock to chop around a while,
        > and still fire a signal on the 3rd high close.
        > Also, any price below the low of the first bar in the sequence
        should
        > reset everything, and start counting over.
        >
        > There seems to be a requirement of an "ELSE" parameter in an IF
        > statement with ThinkScript. So after the first higher close sets
        the
        > appropriate trigger price/stopout price, the next bar (if it
        doesn't
        > make another higher high) will reset the thing, because my IF close
        >
        > close[1] statement will be false, and the ELSE kicks in, resetting
        it
        > to zero.
        >
        > If I could reference "close[NumberOfBars]" via a counter of some
        > sort, I could reference back to the first bar, no matter how long
        it
        > takes.
        >
        > Alternatively, if I could say "IF blah-blah, ELSE don't do a damn
        > thing", that would also work.
        >
        > Any thoughts? It certainly feels like I'm missing something very,
        > very simple, but I'm going nuts here.
        >
        > Thanks,
        > Erik
        >
      • Erik
        Thanks for the response! Can you tell me how to use the FREEZE command? I couldn t ever get that to work for me.
        Message 3 of 3 , Jun 2, 2008
        • 0 Attachment
          Thanks for the response!

          Can you tell me how to use the FREEZE command? I couldn't ever get
          that to work for me.
        Your message has been successfully submitted and would be delivered to recipients shortly.