Announcement

Collapse
No announcement yet.

Use of own Arrays and Built In functions to store and retreive data

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

  • Use of own Arrays and Built In functions to store and retreive data

    Having a hard time what should be an easy task:-

    Feeding own arrays with eSignal Built In functions and then retrieving the data for further calculation.

    For example following main

    START OF CODE

    if ( getBarState() == BARSTATE_ALLBARS ){

    // Built In
    xADX = adx(14,14);
    var vADX;

    var nADX, nADX_P, vADXDif;

    // Create a new array
    // ADX Values
    var nADXOscLenP=1;
    aADX = new Array(nADXOscLenP+1);

    // ADX Oscillator
    aADXDif = new Array(2);

    //
    var vADXDif, rADXDif;

    return null;
    } // END ALLBARS

    // ADXDM Values
    vADX = getSeries(xADX, 0);

    // Feed ADX values to user array
    if(getBarState() == BARSTATE_NEWBAR) {
    aADX.unshift(vADX);
    aADX.pop(); //
    } else if(getBarState() == BARSTATE_CURRENTBAR) {
    aADX[0]= vADX; //
    }

    nADX=aADX[0];
    nADX_P=aADX[nADXOscLenP-1];
    vADXDif=(nADX-nADX_P);

    // Feed ADXDif values to user array
    if(getBarState() == BARSTATE_NEWBAR) {
    aADXDif.unshift(vADXDif);
    aADXDif.pop(); //
    } else if(getBarState() == BARSTATE_CURRENTBAR) {
    aADXDif[0]= vADXDif; //
    }

    rADXDif=aADXDif[0]-aADXDif[1];

    return rADXDif;

    END OF CODE

    The reason I am not calling the ADX series directly is that in case the period for Oscillator is greater than ADX length that the values of each current nADX is fed into the array.

    Until now all the values in aADXOsc array are all the same so I can't calculate a difference.

    Any help will be greatly appreciated

    Robert

  • #2
    As I understand your post, all you need is the difference of the difference of the last two ADX values.

    If so try:
    PHP Code:
    var nADXDif;
    function 
    main() {
        if(
    nADXDif == nullnADXDif efsInternal("ADX_Diff");//creates & assigns a series of the difference of the current and previous adx values
        
    return nADXDif.getValue(0) - nADXDif.getValue(-1);
    }
    var 
    xADX;
    function 
    ADX_Diff(){
        if(
    xADX == nullxADX adx(1414);
        return 
    xADX.getValue(0) - xADX.getValue(-1);

    A forum search of "efsInternal" would help you out.

    Wayne
    Last edited by waynecd; 02-27-2013, 12:04 AM.

    Comment


    • #3
      Wayne

      Thank you for your suggestion - both code and looking in the forum.

      I want the code to run into arrays as mentioned when the ADX difference is user selectable and can be greater than the period chosen for ADX therefore each ADX value for each bar can be captured on a bar by bar basis.

      My main point really is that the code I have shown does not capture data bar by bar and it is therefore faulty. I wouls like to know where it is wrong.

      Robert

      Comment


      • #4
        I found where the problem was and have corrected the whole code.

        The problem was in the following:-
        // Built In
        xADX = adx(14,14);

        // ADXDM Values
        vADX = getSeries(xADX, 0);

        I eliminated one user array by now doing the following:-

        nADX=adx(14, 14,0); // ADX current bar
        nADX_P=adx(14, 14,-(nADXDifLenP)); //ADX for lookback bar value

        The difference is found and if the user requires a further difference is calculated in a user defined array.

        The full code and working efs is attached in case it helps anyone with coding or wishes to use the indicator.

        Robert
        Attached Files

        Comment


        • #5
          Robert
          IMHO that seems to be a somewhat convoluted way of coding the study.
          You can accomplish the same results with the code shown in the following image.



          Just replace your entire main function with what is shown. As an aside this would allow you to also easily define a lookback for the difference of the difference of the ADX [and/or use the xADXDif series nested in other built-in or custom functions e.g. a moving average]
          Also you may want to use the Boolean type instead of String type for the bADXDoDDspP FunctionParameter
          Alex

          Comment


          • #6
            Alexis

            Thanks for that the code works well and certainly much simpler and cleaner.

            Robert

            Comment


            • #7
              Robert
              You are welcome
              Alex


              Originally posted by rcamrn123 View Post
              Alexis

              Thanks for that the code works well and certainly much simpler and cleaner.

              Robert

              Comment

              Working...
              X