Announcement

Collapse
No announcement yet.

constructing time/price array

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

  • constructing time/price array

    I am trying to construct two arrays, one for price and one for time. It appears to be difficult to find a correct correlation between the time at the end of the bar and the close.
    (and this for e.g. the previous 20 or 30 bars of a specific time-frame chart).

    At first I would have thought this is not a difficult problem, maybe there is some misunderstanding from my side ???

    Any suggestions are welcome

    My abreviated script is below:

    function preMain()
    {
    setPriceStudy(false);
    setStudyTitle("Time Price study");
    setCursorLabelName("Time_Price");
    }

    function main(nLength,nBarPlus)
    {
    var mPrices = new Array(depth);
    var mTimes = new Array(depth);
    var depth = 30;
    var parameter;
    var period = getInterval();
    var vPrice = getValue("Close", 0, -depth);
    var vTime = getValue("rawtime",-depth)
    for(i = 0; i < depth; i++)
    {
    mPrices[i] = vPrice[i];
    // this is a first possibility for a one minute chart,
    // does not work out
    mTimes[i] = - 60 * i ;
    // this is a second possibility for a one minute chart,
    // does not work out either
    mTimes[i]=vTime[i];
    }
    //meaningless example
    parameter=(vPrice[0]-vPrice[1])/(
    return(parameter);
    }

    It is obvious that I want to make this thing robuts enough to spand over the non-trading periods (week-ends and nights).
    Attached Files

  • #2
    Hello jhonick,

    I'm not clear on what your formula example was trying to accomplish. Perhaps you could expand a bit on the result of the two possibilities you mentioned that aren't working out. Describe the result that you are expecting to see. If you just need the two arrays, the following routine will fill and maintain two arrays for price and time that will be the most recent number of bars with size based on depth. The zero element being the most recent bar. Let me know if this helps or if you have other questions.

    PHP Code:
    function preMain() {
        
    setPriceStudy(false);    
        
    setStudyTitle("Time Price study");
        
    setCursorLabelName("Time_Price");
    }

    var 
    mPrices null;
    var 
    mTimes null;

    function 
    main(depth) {
        if (
    depth == nulldepth 30;
        
        if (
    mPrices == null || mTimes == null) {    // arrays only need to be created once.
            
    mPrices = new Array(depth);
            
    mTimes = new Array(depth);
        }

        if (
    getBarState() == BARSTATE_NEWBAR) {
            
    mPrices.pop();      // removes last array element
            
    mPrices.unshift(null);  // inserts one array element to the front of the array
            
    mTimes.pop();
            
    mTimes.unshift(null);
        }
        
        var 
    vPrice close();
        
    mPrices[0] = vPrice;

        var 
    vTime getValue("rawtime");
        
    mTimes[0] = vTime;
        
        
    // if arrays are not complete, return
        
    if (mPrices[depth-1] == null || mTimes[depth-1] == null) return;
        

        
    //meaningless example
        
    var parameter = (mPrices[0]-mPrices[1])/(mTimes[0]-mTimes[1]);

        return 
    parameter

    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