Announcement

Collapse
No announcement yet.

Please help (ADX indicator)

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

  • Please help (ADX indicator)

    Hi all!

    I re-wrote the ADX indicator that shows the value of the ADX in the frame on the chart, but sometimes it shows an ADX value that is correct, but sometimes it's wrong.

    Could anyone point out where I am making a mistake?

    I would appreciate any tips...
    Thanks in advance!

    Examples Charts

    Wrong



    Correct



    PHP Code:
    /*********************************************************
    Alexis C. Montenegro © July 2003                          
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a 
    description of any changes you make.                      
    **********************************************************/

    var vADX null;
    var 
    ADX14;

    function 
    preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("ADX^14");
        
    setDefaultBarFgColor(Color.RGB(2550255), 0); //adx color
        
    setDefaultBarFgColor(Color.blue1); //+DI color
        
    setDefaultBarFgColor(Color.red2); //-DI color
        
    setDefaultBarThickness(2,0); //ADX Line thickness
        
    setDefaultBarThickness(1,1); //+DI Line thickness
        
    setDefaultBarThickness(1,2); //-DI Line thickness
        
    setShowTitleParameters(false);
        
    setShowCursorLabel(false);
        
        var 
    fp1 = new FunctionParameter("DILength"FunctionParameter.NUMBER);
        
    fp1.setLowerLimit(1);        
        
    fp1.setDefault(14); //Edit this value to set a new default
        
        
    var fp2 = new FunctionParameter("ADXLength"FunctionParameter.NUMBER);
        
    fp2.setLowerLimit(1);        
        
    fp2.setDefault(14); //Edit this value to set a new default
            
    }

    function 
    main(DILengthADXLength) {
        
        if (
    vADX == nullvADX = new ADXDMStudy(DILengthADXLength);
        
    vADX14 vADX.getValue(ADXDMStudy.ADX);
        
        if(
    vADX14 == null)
        return;
    /******************************************************************
    Insert your code following this text block                         
    Use vADX.getValue(ADXDMStudy.ADX) and vADX.getValue(ADXDMStudy.PDI)
    and vADX.getValue(ADXDMStudy.NDI) for your code                    
    *******************************************************************/    
        
        /*//Display result
        
        drawTextAbsolute( 0, 15, "ADX: " + vADX.getValue(ADXDMStudy.ADX) +"  ", Color.black, Color.lightgrey, 
            Text.BOLD | Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM, "Arial", 10, "ADX" );*/
        
        // Color Coding
        
    if(vADX.getValue(ADXDMStudy.ADX)>25&&vADX.getValue(ADXDMStudy.ADX)<45&&vADX.getValue(ADXDMStudy.PDI)>vADX.getValue(ADXDMStudy.NDI)){
            
    drawTextAbsolute015"ADX: " vADX14.toFixed(2) +"  "Color.whiteColor.blue
            
    Text.BOLD Text.RELATIVETOLEFT Text.RELATIVETOBOTTOM"Arial"10"ADX" );
            
        }
        if(
    vADX.getValue(ADXDMStudy.ADX)>25&&vADX.getValue(ADXDMStudy.ADX)<45&&vADX.getValue(ADXDMStudy.PDI)<vADX.getValue(ADXDMStudy.NDI)){
            
    drawTextAbsolute015"ADX: " vADX14.toFixed(2) +"  "Color.blackColor.magenta
            
    Text.BOLD Text.RELATIVETOLEFT Text.RELATIVETOBOTTOM"Arial"10"ADX" );
            
        }
        if(
    vADX.getValue(ADXDMStudy.ADX)>45&&vADX.getValue(ADXDMStudy.PDI)>vADX.getValue(ADXDMStudy.NDI)){
            
    drawTextAbsolute015"ADX: " vADX14.toFixed(2) +"  "Color.blackColor.red
            
    Text.BOLD Text.RELATIVETOLEFT Text.RELATIVETOBOTTOM"Arial"10"ADX" );
            
        }
        if(
    vADX.getValue(ADXDMStudy.ADX)>45&&vADX.getValue(ADXDMStudy.PDI)<vADX.getValue(ADXDMStudy.NDI)){
            
    drawTextAbsolute015"ADX: " vADX14.toFixed(2) +"  "Color.blackColor.lime
            
    Text.BOLD Text.RELATIVETOLEFT Text.RELATIVETOBOTTOM"Arial"10"ADX" );
            
        }
        if(
    vADX.getValue(ADXDMStudy.ADX)<18){
            
    drawTextAbsolute015"ADX: " vADX14.toFixed(2) +"  "Color.blackColor.yellow
            
    Text.BOLD Text.RELATIVETOLEFT Text.RELATIVETOBOTTOM"Arial"10"ADX" );    
        }
        
        return 
    null;


  • #2
    Nooze
    Actually the efs is working correctly
    Run the modified version I have attached here and you will see that the value that is written to the chart is always the last value of the ADX while any one of the conditions is true. To make this more obvious I am painting the background with the same color you use for the text. Go into Bar Replay mode and scroll back to any last bar with the colored background and you will see that the value of the ADX returned to the price chart will be that of the ADX at that time (see sample image below).
    You need to change your logic so that each condition only defines a color. Then you have one drawTextAbsolute() command outside of any condition in which the color of the background is the variable set by the conditions
    Alex

    Attached Files

    Comment


    • #3
      Alex!

      Thank you very much! I see where I made a mistake...

      All the best,

      Comment

      Working...
      X