Announcement

Collapse
No announcement yet.

Please help: condition in the formula

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

  • Please help: condition in the formula

    Hello,
    I have a special formula for buying:
    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Buy 4 GSV");
    setCursorLabelName("Buy 4 GSV");

    setDefaultBarStyle(PS_SOLID);
    setDefaultBarFgColor(Color.blue);
    setDefaultBarThickness(2);
    setPlotType(PLOTTYPE_FLATLINES);
    }

    function main() {

    return open(0) + (((high(-4) - open(-4) + high(-3) - open(-3) + high(-2) - open(-2) + high(-1) - open(-1)) / 4 ) * 1.8);

    }

    This formula should be fulfiled only when close<open. For example, high(-4) - open(-4) if close < open.
    How can I put the condition into my formula?
    I am waiting for your help.
    Thanks,
    Tonal
    Tonal

  • #2
    Hello,

    try this...

    if it's not giving the results you want, please repost your next question or screenshot

    kz
    PHP Code:
    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Buy 4 GSV");

    //setCursorLabelName("Buy 4 GSV");
    //setDefaultBarStyle(PS_SOLID);
    //setDefaultBarFgColor(Color.blue);
    //setDefaultBarThickness(2);
    //setPlotType(PLOTTYPE_FLATLINES);    

    // added "0" assignments

        
    setCursorLabelName("Buy 4 GSV "0);
        
    setDefaultBarStyle(PS_SOLID0);
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarThickness(20);
        
    setPlotType(PLOTTYPE_FLATLINES0);
        
    }

    function 
    main() {


    var 
    myStudy open(0) + (((high(-4) - open(-4) + high(-3) - open(-3) + high(-2) - open(-2) + high(-1) - open(-1)) / ) * 1.8);


    return 
    myStudy//open(0) + (((high(-4) - open(-4) + high(-3) - open(-3) + high(-2) - open(-2) + high(-1) - open(-1)) / 4 ) * 1.8);


    Comment


    • #3
      conditions in the formula

      Hello
      In my formula high(-1) - open(-1) means that it takes the previous day(-1). But if the condition on this day(close < open) is not true than the day should be ignored. Than a day before will be the day(-1), if the condition(close < open) is true.
      How can I put this condition into my formula?

      Thanks,
      Tonal.
      Tonal

      Comment


      • #4
        Tonal,

        sorry I misunderstood.

        Also, need to understand this - your first post:
        This formula should be fulfiled only when close<open.
        your second post:
        But if the condition on this day(close < open) is not true than the day should be ignored.
        Are you wanting a flatline? or a moving average line?

        And are you only wanting to consider 4 days of the condition for the average?

        kz

        Comment


        • #5
          Hello,
          Yes, I want a flatline. You see, Larry Williams in his book "Long-Term Secrets of Short-Term Trading" said(Chapter 8, GSV) : if you were to add up the swings from the open to the daily highs (on down close days), you would arrive at the swing values the market could rally without setting off a wave of buying resulting in an up close.
          In my formula I mean that the condition should be fulfiled 4 times, and it's not important 4 days or 10 days before.
          Tonal.
          Tonal

          Comment


          • #6
            Hello Alex,
            Could you help me with my formula, please? I can't put the condition into the formula.
            Thank you,
            Tonal.
            Tonal

            Comment


            • #7
              Sorry this was meant for JasonK.
              I have a special formula for buying(my first post). It works, but I want to put the condition into the formula.
              You see, Larry Williams in his book "Long-Term Secrets of Short-Term Trading" said(Chapter 8, GSV) : if you were to add up the swings from the open to the daily highs (on down close days), you would arrive at the swing values the market could rally without setting off a wave of buying resulting in an up close.
              In my formula I mean that the condition should be fulfiled 4 times, and it's not important 4 days or 10 days before.
              Could you help me with my formula, please? I can't put this condition into the formula. It's very important.
              Thank you,
              Tonal.


              __________________
              Tonal

              Comment


              • #8
                Tonal
                To accomplish what you want you will need to use an array in which you store the values of High-Open when the condition Close<Open is met. For the description of the Array Object and its methods see this article in the EFS KnowledgeBase.
                The first thing you need to do is to declare the array as a global variable ie outside of the preMain() or main() functions and set its length (in this case this will be 4 as you want to store the last four values)



                Then inside main you set an initial condition that checks for a new bar using the getBarState() function. Inside that condition you set your condition to evaluate if the prior close Close is less than the prior Open and if that condition is true you update the array using the pop() and unshift() methods of the Array Object to remove the last element of the array and to add the prior H-O range as the first element of the array.



                Once you have done that you can use the elements of the array ie myArray[0], myArray[1], myArray[2] and myArray[3] in place of each high(-1)-open(-1), high(-2)-open(-2), etc that is contained in your equation
                If you are not familiar with programming in EFS and are interested in learning then I would suggest that you begin by reviewing the JavaScript for EFS video series and the Core JavaScript Reference Guide. Those will provide you with a thorough introduction to programming in JavaScript which is at the foundation of EFS. Then go through the EFS KnowledgeBase and study the Help Guides and Tutorials which will provide you with the specifics of EFS.
                If instead you are just looking for someone to write the script(s) for you then you may want to review the FAQ: How can I get my custom study built?
                Alex



                Originally posted by Tonal
                Hello,
                I have a special formula for buying:
                function preMain() {
                setPriceStudy(true);
                setStudyTitle("Buy 4 GSV");
                setCursorLabelName("Buy 4 GSV");

                setDefaultBarStyle(PS_SOLID);
                setDefaultBarFgColor(Color.blue);
                setDefaultBarThickness(2);
                setPlotType(PLOTTYPE_FLATLINES);
                }

                function main() {

                return open(0) + (((high(-4) - open(-4) + high(-3) - open(-3) + high(-2) - open(-2) + high(-1) - open(-1)) / 4 ) * 1.8);

                }

                This formula should be fulfiled only when close<open. For example, high(-4) - open(-4) if close < open.
                How can I put the condition into my formula?
                I am waiting for your help.
                Thanks,
                Tonal

                Comment


                • #9
                  Thank you very much Alex. Your advice was a great help.

                  Tonal.
                  Tonal

                  Comment


                  • #10
                    Tonal
                    You are most welcome
                    Alex

                    Originally posted by Tonal
                    Thank you very much Alex. Your advice was a great help.

                    Tonal.

                    Comment

                    Working...
                    X