Announcement

Collapse
No announcement yet.

Previous bar's values

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

  • #16
    Using another custom study, I referenced the previous bar value (-1 bar) as described earlier in this thread... but this time the method didn't work. Tried all kinds of variations.. but now out of ideas. The script will output the array alright, but I'm getting no shapes output from the if statements which include reference to the custom study prior bar value (lines 104-110). No syntax or formula error is reported in the formula output window.

    Thanks for any help.

    (Alex, do you have that write-up on retrieving historical bars of custom variables posted somewhere? I looked for it. Thx.)
    Attached Files

    Comment


    • #17
      Lancer
      The attached revision appears to be working now. Changes are commented in the efs.
      Alex

      PS. The write-up is not completed yet as I have been sidetracked by other things lately.
      Attached Files

      Comment


      • #18
        Hi,

        I have a few (related) questions to which I did not find sufficient explaination anywhere else.

        General information. I am trying to reduce the overhead by executing parts of the code only once/minute or once/bar, regardless of the chart interval.
        I tried what I thought should work, but I ran into unexpected false results.

        1. Is it true that on "NEWBAR" the getValue.AnyStudy returns null?
        If the answer is "no" please provide an example of simple efs that plot anything on NEWBAR only, in real time (real time is very important).
        If the answer is "yes", what is the best way to execute a piece of code only once per bar (without setting the ComputeOnClose, which is said that can be set only in premain)?

        2. Is it true that time functions (getHour, getMinute), return only the start time of the bar?
        If yes, as I suspect, how can we get higher granularity for a chart?
        Note: Counting ticks is not an option, as ticks have no time value and I want to run the entire code at least once per bar (prefer at close), parts of it every minute and some of it every tick.

        Thank you.
        Mihai buta
        Mihai Buta

        Comment


        • #19
          mbuta,

          1. Is it true that on "NEWBAR" the getValue.AnyStudy returns null?
          This hasn't been my experience, and I have a lot of studies that do their calculations only on NEWBAR. However, it would be easy to prove one way or the other just create a MA study that uses the MA builtin and only gets the latest MA on NEWBAR. Compare the results to an MA put on the chart from Basic Studies.

          2. Is it true that time functions (getHour, getMinute), return only the start time of the bar?
          This is what I have seen. I'm not aware of any way to get further granularity - short of setting up some lower interval chart (one that has a mod 0 of the higher interval chart would be best, but shouldn't be mandatory) and have the shorter interval chart set a universal global (setGlobalValue()) with the time which the higher interval chart reads on each tick (getGlobalValue()). Obviously depending on the activity of the symbol in question will determine your granularity.

          G
          Garth

          Comment


          • #20
            Hi G and thank you for your reply.

            Maybe I was not specific enough in my first question.

            1. Is it true that on "NEWBAR" get.value. AnyStudy(0) returns null, in real time?
            I know it returns correct values for previous bars, but what about (0) bar? Again, we talk about real time only.

            I asked the question because ALL my plots stop plotting in real time when "NEWBAR" is the trigger to plot. If I refresh (reload) they go to current bar, but nothing after that. I change to other condition than NEWBAR they plot as expected, all of them.

            2. On my second question, I saw many using the "rawTime" but never understood how to use it. Would that be a solution?
            Can you point to an example where I can see how to use it?

            Thank you.
            Mihai
            Mihai Buta

            Comment


            • #21
              Mihai,

              Regarding your second question, "rawTime" returns bar time. To get actual clock time, see this link http://forum.esignalcentral.com/show...+000#post30983.

              Comment


              • #22
                mbuta,

                1. Is it true that on "NEWBAR" get.value. AnyStudy(0) returns null, in real time?
                I don't usually specify the zero, but since that is the default I feel pretty confident saying it should work. Why not use debugPrintln and see if it prints out the correct value? This quick test will prove if you are getting valid rt values from your get.value().

                I asked the question because ALL my plots stop plotting in real time when "NEWBAR" is the trigger to plot. If I refresh (reload) they go to current bar, but nothing after that. I change to other condition than NEWBAR they plot as expected, all of them.
                You don't have enough info here for me to help you. Are you plotting using return() or one of the drawXXX() functions? Are you restricting your EFS so that plots only happen on NEWBAR?

                The best bet is to post the EFS in question, or come up with some small sample code that reproduces the error and post that. I find that often I find my errors when trying to create a mini-test case.

                Garth
                Garth

                Comment


                • #23
                  Hi Steve, Hi G,
                  Thank you for your replies.
                  I will take a look at the link you suggested Steve, thank you.

                  G,
                  I do not restrict plotting, I restrict code execution (the entire efs has over 4500 lines and executes "as neede" diferent sections).
                  Here is the basic setting:

                  var TimeToUpdate = 0;
                  var studyMAxx = ....
                  var MAxx = 0;

                  function premain() {...}
                  function main() {
                  var nBarState = getBarState;
                  TimeToUpdate = nBarState == BARSTATE_NEWBAR;
                  if (TimeToUpdate) {
                  execute some code
                  Plot for PriceStudyCase {
                  Build return Array
                  return Array;
                  }
                  else PlotNonPriceStudyCase{
                  Build Array
                  return Array;
                  }
                  }
                  return; //HAHA. I did not have this! => Never got here if TimeToUpdate==false. I will try and report if this was the problem.
                  }

                  Thank you.
                  Mihai
                  Mihai Buta

                  Comment

                  Working...
                  X