Announcement

Collapse
No announcement yet.

Q for the Java gurus out there

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

  • Q for the Java gurus out there

    Hi,

    If I am not mistaken, Java does not provide [like other languages] statements like: "go to" and "resume".

    However, the need to re-execute parts of the code, based on conclusions derived some time later exists.

    Here is the question: how can this be achieved in Java/efs?

    Specific example:
    I am using several time intervals in one efs and I apply a number of functions/calculation to each one of them, starting from the lowest interval up.
    Sometimes, when analyzing a higher interval, I discovered that I should have set a condition/state in a lower and I have no clue how to go back and re-execute that cycle and either [a] come back and continue, or [b] let it run the entire sequence again.

    I assume it is a common need and someone has a solution.
    Any help would be greatly appreciated.

    Thank you.
    Mihai Buta

  • #2
    Other related Q for the Java gurus

    A related situation to which I have no idea how to implement is the following:

    For the same time-interval I apply a number of calculations wich are inter-related. For example, Pivots are using the results from either the CCI OB/OS, or Stoch OB/OS, or MARSI OB/OS, depending on the situation.

    I have two options, either to store all the results and use them when I get to Pivots function in sequence [as I do now], or to call the Pivots function from the others, as a flip condition is dicovered.

    Second solution seems more logical, but don't know how to keep track/flag that a condition already called the Pivots function so, when I get to the Pivots function [in sequence] to know that is was already executed for that bar and I do not advance the Pivot Counter twice.

    Your help will be greatly appreciated.
    Thank you.
    Last edited by mbuta; 10-14-2007, 08:39 AM.
    Mihai Buta

    Comment


    • #3
      My solution to this would be to break up your sequence into functions, then as you step thru the sequence, you *could* recall the functions as needed to re-execute portions of your sequence.

      So, instead of having one big sequence in code - like this.

      PHP Code:
      function do_sequence() {
         do 
      this
         
      do that
         
      do the other
         
      do something else
         do 
      another thing
         
      do more things
         
      do still more
         
      do extras

      make them all functions - like this.

      PHP Code:
      function do_sequence() {
         
      do_this();
         
      do_that();
         
      do_the_other();
         
      do_something_else();
         
      do_another_thing();
         
      do_more_things();
         if (
      oops_recalcthen {
           
      do_the_other();
           
      do_something_else();
         }
         
      do_still_more();
         
      do_extras();

      Brad Matheny
      eSignal Solution Provider since 2000

      Comment


      • #4
        Brad,

        Thank you for your reply. I do have them as you say, in functions, and can call same function again, but cannot re-execute the sequence, which I am looking for, but seems to be no solution.

        Note: We'll see, someone [a guru] promissed again to call me this weekend to look at my work, but maybe got scared after looking at some samples.

        Thank you again.
        Mihai Buta

        Comment


        • #5
          Re: Other related Q for the Java gurus

          Hello Mihai,

          Originally posted by mbuta
          A related situation to which I have no idea how to implement is the following:

          For the same time-interval I apply a number of calculations wich are inter-related. For example, Pivots are using the results from either the CCI OB/OS, or Stoch OB/OS, or MARSI OB/OS, depending on the situation.

          I have two options, either to store all the results and use them when I get to Pivots function in sequence [as I do now], or to call the Pivots function from the others, as a flip condition is dicovered.

          Second solution seems more logical, but don't know how to keep track/flag that a condition already called the Pivots function so, when I get to the Pivots function [in sequence] to know that is was already executed for that bar and I do not advance the Pivot Counter twice.

          Your help will be greatly appreciated.
          Thank you.
          To track whether or not an execution of a specific routine has occurred can be accomplished with a global Boolean variable. Initialize the variable in the global scope and set it to false.

          Inside the routine that you want to track, set this variable to true. This variable (or flag) can then be used in subsequent conditional statements to check whether or not the routine in question was already executed. If the condition sees a true value for the flag, do not allow your code block to be executed.

          At some point in your formula code you will want to reset the flag back to false to allow your routine to be executed as needed. You can do this two ways. One is to reset the Boolean flag at the end of main() as the last line to be executed before your final return statement. This will allow the flag to be reset after each tick in real time processing. However, keep in mind that if you have more than one area in your formula that can hit a return statement, you may need to reset the flag before each of the return statements. The other option is to check for BARSTATE_NEWBAR at the very top of main() and reset the flag to false when that condition is true. This method will allow the flag to be set to true only once per bar.
          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


          • #6
            Jason, thank you.

            I was afraid of that answer. I actually do that for a lot of other "stuff", but with six time frames and quite a few studies and custom work on each one of them is getting messy, very messy and I am not smart enough to keep track of all of it.

            I did it for my indicators and states, if I add flags to each one of them, good luck to me!

            I did ask for help from advanced programmers, but several backed off after initial evaluation. This is not a two sma's crossing type of system, I understand that. Maybe somebody will decide to take the challenge.

            Thank you again.
            Mihai Buta

            Comment


            • #7
              The Real Q for Java Gurus

              Hi,

              I don't think I was very clear in previous two posts.

              What I am really looking for is some techniques to implement State Machines in Java/efs.

              State machines imply branching and looping back, based on diferent conditions. It can be called only once per bar, but its action can be to go back to a previous state and re-execute from there.

              Does anyone have any examples of code that implements state machines like design?

              Thank you.
              Last edited by mbuta; 10-15-2007, 04:37 PM.
              Mihai Buta

              Comment


              • #8
                Mihai,

                I've done a few state machine implementations, but I don't think that's what you really want. The problem with a state machine is that it can only change from one state to another per evaluation.

                It sounds like you want to go thru several "states" during the same evaluation. By evaluation I mean either a tick or a new bar.

                What you describe is more of a recursive algorithm.

                From what you've described, it sounds like you have a list of functions you call, and based on what the functions return you may alter the original function call list and make a new list. Is this correct?

                If that is correct, I would make a linked list of your functions to call. If one of them finds it needs to "recall" other functions it's a simple matter to add them into the linked list. Same thing if you find you don't need to call some functions you can remove them from the list while the script is running.

                Steve

                Comment

                Working...
                X