Announcement

Collapse
No announcement yet.

Minimized charts don't update

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

  • #16
    Steve, Tony
    Given that the conditions are evaluated inside a BARSTATE_NEWBAR statement and that they reference the values of the indicators at the prior bar the more logical fill type constant to use is Strategy.MARKET [rather than Strategy.CLOSE] as it simulates the first tick after the conditions evaluate to true.
    Alex

    Comment


    • #17
      Alexis,

      Great minds must think alike because I was just going to post that same remark about using the open price versus the close.

      It should also be more profitable.

      I've updated the efs and made a couple of bug fixes and cosmetic updates to the prior one. It now displays a blue "C" when you close a long or cover a short position.

      Steve
      Attached Files

      Comment


      • #18
        ADX/MAcross

        Alex and Steve,

        Why do I get the feeling that it takes you guys a few minutes to do what it is going to take me six months to do. I only hope that one day I will understand the codes as well as you guys do.

        I had to work late and did not get a chance to study and look up exactly what all the changes were but I really do like the blue "c" when an alert to cover is triggered...very nice touch.

        It does work great now but I'm trying to write in another "if" condition.

        Can I add yet another "if" ....the ADX (-1)>=25 and ADX (-2)<25and MA1 >= MA2...re-enter long. This is, of course after the positions were covered due to the ADX dropping below 25. And of course have the same condition for the short side as well.

        My question is this....does it matter how many "ifs" or "elses" I have as long as the logic works?

        You guys are great and thanks once again for all the help. I love this stuff...don't you!

        Thanks,
        Tony

        Comment


        • #19
          Tony,

          You can have as many if statements as you want. The if statement you describe isn't needed though. Your current if statements will trigger if ADX is over 25 and there's a cross. The ADX < 25 is a "don't care" condition. The if statement will run if ADX(-2) <25 or ADX(-2)>25.

          I would guess it took about 20 minutes for the changes I made to your code. It does get easier with practice, and it doesn't hurt to have 18+ years of programming experience either

          Another thing I've done on my strategies is paint the background red/green when in a short/long position. You can insert the following code before your return statement in main to get that feature.
          PHP Code:
                  // Paint Bar Background to indicate long or short position on chart
              
          if(vTradeState == LONG
                  
          setBarBgColor(Color.RGB(178243171)); // light green background
              
          if(vTradeState == SHORT
                  
          setBarBgColor(Color.RGB(246168188)); // light red background 
          Steve

          Comment


          • #20
            Tony

            Can I add yet another "if" ....the ADX (-1)>=25 and ADX (-2)<25and MA1 >= MA2...re-enter long. This is, of course after the positions were covered due to the ADX dropping below 25. And of course have the same condition for the short side as well.
            Although you can add another condition to do that [and it does not matter how many if statements you have] an easier way to accomplish what you want is to modify your current entry conditions (lines 127-130 and 147-150) by removing or commenting out the line that checks the status of the averages two bars back (as an example of this see the enclosed image)



            Apply the same logic to the condition for the short entry.
            This way the system will enter [and re-enter] a trade in the direction of the vMA1 average once the ADX rises above 25 in other words without the need for the averages to cross over

            I only hope that one day I will understand the codes as well as you guys do.
            If you are interested in learning how to program in efs then the best way to do that is 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.
            Alex

            Comment


            • #21
              MAx/ADX

              Steve and Alex,

              Once again thank you for your input. It has been very helpful in helping me understand how to write the code. Now if I could get past this basic MA formula I would feel alot better about my programming skills...what little I have.

              I wasn't happy with the results that I have been getting with the basic MA crossover. Even with the ADX as a filter I still get tons of false signals and the sell/cover signals I get usually come after the MA's cross back over and usually at a loss.

              What I decided might make a more profitable program would be to leave the ADX in but add a sell/cover condition when the price crosses the MA1 line whenever in a trade and then if the price crosses back above or below (long side or short side) get a signal to reenter the trade.

              I thought this would be simple enough and I would take Steves' ADX condition and just write in for the close()<vMA1 or close()>vMA2.

              You can see what I did on lines 66-203. I get a Syntax error...

              line 170: SyntaxError: syntax error:
              if(vTradeState ==Long))

              What am I doing wrong?

              Thanks again guys!!!
              Attached Files

              Comment


              • #22
                ADX/MA cross

                I think I have it...

                I have to declare a global variable for the close like...

                var vClose = nul;

                Then i will have to use the getValue("close"-1) to get my closing price...is this correct?

                Comment


                • #23
                  tonman1,

                  Your syntax error problem was due to your if statement braces not matching up properly. I've changed them to how I think they should be, but you'll have to verify it's what you intended.

                  For close, you can just use close(0), close(-1), etc to get values for close. The open, high, low, and close series objects let you access them without using the getValue() method.

                  So you could have
                  var myCloseNow = close(0);

                  This will assign the value of the current bar's close to myCloseNow. Use close(-1) to get the prior bar's close.

                  Steve
                  Attached Files

                  Comment


                  • #24
                    MA cross

                    I've made some adjustments to the original strategy and taken from Steves' code on his re-write of the MA/ADX formula. I took out the ADX filter and just put in a sell/cover when the price crosses the MA1 line.

                    Now I'm getting a syntax error that states I have invalid return.

                    Can anyone help me with this?

                    Thanks....
                    Attached Files

                    Comment


                    • #25
                      tonman,

                      For some reason you have deleted the start of line 100. It should start with

                      function main(MA1Length, etc...

                      The error was due to JavaScript seeing a return, but it knew you weren't in a function block.

                      Steve

                      Comment


                      • #26
                        MA cross

                        Thanks Steve....

                        I must have blanked it out when cut and pasted. Thanks ...I will give it a try when I get a chance.

                        Comment

                        Working...
                        X