Announcement

Collapse
No announcement yet.

ADX crossover with bands

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

  • ADX crossover with bands

    Ok I'm trying to create an ADX crossover alert alone...meaning that this EFS will not include the either one of the DI lines.

    I'm starting off with trying to include upper and lower bands....but keep getting an error message.

    Here is the code, can someone advise on what part is incorrect or missing?
    It won't let me continue with the code until I fix the error.
    Thanks.

    var vADX = null;

    function preMain() {


    setStudyTitle("ADX");
    setCursorLabelName("ADX", 0);
    setDefaultBarFgColor(Color.magenta,0);
    setPlotType(PLOTTYPE_LINE,0);
    setDefaultBarThickness(2,0);
    setStudyMin(0);
    setStudyMax(100);

    var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
    fp1.setLowerLimit(1);
    fp1.setDefault(14); //Edit this value to set a new default

    var fp2 = new FunctionParameter("Upper", FunctionParameter.NUMBER);
    fp2.setLowerLimit(0);
    fp2.setDefault(50); //Edit this value to set a new default

    var fp3 = new FunctionParameter("Lower", FunctionParameter.NUMBER);
    fp3.setLowerLimit(0);
    fp3.setDefault(20); //Edit this value to set a new default
    }

    function main(Length, Upper, Lower) {

    if (vADX == null) vADX = new ADXStudy(Length);
    addBand(Upper,PS_SOLID,1,Color.black,1);
    addBand(Lower,PS_SOLID,1,Color.black,2);


    return vADX.getValue(ADXStudy.ADX);

    }

  • #2
    Actually here is the whole thing.
    What I basically did is copy the RSI alert code that someone posted, and used the "Replace" command to replace "RSI" with "ADX"
    Yet the error message keeps referencing the addband function.
    Can anyone help?

    var vADX = null;

    function preMain() {
    setStudyTitle("ADX");
    setCursorLabelName("ADX", 0);
    setDefaultBarFgColor(Color.blue, 0);
    setStudyMin(0);
    setStudyMax(100);
    //checkVeADXon(2,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/basicADX.efs"); //Comment this line out if modifying the code

    var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
    fp1.setLowerLimit(1);
    fp1.setDefault(14); //Edit this value to set a new default

    var fp2 = new FunctionParameter("Source", FunctionParameter.STRING);
    fp2.setName("ADXSource");

    fp2.setDefault("Close"); //Edit this value to set a new default

    var fp3 = new FunctionParameter("Upper", FunctionParameter.NUMBER);
    fp3.setLowerLimit(0);
    fp3.setDefault(50); //Edit this value to set a new default

    var fp4 = new FunctionParameter("Lower", FunctionParameter.NUMBER);
    fp4.setLowerLimit(0);
    fp4.setDefault(20); //Edit this value to set a new default

    }

    function main(Length, Source, Upper, Lower) {

    if (vADX == null) vADX = new ADXStudy(Length, Source);
    addBand(Upper,PS_SOLID,1,Color.black,1);
    addBand(Lower,PS_SOLID,1,Color.black,2);

    /********************************************
    Insert your code following this text block
    Use vADX.getValue(ADXStudy.ADX) for your code
    *********************************************/

    if(getBarState()==BARSTATE_NEWBAR){ //when a new bar is created

    if(vADX.getValue(ADXStudy.ADX,-2) < 30 && //IF the ADX of 2 bars ago was below 30 AND
    vADX.getValue(ADXStudy.ADX,-1) > 30){ //the ADX of 1 bar ago was above 30 THEN
    Alert.addToList(getSymbol(),"ADX Crossing Up",Color.black,Color.blue); //trigger an alert
    } //closes the crossing up condition

    if(vADX.getValue(ADXStudy.ADX,-2) > 70 && //IF the ADX of 2 bars ago was above 70 AND
    vADX.getValue(ADXStudy.ADX,-1) < 70){ //the ADX of 1 bar ago was below 70 THEN
    Alert.addToList(getSymbol(),"ADX Crossing Down",Color.black,Color.red); //trigger an alert
    } //closes the crossing down condition

    } //closes the new bar condition


    return vADX.getValue(ADXStudy.ADX);
    }

    Comment


    • #3
      Hi Spider,

      See this link: http://kb.esignalcentral.com/display...49&r=0.3123743

      1. Replace all instances of "ADXStudy" with "ADXDMStudy"
      2. Replace
      PHP Code:
      if (vADX == nullvADX = new ADXStudy(LengthSource); 
      with
      PHP Code:
      if (vADX == nullvADX = new ADXDMStudy(LengthLength); 
      The first length should be the DILength and the second Length should be the ADXLength as required by the syntax: ADXDMStudy(DILength, ADXLength) .

      Once this is done, it should work.

      Alternatively use the updated EFS2 version of ADX syntax found at: http://kb.esignalcentral.com/display...L=&r=0.9369776 and reference the sample customADXDM.efs found in the "...C:\Program Files\eSignal\Formulas\EFS 2 Custom" folder and/or a search of the forum for "ADXDMStudy".

      wayne
      Last edited by waynecd; 09-26-2009, 01:33 PM.

      Comment


      • #4
        Whats up Wayne,

        Good to see your post...how've you been?
        And yes, that adjustment fixed the code...thanks!

        Let me ask you this:
        I also want to draw an up arrow at the crossover points, along with an audio alert.

        I tried to copy and paste the code from your "Bollinger band piercing" code, and here's what I coded so far:

        if(vADX.getValue(ADXDMStudy.ADX,-2) < 30 &&
        vADX.getValue(ADXDMStudy.ADX,-1) > 30){
        Alert.addToList(getSymbol(),"ADX Crossing Up",Color.black,Color.blue);
        drawShape(Shape.UPARROW, BottomRow2 , Color.green);
        Alert.playSound("ding");
        }

        if(vADX.getValue(ADXDMStudy.ADX,-2) > 70 &&
        vADX.getValue(ADXDMStudy.ADX,-1) < 70){
        Alert.addToList(getSymbol(),"ADX Crossing Down",Color.black,Color.red);
        drawShape(Shape.DOWNARROW, TopRow1, Color.red);
        Alert.playSound("ding");
        }


        it seemed way to simple to copy and paste, haven't yet tried it out yet.
        what do you think?

        Comment


        • #5
          Hi Spyder

          Good to hear. Your solution should work fine.

          Using other functional code as reference and to get working lines of code, along with the other resources, is a good way to increase your knowledge .

          Wayne

          Comment


          • #6
            Yea, thats true Wayne, I've actually learned a lot just by referencing other custom EFS code on these forums.

            The only thing is that this EFS prints the arrows in the indicator window.
            Is there any way to print them in the chart window? (the main window).

            Also, could you explain how to print the arrows directly under the candlestick?

            drawShape(Shape.UPARROW, BottomRow2 , Color.green);

            I imagine you have to change the "Bottom Row" command?
            Lastly, is there a way to increase the size of the arrows?
            I couldn't find this in the Esignal function library.

            Thanks!

            Comment

            Working...
            X