Announcement

Collapse
No announcement yet.

Moving average crossover - Part 1

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Moving average crossover - Part 1

    Attached is a formula for a moving average crossover. The only adjustments I made in the formula are: 1. Changed the B and S to Buy and Sell boxes 2. changed the sound files 3. changed the MA1 & MA2 lengths. The problem that I am having is that the alert ... Buy & Sell boxes and associated sounds are not happening on all crossovers. Could someone please look at the formula and see what's wrong ? Did one of the E-Signal updates throw something out of whack ?? Thank you for any help.
    Paul W.

    P.S. I will attached my chart in a new thread called "Moving average crossover - Part 2" to show where the signals are not firing and you can try it out on your end.
    Attached Files

  • #2
    Moving average crossover - Part 2

    This is for Alex Montenegro... Alex here is the attached chart. Look at the following times:
    11:46/11:47 moving average crossed-no sell box nor sound
    12:02 moving average crossed-we get a buy box and a sound
    12:33 moving average crossed-no sell box nor sound
    12:43 moving average crossed-no buy box nor sound
    12:47 moving average crossed-we get a sell box and a sound.

    I think you get the point from here Alex ... seeing is believing. Thanx again, Alex for your help
    Attached Files

    Comment


    • #3
      Paul
      In line 102 replace < with <= and in line 111 replace > with >=
      That should fix the problem
      Alex

      Comment


      • #4
        Moving average crossover fix

        Alex: What can I say ? It worked. As they say in the sports world .... " YOUR THE MAN". Thanx again for all your continued support and help.
        Paul W.

        Comment


        • #5
          Alex, could you please help me in adding a Pop Up Alert to go along with this indicator?

          I have 6 charts up and when the audio triggers, it's not clear what chart it's referring to.

          Thank you!
          Greg

          Comment


          • #6
            Greg
            After line 108 insert the following command
            Alert.addToList(getSymbol()+" "+getInterval(), "Crossing Up", Color.black, Color.blue)
            Repeat the same after line 117 substituting "Crossing Up" with "Crossing Down" and Color.blue with Color.red
            These commands will trigger also a popup alert containing the symbol/interval of the chart that triggered it.
            Alex

            Comment


            • #7
              Thank you Alex, it seems to work great now!

              I have one other problem though - the 5 day MA is not updating in real time on charts...it stops drawing at the point in which the chart was loaded. Only the green 8 MA keeps updating with each new candle that is drawn. Also, it seems as though the trigger is not funcition properly then as a result??

              Can you help me in resolving this please?

              Thanks again!
              Attached Files
              Last edited by bugscoe; 05-24-2005, 10:27 AM.

              Comment


              • #8
                A follow up Alex - the problem occurs when I change the offset value of the 5 MA to -1. In doing so, the MA stops drawing???

                Thanks!

                Comment


                • #9
                  bugscoe
                  Try running a search for negative offset (or similar keywords) and you should find several threads on this subject explaining why this happens and how the efs needs to be written to have the plots update.
                  If you do not find anything try running a serach also for setbar* which is the function required to update plots of indicators with a negative offset
                  Alex

                  Comment


                  • #10
                    Alex, is the attached file the proper code? It seems to work on it's own...

                    However, I need help in putting this code into my efs. I don't know where to paste it and what exactly to paste??

                    Thank you!
                    Greg
                    Attached Files

                    Comment


                    • #11
                      Greg
                      The example you posted only computes one moving average. See the efs attached to this post that computes two moving averages one of which has a negative offset and determines the crossover points
                      Alex

                      Comment


                      • #12
                        Hi Alex, I really would like your help in putting this formula together! If you know what code I need to add to my formula to correct the offest issue, I would greatly appreciate it if you could correct if for me...please! Or at the very least, tell me what code needs to go in what lines, etc. in my formula, like you did for me on the trigger alert window.

                        Whether I find the right code or not, I still have no idea what I'm looking at and what I'm suppose to copy and paste into my formula. I looked at the efs file you attached but am clueless as to what to do with it.

                        I know very little to nothing about writing efs files so it's all very foreign to me! I hope you understand?

                        Thank you!
                        Greg
                        Attached Files

                        Comment


                        • #13
                          Greg
                          Not sure as to what you are trying to accomplish.
                          Anyhow if your objective is to signal when two averages - one of which has a -1 offset - are crossing then you can obtain the same exact results in a much simpler way by resetting the -1 offset to 0 and offsetting the other average forward by 1.
                          While you may have the impression that the signals are one bar behind you need to consider that when using a negative offset you also need to apply it to the conditions that generate the signals. These would need to be changed to the following for your efs to work correctly in real time

                          PHP Code:
                          if(vMA1.getValue(MAStudy.MA,-3)<=vMA2.getValue(MAStudy.MA,-3)&&
                                     
                          vMA1.getValue(MAStudy.MA,-2)>vMA2.getValue(MAStudy.MA,-2)&&. 
                          and

                          PHP Code:
                          if(vMA1.getValue(MAStudy.MA,-3)>=vMA2.getValue(MAStudy.MA,-3)&&
                                     
                          vMA1.getValue(MAStudy.MA,-2)<vMA2.getValue(MAStudy.MA,-2)&& 
                          Once you do this you will see that the signals are going to be triggered differently. As is the formula indicates the Buy/Sell alerts one bar earlier on historical data because it is foward looking.
                          If you apply my suggestion you also no longer need to worry about plotting the average with a negative offset.
                          Alex

                          Comment


                          • #14
                            Hi Alex and thanks for the reply!!

                            I tried your code and it's working fine but I would really prefer to have the 5 MA offset by -1 and the 8 MA at 0 and achieve the same results that your code offered up.

                            Although doing what you suggested is working, it's just working a little "later" than I'd like/need it to. The MA crossover and triggers are occuring about 1-2 candles later in time on my 15min chart with your code below.

                            This is the reason I wanted the 5 MA offest by -1, so that I could achieve an earlier crossover and trigger/alert.

                            So, if we could take the formula I attached, make the 5 MA offset by -1 and have it plot correctly AND also get the triggers to line up with the -1 offset, I'd have the perfect formula!!

                            You mentioned that this code you offered was the 'easier' way...is doing what I'm asking much more complex, or is it possible to do?

                            Thank you!
                            Greg
                            Attached Files

                            Comment


                            • #15
                              Greg
                              First of all please note that the modified conditions I provided in my prior reply are required only if you are applying a negative offset to the 5 MA.
                              If instead you implement my suggestion you should leave the conditions as they are in the script you posted.

                              This is the reason I wanted the 5 MA offest by -1, so that I could achieve an earlier crossover and trigger/alert

                              As I said in my prior reply that is not what will happen in real time if the conditions are programmed correctly. It only appears to do so at this time because the efs is currently set up to "look" into the future. If you run a search for negative offset in these forums you will find several examples of what I am saying as this is a subject that has been covered many times.
                              If however you would still like to use a negative offset then I would suggest using the example I provided as a guideline for what is required. If you are not comfortable implementing that solution yourself then I would suggest contacting an EFS Consultant
                              Alex

                              Comment

                              Working...
                              X