Announcement

Collapse
No announcement yet.

Array of closes from one timeframe into another

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

  • Array of closes from one timeframe into another

    I want to pass an array of say 10minute closes for 20 bars in that timeframe into a smaller timeframe say 1minute.

    I have tried numerous combinations of getValue() or calling close() function without success.

    This has to be an easy and obviously I am missing something, as it is easy to do it for all built in indicators such as rsi, cci etc...

    Any help would be appreciated

    Robert

  • #2
    Hi Robert,

    Have you tried myArray = close( 0, -20, inv("10")); ?

    Comment


    • #3
      Hi Robert,

      Evidently this does not work, I am sorry I lead you astray. As I had remembered this, it was on a list to be included in EFS2...

      Regards,

      Comment


      • #4
        I'm glad it was not me going mad trying to get this to work, the only way I can get things to work is to call individual prices such as:-

        close(-2, sym(YM #F, 10))

        which is very inefficient and cpu intensive rather than calling an array and assigning to a variable. Especially when you want to do some summing or averaging or whatever using non built in eSignal functions.

        Something for inclusin in next release? I believe it is necessary

        Also it would be nice if hl2(), hlc3() be expanded and work like close() etc... rather than just a macro to be placed in built in eSignal functions

        Robert
        Last edited by rcameron; 06-13-2005, 01:43 PM.

        Comment


        • #5
          Hi Robert,

          Actually close(-2, sym("YM #F, 10")) (iterating over the 10 values that you want to get) will be equivalent in CPU usage to the EFS2 engine returning an array, which is why it was not done for EFS2.

          Also, not sure I understand about hl2(), hlc3() ? They use the same backend processing and code as close(), high(), low(), etc... and are not just macros.

          ie, you can do hl2(-2, sym("YM #F, 10")) etc... However, as EFS2 functions, they do not support (at least I don't think they do) the EFS1 array getValue calls, is that what you were looking for?

          Comment


          • #6
            Hi Dion,

            I cannot get close(-2, sym("YM #F, 10")) to pass an array, just a single value.

            With regard to hl2() etc... according to the help file there are no input parameters indicated. However using sym() function within the macro actually works, without it you get nothing, at least this is some help to me now. Nevertheless it is only a single value not an array.

            If you can confirm that you can get an array of values using close, open etc... with accessing other symbols & intervals from outside the current timeframe then I would like to know as doing so with individual calls and building my own array is time consuming in terms of cpu cycles as well as unnecessary extra lines of coding.

            Robert

            Comment


            • #7
              OK I cracked it regarding using regular EFS1 close() etc... functions to get an array from another timeframe, do not use sym() within the function (I knew it had to be easy - duh):-

              Last 10 closes from YM #F Daily into any timeframe

              close(0, -10, "YM #F,D")


              10 closes from 5 bars ago in IBM 15min into any timeframe

              close(-5, -10, "IBM,15")

              However hl2(), hlc3(), ohlc4() refuses to return anything using this method and using sym() within these macros do return a single value not an array.

              So i have a net gain from this posting that I can utilize the new macro functions in a limited way at least! However it would be nice if they could work exactly the same as close(), open(), high(), low() in all respects.

              It would also be good if we could have a function like truehigh() and truelow(), truerange(), range() with all the same capabilities as close(). It would eliminate a lot of coding. anything for an easy life.

              Robert

              Comment


              • #8
                Returning arrays is an EFS1 function, which was not carried over to the EFS2 functions.

                I would suggest retrieving the values one by one instead of in an array. With EFS2 this is just as efficient. Is there a particular reason why you need an array?

                The objects that EFS2 returns behave in an array-like manner:

                PHP Code:
                var mySeries getSeries(hl2(sym("INTC,5")));
                mySeries.getValue(0);
                mySeries.getValue(-1);
                mySeries.getValue(-2);
                etc.. 
                truerange() and range() should be pretty easy to add (for 7.9.2 though, not the upcoming version).

                What does truehigh() and truelow() do though?

                Comment


                • #9
                  Dion,

                  Using all the information to date in this posting I have now developed my own function that is called when I want an array of data to work on for various needs in my efs projects. So within main I may do the following call:-

                  myArr = fnPrcArr("close",0,10,"YM #F, 10" );

                  or

                  myArr = fnPrcArr("hl2",0,20,"YM #F, D" );


                  // *******************************************
                  function fnPrcArr(sPrcSrc, nPrcStrt, nPrcPer, sOscSymInt){
                  // -------------------------------------------------------------------
                  var i, j;
                  var aArrSrc = new Array();


                  switch (sPrcSrc){

                  case "close": // close
                  aArrSrc = close(-nPrcStrt, -nPrcPer, sOscSymInt) ;
                  break;

                  case "open": // open
                  aArrSrc = open(-nPrcStrt, -nPrcPer, sOscSymInt) ;
                  break;

                  case "high": // high
                  aArrSrc = high(-nPrcStrt, -nPrcPer, sOscSymInt) ;
                  break;

                  case "low": // low
                  aArrSrc = low(-nPrcStrt, -nPrcPer, sOscSymInt) ;
                  break;

                  case "hl2": // (h+l)/2
                  for(i = 0; i < nPrcPer; i++) {
                  aArrSrc[i] = hl2(-i, sym(sOscSymInt)) ;
                  }

                  break;

                  case "hlc3": // (h+l+c)/3
                  for(i = 0; i < nPrcPer; i++) {
                  aArrSrc[i] = hlc3(-i, sym(sOscSymInt)) ;
                  }

                  break;

                  case "ohlc4": // (o+h+l+c)/4
                  for(i = 0; i < nPrcPer; i++) {
                  aArrSrc[i] = ohlc4(-i, sym(sOscSymInt)) ;
                  }

                  break;

                  } // end switch

                  return aArrSrc;

                  // ------------------------------------------------------------
                  } // END function fnPrcArr(sPrcSrc, nPrcStrt, nPrcPer, sOscSymInt)
                  // ------------------------------------------------------------


                  I like using arrays rather than calling each price as a single value as I find noticibly less cpu cycles are needed this way.

                  If we could get the functions I mentioned soon that would be great, with full capability to call full arrays as well as referencing other symbols and timeframes. The formula for each function would be as follows:-

                  truehigh(nOff) = Math.max( close(-(nOff+1)), high(-(nOff) )

                  truelow(nOff) = Math.min( close(-(nOff+1)), low(-(nOff) )

                  range(nOff) = high(nOff) - low(nOff);

                  truerange(nOff) = Math.max (Math.max (Math.abs(high(-(nOff)) - low(-(nOff))), Math.abs(close(-(nOff+1)) - high(-(nOff)))), Math.abs(close(-(nOff+1))- low(-(nOff)))) );

                  Another question, is there any way to use built in efs functions such sma(), etc... to work on a user built array ie:-

                  // ===============================
                  // Price Array
                  var aIx = new Array(); // create empty array

                  // -------------------------------------------------------
                  function preMain(){
                  //
                  setPriceStudy(false);

                  var k;
                  // USER SELECTION

                  //set up our function parameters
                  k=0;
                  aPArrG[k] = new FunctionParameter( "nArrPer", FunctionParameter.NUMBER);
                  with( aPArrG[k] ) {
                  setLowerLimit( 1 );
                  setDefault( 10 );
                  }
                  k++;

                  } // END PREMAIN
                  // ----------------------------------------------------

                  // MAIN
                  function main(nArrPer ){


                  // *************************
                  if ( getBarState() == BARSTATE_ALLBARS ){
                  // ----------------------------------------
                  var myVar1, myVar2;

                  aIx.PArr = new Array(nArrPer );


                  // ----------------------------------------
                  return null;
                  } // END ALLBARS
                  // ======================

                  myVar1 = close(0) - close(-2);

                  // Feed the Price array
                  if(getBarState() == BARSTATE_NEWBAR) {
                  aIx.PArr.unshift(myVar1);
                  aIx.PArr.pop();

                  } else if(getBarState() == BARSTATE_CURRENTBAR) {
                  aIx.PArr[0]= myVar1;

                  }

                  // -------------------------
                  // FUNCTION REQUIRED
                  myVar2 = sma(aIx.PArr);
                  // ---------------------------

                  return (myVar2);

                  } // END MAIN
                  // ====================================



                  So that myVar2 would be easily calculated by the efs function in question as it would be smart enough to work out the length of the array being passed.

                  Robert

                  Comment


                  • #10
                    Hi,

                    The thing is the new Series object was intended as the 'Array' replacement.

                    You can use sma, ema etc.. if you return a Series object from your own code, which can be done using the efsInternal or efsExternal calls (efsExternal is the replacement for efs() in 7.9.1).

                    Comment


                    • #11
                      Dion,

                      I wrote the attached efs script in EFS2 format to try to emulate the built in ATR function as I require the functionality of both True Range and Wilders MA for use individually in other projects.

                      The script works with no problems in the current timeframe but totally fails in accessing other timeframes and I don't know how to proceed further having tried many different methods with no success.

                      Any help to resolve would be much appreciated.

                      Robert
                      Attached Files

                      Comment


                      • #12
                        Robert
                        See my reply here
                        Alex

                        Comment


                        • #13
                          DionLoy,

                          I am converting my EFS1 scripts to EFS2. Could you tell me the most efficient yet simple way to access the close prices of the second symbol/interval within a specific range (i.e. the close price of "$INTC,5" of the most recent five bars when the primary symbol is "$SPX")?

                          According to the syntax of close() in the developer's reference (
                          close( barIndex [, numBars] [, sym()] [, inv()] ) ),
                          close(0, -20, sym("INTC"), inv("5"))
                          and close(0, -20, sym("INTC"), inv("5"))
                          should be valid expressions. Why do they not work?

                          Thanks.

                          -- Clearpicks




                          Thanks.


                          -- Clearpicks



                          Originally posted by DionLoy
                          Returning arrays is an EFS1 function, which was not carried over to the EFS2 functions.

                          I would suggest retrieving the values one by one instead of in an array. With EFS2 this is just as efficient. Is there a particular reason why you need an array?

                          The objects that EFS2 returns behave in an array-like manner:

                          PHP Code:
                          var mySeries getSeries(hl2(sym("INTC,5")));
                          mySeries.getValue(0);
                          mySeries.getValue(-1);
                          mySeries.getValue(-2);
                          etc.. 
                          truerange() and range() should be pretty easy to add (for 7.9.2 though, not the upcoming version).

                          What does truehigh() and truelow() do though?
                          Last edited by clearpicks; 06-19-2005, 08:32 PM.

                          Comment


                          • #14
                            What would be the method to maintain a Bar Counter in one timeframe from another.

                            The usual way to maintain a bar counter in a single timeframe would be something like:-


                            // Bar Counter
                            var nBrCntrG = 0;

                            main(){

                            if ( getBarState() == BARSTATE_NEWBAR ){
                            nBrCntrG++
                            }

                            /*
                            Do something with the bar counter like save a price in an array
                            at a specific bar reference for future reuse like drawing lines
                            from one point to anotehr, checking price values etc...
                            */

                            }

                            So if in the above case a series was created using a higher timeframe and/or symbol then how would the bar counter be maintained for that timeframe

                            Robert

                            Comment


                            • #15
                              Robert
                              Version 7.9.1 adds two new functions for that
                              getBarStateInterval("interval")
                              getBarStateSymbol("symbol" or "symbol,interval")

                              In both functions the parameter is a string and you do not use inv() or sym()
                              Alex

                              Comment

                              Working...
                              X