Announcement

Collapse
No announcement yet.

Using getBartState Command

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

  • Using getBartState Command

    I have written an EFS, which is designed to provide me with an alert when the 2 min Stochastics crosses down.

    The added condition I required is that when the 2 min Stochastics crosses down, at the same point in time, the 1 min K line must be going up.

    When I apply this EFS to the stock GSF, on Wednesday, June 6th, the alert works several times, but I am expecting it to alert me at 10:48am and again at 11:24am, but it does not alert me.

    Can anyone provide me with some direction on why it did not trigger the alert?

    Sincerely

    Royce
    Attached Files

  • #2
    Using getBartState Command

    When using the getBarState command, I am finding that if I place this command within a 3 minute chart and am looking for my specified condition to be met and confirmed at the end of the 3 minutes, the alert seems to fire at the end of the 1st minute, not at the end of the 3 minutes.

    if (getBarState() == BARSTATE_NEWBAR){

    When using this command, regardless of the chart timeframe where it is placed, will it always check the condition based the first tick of every minute.

    If yes, is there a way to use getBarState, so that it checks the beginning of the next price bar, based on the chart timeframe where the command is being used.

    Thanks in Advance

    Royce

    Comment


    • #3
      Royce
      getBarState() returns BARSTATE_NEWBAR on the first tick of each new bar of a chart.
      If you want to base your conditions on the bar state of an external interval and/or symbol you need to use either the getBarStateInterval() or getBarStateSymbol() functions (see the links for the corresponding descriptions and syntax)
      Alex

      Comment


      • #4
        Hello Royce,

        What interval was your chart set to?
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment


        • #5
          Thanks Alex

          I will give it a try.

          Royce

          Comment


          • #6
            Royce
            You are most welcome
            Alex

            Comment


            • #7
              Hi Alex, hopefully you can give me further assistance. I am trying to create an alert, that alerts me when the 1 min Stochastics crosses up, at the same time the 2 min Stochastics crosses up. The confirmed cross for both timeframes at the end of the 2 minute period.

              From my results, it seems like the 1 min is crossing, a minute goes by and then the 2 min Stoch crosses. I must be missing something.

              I am providing a sample of the EFS, if you wouldn't mind looking at it to let me know where I might be going wrong.

              P.S. I have loaded the EFS on a 1 minute chart and also tried on a 2 minute chart. I get different results, I don't believe either of the results are correct.

              Thanks

              Royce

              function main() {

              var vStK1_01 = stochK(14 ,3 ,3, inv(1));
              var vStD1_01 = stochD(14 ,3 ,3, inv(1));

              var vStK1_1 = stochK(14 ,3 ,3, inv(1), -1);
              var vStK1_2 = stochK(14 ,3 ,3, inv(1), -2);
              var vStK1_3 = stochK(14 ,3 ,3, inv(1), -3);
              var vStD1_1 = stochD(14 ,3 ,3, inv(1), -1);
              var vStD1_2 = stochD(14 ,3 ,3, inv(1), -2);
              var vStD1_3 = stochD(14 ,3 ,3, inv(1), -3);

              var vStK2_01 = stochK(14 ,3 ,3, inv(2));
              var vStD2_01 = stochD(14 ,3 ,3, inv(2));

              var vStK2_1 = stochK(14 ,3 ,3, inv(2), -1);
              var vStK2_2 = stochK(14 ,3 ,3, inv(2), -2);
              var vStD2_1 = stochD(14 ,3 ,3, inv(2), -1);
              var vStD2_2 = stochD(14 ,3 ,3, inv(2), -2);

              if ((vStK2_01 >= vStD2_01 && vStK2_1 <= vStD2_1) && (vStK1_01 >= vStD1_01 && vStK1_1 <= vStD1_1)){
              if (getBarStateInterval(2) == BARSTATE_NEWBAR){
              if (vStK2_01 >= vStD2_01 && vStK2_1 <= vStD2_1){
              Alert.addToList(getSymbol(), "LONG - True 1&2 X At the End of 2 Min period "+close(0), Color.RGB(0,0,0), Color.RGB(0,255,0));
              Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Ding.wav");
              setChartBG(Color.RGB(215,255,195));
              }
              }
              }

              Comment


              • #8
                Hi Jason

                I am hoping for a 2 minute interval.

                Also, here are my defined variables

                var vStK1_01 = stochK(14 ,3 ,3, inv(1));
                var vStD1_01 = stochD(14 ,3 ,3, inv(1));

                var vStK1_1 = stochK(14 ,3 ,3, inv(1), -1);
                var vStK1_2 = stochK(14 ,3 ,3, inv(1), -2);
                var vStD1_1 = stochD(14 ,3 ,3, inv(1), -1);
                var vStD1_2 = stochD(14 ,3 ,3, inv(1), -2);

                var vStK2_01 = stochK(14 ,3 ,3, inv(2));
                var vStD2_01 = stochD(14 ,3 ,3, inv(2));

                var vStK2_1 = stochK(14 ,3 ,3, inv(2), -1);
                var vStK2_2 = stochK(14 ,3 ,3, inv(2), -2);
                var vStD2_1 = stochD(14 ,3 ,3, inv(2), -1);
                var vStD2_2 = stochD(14 ,3 ,3, inv(2), -2);

                Royce

                Comment


                • #9
                  P.S.

                  Alex, I have also tried the EFS with

                  if (getBarStateInterval("2") == BARSTATE_NEWBAR){

                  }

                  Still does not seem to provide the correct results

                  Royce

                  Comment


                  • #10
                    Hi Alex

                    Can you look at the following EFS, it is designed to alert me when the 1 min and 4 min both cross at the end of the 4 min period. I am loading this EFS on a 4 min chart.

                    The thing I don't understand, is if you load this EFS and run it during the following date and time, I expect an alert, but do not get one, I am not sure why I did not receive an expected alert.

                    Stoch GSF
                    Date: 06/07/07
                    Time: 9:36am

                    Thanks

                    Royce
                    Attached Files

                    Comment


                    • #11
                      Hi Alex

                      After another sleepless night, I think I have found the error of my ways, tell me if I am correct.

                      The reason, the EFS was not working is because I have to many if statements which confuses my goal, this is the change I have made.

                      Sample

                      if (getBarStateInterval("4") ==BARSTATE_NEWBAR){
                      if ((vStK4_01 > vStD4_01 && vStK4_1 < vStD4_1) &&
                      (vStK1_01 > vStD1_01 && vStK1_1 < vStD1_1)){
                      Alert.addToList(getSymbol(), "LONG - True 1&4 X At the
                      End of 4 Min period Ver 3 "+close(0), Color.RGB(0,0,0),
                      Color.RGB(0,255,0));
                      Alert.playSound("C:\\Program
                      Files\\eSignal\\Sounds\\Ding.wav");
                      setChartBG(Color.RGB(215,255,195));
                      }
                      }

                      I have also attached the modified version of the EFS.

                      Royce
                      Attached Files

                      Comment


                      • #12
                        Hi Alex

                        Another quick question: Is it true that regardless of stock, the time the stock opens, regardless of what exchange that all calculations based on the close of a 4 minute period, begins at 9:30am.

                        Therefore the first 4 min period end is 9:34am
                        9:38am, 9:42am, ....

                        I believe this is correct, but there are time on the New York exchange whereby all stocks to not necessarily open right at 9:31:01am ??

                        Royce

                        Comment


                        • #13
                          Royce

                          The reason, the EFS was not working is because I have to many if statements which confuses my goal, this is the change I have made
                          From what I am seeing the reason it was not working properly was not because there were too many if statements but because some of those if statements were outside of the BARSTATE_NEWBAR conditional statement hence they were being evaluated on every tick rather than on completed bars.

                          Is it true that regardless of stock, the time the stock opens, regardless of what exchange that all calculations based on the close of a 4 minute period, begins at 9:30am
                          Assuming that the Time Template for that interval is set to start at 9:30 that is correct.

                          Therefore the first 4 min period end is 9:34am
                          9:38am, 9:42am,
                          No. The period that started at 9:30 ends at 9:33:59.
                          9:34, 9:38 9:42 will be the starting times of the subsequent periods (and the time stamps for those bars as eSignal timestamps use the starting time of the period)

                          I believe this is correct, but there are time on the New York exchange whereby all stocks to not necessarily open right at 9:31:01am ??
                          I don't trade stocks so I may not be the appropriate person to ask this question. Anyhow as far I know stocks don't necessarily always open at 9:30 on the NYSE. Regardless if they trade anywhere between 9:30:00 and 9:33:59 the first bar will be time stamped 9:30.
                          Alex

                          Comment

                          Working...
                          X