Announcement

Collapse
No announcement yet.

ADX in 1 min chart Calulated every 5 min

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

  • ADX in 1 min chart Calulated every 5 min

    I have an efs below. This efs is going to be on 1 min charts, however I want to make this part of efs make it's calculation every five min. Then I want to have other part to calculate once ever on min. Is there way to do this? I'm doing this because this efs takes too much time.

    Thanks

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("ADX Test II");
    setCursorLabelName("ADX Test II");
    setColorPriceBars(true);
    setDefaultPriceBarColor(Color.blue);
    setComputeOnClose();
    }

    function main() {

    Symbol = getSymbol();
    Interval = 5;
    var vSymbol = Symbol+","+Interval;
    hADX = adx(14,14,sym(vSymbol));
    hPDI = pdi(14,14,sym(vSymbol));
    hNDI = ndi(14,14,sym(vSymbol));

    if (
    hPDI > hNDI &&
    hPDI > hADX
    ) {
    setPriceBarColor(Color.lime);
    }
    }[COLOR=darkblue]

  • #2
    Hello buzybill,

    There may be a better solution than what you are asking for. First try the modified example below. This code is using an initialization routine that will occur only once to set up your indicators and assign them to global variables. After they have been established all you should need to do is reference the values of the series with the .getValue() method.

    One of the issues in your original code that may have been causing inefficiency is the fact that you were initializing the series implicitly (i.e. without var). Placing the initialization inside a bInit routine and assigning the series to global variables should help.

    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("ADX Test II");
        
    setCursorLabelName("ADX Test II");
        
    setColorPriceBars(true);
        
    setDefaultPriceBarColor(Color.blue);
        
    setComputeOnClose();
    }

    // initialization flag
    var bInit false;

    // global variables for series objects
    var xADX null;    
    var 
    xPDI null;
    var 
    xNDI null;

    function 
    main() {
        
        if (
    bInit == false) {  // initialization routine occurs only once.
            
    Symbol getSymbol();
            
    Interval 5;
            var 
    vSymbol Symbol+","+Interval;
            
    xADX adx(14,14,sym(vSymbol));
            
    xPDI pdi(14,14,sym(vSymbol));
            
    xNDI ndi(14,14,sym(vSymbol));
            
    bInit true;
        }
        
        var 
    hADX xADX.getValue(0);
        var 
    hPDI xPDI.getValue(0);
        var 
    hNDI xNDI.getValue(0);
        if (
    hADX == null || hPDI == null || hNDI == null) return; // null check
        
        
    if (hPDI hNDI && hPDI hADX) {
            
    setPriceBarColor(Color.lime); 
        }
        
        return;

    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
      Hi Jason,

      If I wanted to use your formula to show a rising ADX what would I need to do?

      I tried the following but I could not get it to work.

      if (hADX > hADX) {
      setPriceBarColor(Color.lime);


      Thanks,
      Dave

      Comment


      • #4
        Hello Dave,

        The condition as you've written it is comparing the hADX variable to itself, which will always evaluate to false. Use the .getValue() method of the Series Object to reference the previous bar's value and compare it to the current bar's value, which is assigned to the hADX variable. Try the following condition.

        PHP Code:
        if (hADX xADX.getValue(-1)) {  // adx is rising
            
        setPriceBarColor(Color.lime);

        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


        • #5
          Hi Jason,

          I tried to turn your efs into a plotted study. I did not get any syntax errors but I can not get it to plot the study lines. Please let me know what I did wrong.

          Thanks,
          Dave


          PHP Code:
          function preMain() {
              
          setPriceStudy(false);
              
          setStudyTitle("ADXRisingColorBar");
              
          setCursorLabelName("ADX"0);
              
          setCursorLabelName("DM+"1);
              
          setCursorLabelName("DM-"2);
              
          setDefaultBarFgColor(Color.magenta0);
              
          setDefaultBarFgColor(Color.green1);
              
          setDefaultBarFgColor(Color.red2);
              
          setDefaultBarThickness(20);
              
          setDefaultBarThickness(11);
              
          setDefaultBarThickness(12);
              
          setPlotType(PLOTTYPE_LINE0);
              
          setPlotType(PLOTTYPE_LINE1);
              
          setPlotType(PLOTTYPE_LINE2);
              
          /*setComputeOnClose();*/
          }

          // initialization flag
          var bInit false;

          // global variables for series objects
          var xADX null;    
          var 
          xPDI null;
          var 
          xNDI null;

          function 
          main() {
              
              if (
          bInit == false) {  // initialization routine occurs only once.
                  
          Symbol getSymbol();
                  
          Interval 1;
                  var 
          vSymbol Symbol+","+Interval;
                  
          xADX adx(10,10,sym(vSymbol));
                  
          xPDI pdi(10,10,sym(vSymbol));
                  
          xNDI ndi(10,10,sym(vSymbol));
                  
          bInit true;
              }
              
              var 
          hADX xADX.getValue(0);
              var 
          hPDI xPDI.getValue(0);
              var 
          hNDI xNDI.getValue(0);
              if (
          hADX == null || hPDI == null || hNDI == null) return; // null check
              
              
          if (hADX xADX.getValue(-1
              && 
          hPDI hNDI) {
              
          setBarFgColor(Color.lime0);
              }
              
              else if (
          hADX xADX.getValue(-1
              && 
          hNDI hPDI) {
              
          setBarFgColor(Color.red0);  
              } 
              
               return new Array(
                  
          hADX.getValue(xADX),
                  
          hPDI.getValue(xPDI),
                  
          hNDI.getValue(xNDI)
              );
             

          Comment


          • #6
            Hello David,

            Try changing your return statement to the following. The .getValue() method is expecting a bar index value rather than a series object variable.

            PHP Code:
                 return new Array(
                    
            xADX.getValue(0),
                    
            xPDI.getValue(0),
                    
            xNDI.getValue(0)
                ); 
            or

            PHP Code:
                 return new Array(
                    
            hADX,
                    
            hPDI,
                    
            hNDI
                
            ); 
            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


            • #7
              Hi Jason,

              Thanks for your help!!!

              The following worked perfectly (as you suggested):

              PHP:

              return new Array(
              hADX,
              hPDI,
              hNDI
              );

              Very Best,
              Dave

              Comment

              Working...
              X