Announcement

Collapse
No announcement yet.

TICK call question

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

  • TICK call question

    I started using this a few weeks ago:

    myTICK = "$TICK,1";
    myTICK_H_now = high(0, 1, myTICK)*1;
    myTICK_L_now = low(0, 1, myTICK)*1;

    I briefly remember someone stating there is an error in this call. I just wanted to clarify . . .

    In the following . . .

    myTICK_H_now = high(0, 1, myTICK)*1;

    I understand that 0 is for the current index, but I am not sure what the 1 next to it represents. I thought that it might have been the length of the chart, like 1 minute or 3 minute, but I thought that is what the 1 is for in:

    myTICK = "$TICK,1";

    So just a quick explanation would help make sure I am calling this right.

    Thanks a million,

    Thomas.

  • #2
    Hello Thomas,

    Here's a description of high() from our EFS Help Center;

    high([nRelativeOffset] [, nNumBars [, Symbol ] ])

    The second parameter is the number of bars you want to retrieve. The parameters are all optional, so if you only want the current bar's high for $TICK you could just use high(myTick). You use the other two parameters to retrieve an array of prices. Typically nRelativeOffset is set to 0 to include the current bar. The second parameter is most commonly set to a negative number to retrieve an array of prices older than the bar specified by nRelativeOffset. For example, if you wanted to get the most recent 5 bar's highs of $TICK you could use high(0, -5, myTick). Your variable, myTick_H_now would become an array of 5 so you could then reference each price individually like so.

    myTick_H_now[0] // high at bar 0
    myTick_H_now[1] // high at bar -1
    myTick_H_now[2] // high at bar -2
    myTick_H_now[3] // high at bar -3
    myTick_H_now[4] // high at bar -4

    In my opinion, using a negative value for nNumBars is the best way to go because then the array element numbers match up with bar indexes. The only difference is the sign. However, you can specify a positive number for nNumBars, but if you’re at bar 0, our example above will return null. Therefore you should specify a negative value for nRelativeOffset. So, to get the same array of 5 prices above you could use high(-4, 5, myTick). This will give you the same prices in reverse order in the return array.

    myTick_H_now[0] // high at bar -4
    myTick_H_now[1] // high at bar -3
    myTick_H_now[2] // high at bar -2
    myTick_H_now[3] // high at bar -1
    myTick_H_now[4] // high at bar 0

    One more thing for good programming habits. When using calls like this to get arrays of prices its a good idea to perform a null check immediately after to prevent miscalculations later in your code that will be expecting a value to exist. See the null check example below following the call to high(). By the way, this code example only prints the results to the formula output window so be sure to have that open (Tools-->EFS-->Formula Output Window).

    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("test");
        
    setShowCursorLabel(false);
        
    }

    var 
    bEdit true;

    function 
    main() {

        if (
    bEdit == true && getCurrentBarIndex() == 0) {
            var 
    myTick "$TICK,1";
            var 
    myTick_H_now high(01myTick);
            
    debugPrintln(myTick_H_now);
        }
        
        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
      Thanks so much

      Jason . . .

      AWESOME, thanks so much. Just one question, do arrays have to be declared any differently than normal variables?

      T

      Comment


      • #4
        Hello Thomas,

        When you are declaring a normal array to store some values you can do one of the following.

        var myArray = new Array()

        or

        var myArray = new Array(10)


        You can declare an array with or without specifying the length. When using a call like high(), the returned result from this function is an array, even if you only request a single price. That's why you see var myArray = high(0, 1, myTick) *1 where the function is multiplied by 1. Since it's an array of size 1, we can simply multiply by 1 to convert it to a number. Otherwise you would need to refer to the returned prices as myArray[0].
        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

        Working...
        X