Announcement

Collapse
No announcement yet.

LR / MA Retracement

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

  • LR / MA Retracement

    If someone could please help,

    What is the manner of "marking a bar" that creates a true condition (i.e. when an LR /MA is below another MA - black dashed line with downward slope) and then after an upward retracement of the black dashed line and then turning again to the original downward direction shows that it has gone through this retracement cycle and shows as true again (down)? The barcount between the original true (downward) condition and then the "new" downward condition would need to be flexible.

    Please see attached image. Hope my question makes sense.

    TIA for any help you can offer.
    Kirk
    Attached Files
    Last edited by zeller4; 10-31-2007, 03:55 PM.

  • #2
    Kirk,

    This is a general programming issue where you wait for condition 1 to occur (MA below another MA and sloping down), then wait for condition 2 to occur (retracement) and then wait for condition 3 to occur (MA moving down again).

    The best way I've found to code this is by using a state machine design. You define states for each condition, along with a state where you are waiting for condition 1 to occur. You define a variable that holds the present state, and use this in function main in a switch statement to call a "state" function that handles that particular state. You would have one function for each state and they would simply check if they should go to a new state or stay in the current one.

    I've attached a sample state machine template which demonstrates these priciples. It can be used as a starting point for a state machine design.

    Not sure what you mean by "marking a bar". Do you mean draw an arrow or change the bar color or display text by the bar?

    Steve
    Attached Files

    Comment


    • #3
      what I mean by "marking the bar is" indicating that the condition is currently true - whether it is 3 bars ago or 10. I can do the drawtext or barBg things...

      for example, if STATE_CONDITION1 is true when the LR line is sloping down (same direction of the longer MAs AND below them) and then we get a STATE_CONDITION2 ( rising LR lines but still below downward sloping MAs), then resuming a downward slope of LR lines (STATE_CONDITION3) - that's when I want to be notified that it has gone through this retracement scenario before entering a short. quantity of bars for any one STATE_CONDITION wouldn't necessarily matter. I'm assuming only one STATE_CONDITION is true at any one point in time...

      hope that makes sense,

      (Still reviewing your detailed code example - learning a new language indeed!)

      Thanks Steve,

      Much appreciated.

      Kirk Zeller
      Last edited by zeller4; 11-01-2007, 02:07 PM.

      Comment


      • #4
        Kirk,

        That's what I thought you meant.

        In your case it sounds like you want to get an indication on just one bar when your sequence of conditions becomes true.

        Keep in mind you may also want to have transitions that would cancel the condition and force you back to the idle state. For example what do you do if the rising LR line goes above the MA? What if the MA's aren't sloping down anymore?

        Just some things to think about. The nice thing about a state machine design is you can easily add additional "cancel" conditions to put you back into the idle state.

        Steve

        Comment


        • #5
          Steve,

          thanks for that explanation.
          did some reading in the kb for "switch, case, break and function"

          so if I understand correctly,

          the function Idle could have several conditional if statements to move the state from Idle to another state (ie. condition1, or cond.2, or long, or short)
          I'm assuming the states are mutually exclusive.
          the functions at the bottom are the portions of script for the strategy and drawing or text objects. I thought function subroutines had a return statement in them?

          do you ever have if then "else" in the functions? or only "if" (multiple times as needed)

          in the "switch, case, break" section, after it finds the corresponding case, it breaks to the function?

          I'll try a couple sample routines for my next post.

          thanks again,
          Kirk

          Comment


          • #6
            Kirk,

            Originally posted by zeller4
            Steve,

            thanks for that explanation.
            did some reading in the kb for "switch, case, break and function"

            so if I understand correctly,

            the function Idle could have several conditional if statements to move the state from Idle to another state (ie. condition1, or cond.2, or long, or short)
            I'm assuming the states are mutually exclusive.


            That is correct. You are only in one state at a time, and you use conditional statements to control moving from one state to another.

            the functions at the bottom are the portions of script for the strategy and drawing or text objects. I thought function subroutines had a return statement in them?
            You only need a return statement if you are returning a value or you want to exit the function early. For example, in the if conditional statements, when you find a condition that changes the state, you can put a return at the end of the if statement because you know you don't need to check the other conditions.
            if(condition == true)
            {
            vState = some_state;
            return;
            }

            You can put a return before the closing } of the function if you want, but JavaScript knows to return at the end of the function without it.

            The code in the functions handle how the state is processed. So if you are in the "Idle" state, you call only the Idle function. If a condition is met, you go to another state. But that state's function won't be called until the next tick.

            do you ever have if then "else" in the functions? or only "if" (multiple times as needed)
            You can have any combination of if/else or switch statements. I was just giving you an example of one way to do the condition testing.

            in the "switch, case, break" section, after it finds the corresponding case, it breaks to the function?
            The way the switch works, it's like a whole bunch of if statements. So if a case matches, it will run the code from that case until it hits a break statement or the end of the switch statement. The break statements are kind of like goto statements that say go to the end of the switch statement and run code from there. So you jump out of the switch statement when you hit a break statement.

            I'll try a couple sample routines for my next post.

            thanks again,
            Kirk
            Hope this helps.

            Steve

            Comment

            Working...
            X