Announcement

Collapse
No announcement yet.

Getting exact open price and price ranges in specific timeframes across charts

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

  • Getting exact open price and price ranges in specific timeframes across charts

    Hi ,

    I have three charts. 512T, 3500T and 5M. And I've been struggling with getting consistent price bars on these charts for open price, first 15 mins price-range, pre-market price range, prev-day price range across these charts. When I load the same study on the three charts, they come up with different numbers and as a result I endup with in-consistent indicators on all the three charts. I tried to have a fourth chart (1 Sec) that would set global values for the above and then the studies on the 512T, 3500T, and 5M charts just read the global values, but that causes a lot of performance issues as I need to load a lot of bars for 1 sec chart to span back to previous day. Any help would be deeply appreciated. Here's my code for calculating open and first 15min high/low -


    //OPEN
    var openPrice = null;
    //OPEN RANGE
    var openRangeHigh = null;
    var openRangeLow = null;
    var tempOpenRangeHigh = null;
    var tempOpenRangeLow = null;

    function preMain() {
    setPriceStudy(true);
    }

    function main() {
    var barIndex = getCurrentBarIndex();

    var curHour = null;
    var curMin = null;
    var todayDate = null;
    var lastTrade = null;

    //Logic to figure out if we're in present or in the past
    if(barIndex == 0) {
    today = new Date();
    todayDate = today.getDate();
    curHour = today.getHours()+3;
    curMin = today.getMinutes();
    lastTrade = getMostRecentTrade();
    } else {
    today = getDay();
    curHour = getHour();
    curMin = getMinute();
    lastTrade = close();
    }

    //Prepare counters for the next trading day
    if(openPrice != null && curHour == 16 && curMin >= 0) {
    openPrice = null;
    openRangeHigh = null;
    openRangeLow = null;
    }
    //OPEN PRICE
    if(openPrice == null && curHour == 9 && curMin == 30){
    openPrice = lastTrade;
    }
    //OPEN RANGE
    if(openRangeHigh == null && curHour == 9 && curMin >= 30){
    if(tempOpenRangeHigh == null || tempOpenRangeHigh < lastTrade){
    tempOpenRangeHigh = lastTrade;
    }
    if(tempOpenRangeLow == null || tempOpenRangeLow > lastTrade){
    tempOpenRangeLow = lastTrade;
    }
    //Trigger for setting and plotting the range
    if(curMin >= (45)){
    openRangeHigh = tempOpenRangeHigh;
    openRangeLow = tempOpenRangeLow;
    }
    }
    }

    Thanks!

    EsigTrader

  • #2
    Hi,

    Consider running your script on the lowest interval chart you use, modifying it to setGlobalValue() for open, close, hirange, and lorange variables as they change. Then load a modified version of the script on the higher interval charts that use the getGlobalValue() to retrieve the global values set in the lowest interval chart.

    Conceptually this should solve your issue of consistent values without increasing overhead (other than the global variables).

    Note: Bars of different charts with different intervals and/or time templates will start at different times so the open, close, etc. will not match. A workaround is a lot of coding and applying different time templates that use different number of bars to charts with different intervals, etc.

    If you prefer one script that determines it all itself then you can use setGlobalValue() to create an array of arrays (two dimensional array) that adds [symbol, interval] as the first element of the primary array then the following elements would contain the getInvokerID(), & other needed values as additional array elements for the second dimension array (it would replace values not add them if the getInvokerID() in the array is the same as the charts getInvokerID()). Then have the script determine which set of elements includes the lowest interval and use that set of values in the chart. This method is of course more complicated. An example of the array for 3 charts of different intervals might be structured as:

    PHP Code:
    AAPL_GlobalArray=[[symbolinterval],[getInvokerID(),open,close,hirange,lorange],[getInvokerID(),open,close,hirange,lorange],[getInvokerID(),open,close,hirange,lorange]]; 
    Where only the internal array (2nd dimension) that matches the getInvokerID() of the calling chart is changed by the charts script. If the getInvockerID() is not found then the internal array is created, if it already exists then the values are updated. I would name the setGlobalValue() array using the chart symbol first then some suffix so that you can easily reference it in the script (on a script running in an AAPL chart you would getGlobalValue("AAPL_GlobalArray").

    I hope that makes sense.

    Wayne
    Last edited by waynecd; 12-07-2015, 07:26 PM.

    Comment


    • #3
      Please disregard everything including and after "If you prefer one script that determines it all itself " in my last post. Unless I am wrong, based on some script testing it seems that setGlobalValue() will not accept multidimensional arrays, only values and one dimensional arrays.

      As a side note:

      the code line with "if(curMin >= (45)){" will execute every hour between minutes 45 and 59. It will then halt execution for the next hour's minute 0 through minute 44. Consider using a full hour as a reference point. Something like:
      PHP Code:
      if((getHour(0)*100)+getMinute(0) >= 945){ 
      Wayne
      Last edited by waynecd; 12-08-2015, 12:23 AM.

      Comment

      Working...
      X