Announcement

Collapse
No announcement yet.

EFS MACD, Stoch, and DMA cross on same day

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

  • EFS MACD, Stoch, and DMA cross on same day

    I was wondering if anyone could help me with an EFS that shows when i have a MACD, Stochastic, and 3DMA cross up. I already have the if statements in but I'm looking for signal to only happen when all 3 cross on the same day. I need an If MACD cross up && Stoch cross up && 3DMA cross up and then an If all the crosses are on the same day then give the buy signal. I used the formula wizard and came up with this code but it gives a buy signal everytime all three indicators are up instead of just when the indicators cross.

    Thanks,
    Coheirs
    Attached Files

  • #2
    Hello Coheirs,

    When creating a formula to look for a cross of two indicator lines, you need to take into consideration the values for the two indicators lines on consecutive bars. For each of the crosses you are looking for, you will have two conditions for each. Condition 1 will look at the values on bar -2 to see if line 1 is < line 2. Condition 2 will look at bar -1 to see if line 1 > line 2. This would confirm a cross up, or long signal. Do the opposite for the short signals.

    By always looking at bar -2 and -1 you will assure yourself of a confirmed cross and avoid false signals that can occur when only looking at bar -1 and 0. Since the value of the 0 bar can cause the cross condition to be true for a period of time intra-bar but not close at a level where the cross remains true after the bar closes.

    To generate a signal only when all three studies has a confirmed cross you will add the two conditions for each study to the same set in the Formula Wizard. So on Set 1 you will have a total of 6 conditions. This would handle the long signals. With Set 2 you would do just the opposite to handle the short signals.



    Aside from how to code this, I think your conditions may be too restrictive. I ran this on a couple symbols and didn't see any signals where all three crosses where confirmed on the same bar.
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Multiple Indicator Signals..

      Jason is correct.. Sometimes, when you are using multiple indicators (short-term~longer-term) - they don't always cross on the same bar. One solution to this problem is to use conditionals for the longer-term indicators - thus setting up a "BIAS Variable" for these indicators. Then using a "Trigger Mechanism" for your final conditions...

      For example....

      for your MACD, you might set a condition like...

      var MACDBIAS = 0;
      if (MACD_Value1 > MACD_Value2) {
      MACDBIAS = 1;
      } else {
      MACDBIAS = -1;
      }

      and for your DMA, you might set a condition like...

      var DMABIAS = 0;
      if (DMA_Value1 > DMA_Value2) {
      DMABIAS = 1;
      } else {
      DMABIAS = -1;
      }

      Now, your longer term indicators are setup as "Conditionals", thus you can now test for the triggers...

      if ( (MACDBIAS == 1) && (DMABIAS == 1) && (STO_Value1 > STO_Value2) && (!AlreadyLong) ) {
      .. trigger a buy signal
      }

      if ( (MACDBIAS == -1) && (DMABIAS == -1) && (STO_Value1 < STO_Value2) && (!AlreadyShort) ) {
      .. trigger a sell signal
      }

      You could also adjust this example to track the "crossing points" of the indicators. Then, you could allow triggers to ONLY "go off" within n bars of crossing (for all indicators). For example, you could set your EFS up to only allow triggers if all three indicators crossed within 5 bars of eachother.

      Hope this helps..

      B
      Brad Matheny
      eSignal Solution Provider since 2000

      Comment


      • #4
        How to get withing n bars

        THanks you for your help.
        It helped a lot my question now is how do i set the condition for the cross to take place within n bars.
        Thanks for your help.

        Comment


        • #5
          here you go...

          This code example uses a couple of new things - so study it a bit before you try it out...

          This (rough outline) should do what you want. The "BarstoAllowCross" variable controls how many bars you will allow all three to triggered.

          Hope this helps.

          B

          PHP Code:

          var BarstoAllowCross 5;

          // System variables - do not touch!!
          var vMACD null;
          var 
          vADX null 


          var nLastRawTime 0;
          var 
          BLBarOffset 0;

          var 
          vHour;
          var 
          vMin;
          var 
          vSec;
          var 
          vDay;
          var 
          vMonth;
          var 
          vYear;
          var 
          vTime = new Date();

          var 
          MACDBIAS 0;
          var 
          MACDBIASBar  null;
          var 
          DMABIAS 0;
          var 
          DMABIASBar null;



          function 
          preMain() {
              
          setPriceStudy(true);
              
          setStudyTitle("IndicatorCrossonBars");
              
          setComputeOnClose();
          }


          function 
          main() {

          if (
          vMACD == nullvMACD = new MACDStudy(12269Source"Close"false);
          if (
          vADX == nullvADX = new ADXDMStudy(1414);


          // BLM Added....
          //---------------------------------------------------
          //  Get Time Variables
            
          vTime getValue("Time"0);
            
          vHour vTime.getHours();
            
          vMin vTime.getMinutes();
            
          vSec vTime.getSeconds();
            
          vDay vTime.getDate();
            
          vMonth vTime.getMonth() +1;
            
          vYear vTime.getYear();
          //---------------------------------------------------

          //  Bar Counter
          if (nLastRawTime != getValue("rawtime"0)) {
               
          BLBarOffset += 1;
               
          nLastRawTime getValue("rawtime"0);
          }



          if ((
          vMACD.getValue(MACDStudy.MACD) > vMACD.getValue(MACDStudy.SIGNAL)) && (vMACD.getValue(MACDStudy.MACD,-1) < vMACD.getValue(MACDStudy.SIGNAL,-1))) {
            
          MACDBIAS 1;
            
          MACDBIASBar BLBarOffset;

          if ((
          vMACD.getValue(MACDStudy.MACD) < vMACD.getValue(MACDStudy.SIGNAL)) && (vMACD.getValue(MACDStudy.MACD,-1) > vMACD.getValue(MACDStudy.SIGNAL,-1))) {
            
          MACDBIAS = -1;
            
          MACDBIASBar BLBarOffset;
          }



          if ((
          vADX.getValue(ADXDMStudy.NDI) > vADX.getValue(ADXDMStudy.ADX)) && (vADX.getValue(ADXDMStudy.NDI,-1) < vADX.getValue(ADXDMStudy.ADX,-1))) {
            
          DMABIAS 1;
            
          DMABIASBar BLBarOffset;
          }
          if ((
          vADX.getValue(ADXDMStudy.PDI) > vADX.getValue(ADXDMStudy.ADX)) && (vADX.getValue(ADXDMStudy.PDI,-1) < vADX.getValue(ADXDMStudy.ADX,-1))) {
            
          DMABIAS = -1;
            
          DMABIASBar BLBarOffset;
          }


          if ( ((
          MACDBIAS == 1) && ((BLBarOffset-MACDBIASBar) <=  BarstoAllowCross)) && 
          ((
          DMABIAS == 1)  && ((BLBarOffset-DMABIASBar ) <=  BarstoAllowCross) ) && 
          (
          STO_Value1 STO_Value2) && (!AlreadyLong) ) {
            .. 
          trigger a buy signal
          }

          if ( ((
          MACDBIAS == -1) && ((BLBarOffset-MACDBIASBar) <=  BarstoAllowCross)) && 
          ((
          DMABIAS == -1)  && ((BLBarOffset-DMABIASBar ) <=  BarstoAllowCross) ) && 
           (
          STO_Value1 STO_Value2) && (!AlreadyShort) ) {
            .. 
          trigger a sell signal
          }


          return;

          Brad Matheny
          eSignal Solution Provider since 2000

          Comment

          Working...
          X