Announcement

Collapse
No announcement yet.

MACD formula help!!!

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

  • MACD formula help!!!

    i am a new user and i used the formula wizard for the first time in order to make a test with macd.
    the formula works but i realized that it misses some signals!!
    i will give you the formula here and please tell me what is wrong with it:

    //{{EFSWizard_Description
    //
    // This formula was generated by the Alert Wizard
    //
    //}}EFSWizard_Description 7532


    //{{EFSWizard_Declarations

    var vMACD12_26 = new MACDStudy(12, 26, 9, "Close", false);
    var vLastAlert = -1;

    //}}EFSWizard_Declarations 9531


    function preMain() {
    /**
    * This function is called only once, before any of the bars are loaded.
    * Place any study or EFS configuration commands here.
    */
    //{{EFSWizard_PreMain
    setPriceStudy(true);
    setStudyTitle("MACD");
    //}}EFSWizard_PreMain 5989

    }

    function main() {
    /**
    * The main() function is called once per bar on all previous bars, once per
    * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
    * in your preMain(), it is also called on every tick.
    */

    //{{EFSWizard_Expressions
    //{{EFSWizard_Expression_1
    if (
    vMACD12_26.getValue(MACDStudy.SIGNAL) > vMACD12_26.getValue(MACDStudy.MACD)
    ) onAction1()
    //}}EFSWizard_Expression_1 12826

    //{{EFSWizard_Expression_2
    else if (
    vMACD12_26.getValue(MACDStudy.SIGNAL, 0, 0) > vMACD12_26.getValue(MACDStudy.MACD)
    ) onAction2();
    //}}EFSWizard_Expression_2 16066

    //}}EFSWizard_Expressions 49890


    //{{EFSWizard_Return
    return null;
    //}}EFSWizard_Return 2256

    }

    function postMain() {
    /**
    * The postMain() function is called only once, when the EFS is no longer used for
    * the current symbol (ie, symbol change, chart closing, or application shutdown).
    */
    }

    //{{EFSWizard_Actions
    //{{EFSWizard_Action_1
    function onAction1() {
    if (vLastAlert != 1) drawShapeRelative(1, high(1), Shape.DOWNARROW, "", Color.RGB(128,0,37), Shape.BOTTOM);
    if (vLastAlert != 1) setBarBgColor(Color.RGB(255,255,160));
    vLastAlert = 1;
    }
    //}}EFSWizard_Action_1 27875

    //{{EFSWizard_Action_2
    function onAction2() {
    if (vLastAlert != 2) drawShapeRelative(1, low(1), Shape.UPARROW, "", Color.RGB(0,128,18), Shape.TOP);
    if (vLastAlert != 2) setBarBgColor(Color.RGB(233,255,255));
    vLastAlert = 2;
    }
    //}}EFSWizard_Action_2 27587

    //}}EFSWizard_Actions 72540

    it works fine on the 5' chart but it misses trades on the 3' chart!
    i am going crazy! why is that?

  • #2
    takis
    Try the attached revision and see if it makes a difference.
    Alex
    Attached Files

    Comment


    • #3
      Alex,
      you are great!
      it repaired the thing!
      how come?
      what was the mistake?

      Comment


      • #4
        takis
        Look at the conditions in Set2
        Alex

        Comment


        • #5
          alexis this is really great!
          i see the difference in the two codes.
          now, i will post you what my ultimate target is in this formula and you can tell me if you can help me on that.

          what i am doing is applying it both on 3' and 5' chart.
          now the signal for the order should be triggered only when on both charts we have the same condition.
          (i.e. when the 3' macd crosses upwards we take a long only if the 5'macd is in the same area (has crossed up before), otherwise we dont take the trade and we wait either the 5' to turn upwards or the 3' to go downwards in which case we take a short as the 5' is allready downwards.
          now, we get the trade at the OPEN of the next bar and we put a profit target of 3 points from that price (talking about dax contracts)

          we cover only if the macd crosses opposite in one of the 3' or 5' charts.

          thats the whole system and i have tested it (paper and pen) for a month.
          now i need to test it for bigger period but i need assisanse to put it in the formula.

          and what you do is take the FIRST trade of the day (18 out of 20 days gives you +5 points )and stop trading when you get 3 consecutive trades correct

          i would be grateful if you could help me on that!!!

          Comment


          • #6
            takis
            At this time one of the most difficult things to do with the current version of efs is synchronizing multiple time frames. FWIW eSignal has indicated that the next iteration of the language will make this a very easy task, but for now out of the various solutions available, none can be achieved using the Formula Wizard.
            Anyhow, here is one possible solution, in which I implement parts of code written by Brad Matheny, that uses two efs running on two charts of different intervals.

            The first efs (fileIO-MACD-1.efs attached to this message) plots a standard MACD and paints the background of the indicator in lime/yellow depending on whether the MACD is above/below the Signal. At the same time it writes these conditions to an external file.
            You would run this efs on the 5 minute chart.



            The second efs (fileIO-MACD-2.efs attached to the next message) is loaded on a second chart with a different interval (in your case the 3 minute chart). Also this efs computes/plots a MACD but at the same time it reads the file containing the signals generated by the first efs. It then determines when both MACDs are above/below their respective Signal lines and implements a basic Long/Short (and corresponding Sell/Cover) trading strategy based on the combined signals. Lastly when Long it paints the price bars in blue and when Short in red



            As to the remainder of the strategy ie setting profit targets, counting trades, etc someone else will have to help as that is beyond me.
            However before implementing this rather complex solution, I would suggest looking at a possible alternative which is not "technically" as correct as this one but is far easier to work with and IMHO an acceptable approximation. Explanation follows in a separate message.
            Alex
            Attached Files

            Comment


            • #7
              takis
              Attached is the second efs needed for the strategy. This efs computes only on the close of the bar so as not to trigger any action on intrabar signals.
              Alex

              Note: This efs will not work without fileio-macd-1.efs running on another chart
              Attached Files

              Comment


              • #8
                takis
                As I suggested in my earlier post there is an alternative that you may find is an acceptable solution.
                The alternative is to create two MACDs in the same efs with the second one having its settings multiplied by the ratio of the two intervals. This ratio is 1.66 which means that the values for the second MACD would be 20,43,15
                The attached efs computes/plots both MACDs and sets the conditions for Long/Short based on both MACDs being above/below their corresponding Signal lines. It then paints the bars in blue when Long and in red when Short.
                Compare it to the other one to see if there is any merit to considering this solution. FYI this efs was done using only the Formula Wizard which can be used to view/edit the script.
                Alex

                Attached Files

                Comment


                • #9
                  dear Alexis,
                  thanks for your consern!
                  i will check them all out and tell you what i find of them and if there are any trouble.
                  yesterday i tried the macd(2) formula that you sent me and it looks great for the time being.
                  the only thing that bothers me is that the signals do not show up in real time as they happen but i have to apply the formula again to see the signal plotted past that point

                  Comment


                  • #10
                    takis
                    I have slightly modified the logic in macd(2).efs and it should now work in real time also.
                    Alex
                    Attached Files

                    Comment


                    • #11
                      i tried it but the signals differ from macd2 !

                      Comment


                      • #12
                        takis (and anyone that downloaded fileio-macd-2.efs attached to an earlier message)
                        I have revised the efs so that it will now paint the bars also while running in real time. Note however that the efs still computes at the close of the bar only.
                        Alex

                        NOTE: This efs also needs fileio-macd-1.efs which is available here together with an explanation.
                        Attached Files

                        Comment


                        • #13
                          takis
                          Download it again from the same link. I replaced the prior file that had different settings I was using to test it in real time.
                          Alex

                          Comment


                          • #14
                            the problem is fixed regarding the signals on macd(2b) now i am checking if it works real time.
                            later on i will get involved with the other combined formulas and i will let you know.
                            Thanks for all the help ANYWAY!

                            Comment


                            • #15
                              alexis,
                              the macd(2b) works great in real time!
                              thanks.
                              now i am trying to go over lightly the 2xmacd on backtesting.
                              the first results are mixed as it seems that it has some incorrect trades in between the many correct ones and also the coloring is a bit sloppy, not exact in all trades.
                              i will give you more details later though.

                              also, a small problem i have is setting the time templates for the test (i.e. what do i choose in order to test the strategy in a specific period of time? lets say from beggining of dax trading hours till the close of that specific day?)

                              where can i get some more info regarding the time templates set up?

                              Comment

                              Working...
                              X