Announcement

Collapse
No announcement yet.

rawtime

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

  • rawtime

    can anyone tell me what's wrong with this code. misses step 5 to get rawtime

    //DELL 5 min chart, Time Template 1 day, PC time Zone GMT -8 Pacific Time

    Code:
    var bInit 		= false;
    
    function preMain() 
    {
        setPriceStudy(true);
        setShowTitleParameters(false);
        setShowCursorLabel(true);
    }
    
    var ssLast = null;
    var ssOpen = null;
    
    function main() 
    {
        if(getBarState() == BARSTATE_NEWBAR) 
        {
            var ssSymbol = "SPY";
    db("1.ssSymbol",ssSymbol);        
            var chInterval = getInterval();
    db("2.chInterval",chInterval)        
            var chIndex = getCurrentBarIndex();
    db("3.chIndex",chIndex);        
            ssLast = getValueAbsolute("Close",  chIndex, ssSymbol + "," + chInterval);
    db("4.ssLast",ssLast);        
            if(ssOpen == null || getDay(-1) != getDay(0))
            {
                var chOpenRaw = getValue("rawtime",chIndex);
    db("5.chOpenRaw",chOpenRaw);            
                var chOpenIndex = getFirstBarIndexOfDay(chOpenRaw);
    db("6.openindx",chOpenIndex);       
                if (chOpenIndex != null)
                {            
                    ssOpen = getValueAbsolute("Open",  chOpenIndex, ssSymbol + "," + chInterval);
    db("7.ssOpen",ssOpen); 
                }
            }
        }
        return null;
    }
    
    function db(a,b,c,d,e,f,g,h,i) 
    {
        var str = "[" + String("0"+getMonth()).slice(-2) + "/" + String("0"+getDay()).slice(-2) + " " + String("0"+getHour()).slice(-2) + ":" + String("0"+getMinute()).slice(-2) + "]";
        str += ",";
        if (a != null) str += a;
        str += ",";
        if (b != null) str += b;
        str += ",";
        if (c != null) str += c;
        str += ",";
        if (d != null) str += d;
        str += ",";
        if (e != null) str += e;
        str += ",";
        if (f != null) str += f;
        str += ",";
        if (g != null) str += g;
        str += ",";
        if (h != null) str += h;
        str += ",";
        if (i != null) str += i;
        debugPrintln(str);
        return;
    }
    Paul Williams
    Strategy & Applications
    www.futurenets.co.uk

  • #2
    this gets rawtime on first bar

    Code:
    function main() 
    {
        if(getBarState() == BARSTATE_NEWBAR) 
        {
            var ssSymbol = "SPY";
    db("1.ssSymbol",ssSymbol);        
            var chInterval = getInterval();
    db("2.chInterval",chInterval)        
            var chIndex = getCurrentBarIndex();
    db("3.chIndex",chIndex);        
            ssLast = getValueAbsolute("Close",  chIndex, ssSymbol + "," + chInterval);
    db("4.ssLast",ssLast);  
            if(ssOpen == null || getDay(-1) != getDay(0))
            {
                var chOpenRaw = rawtime(0); //getValue("rawtime",chIndex);
    db("5.chOpenRaw",chOpenRaw);            
                var chOpenIndex = getFirstBarIndexOfDay(chOpenRaw);
    db("6.openindx",chOpenIndex);       
                if (chOpenIndex != null)
                {            
                    ssOpen = getValueAbsolute("Open",  chOpenIndex, ssSymbol + "," + chInterval);
    db("7.ssOpen",ssOpen); 
                }
            }
        }
        return null;
    }
    Paul Williams
    Strategy & Applications
    www.futurenets.co.uk

    Comment


    • #3
      a better solution ...

      Code:
      function main() 
      {
          if(getBarState() == BARSTATE_NEWBAR) 
          {
              var ssSymbol = "SPY";
      db("1.ssSymbol",ssSymbol);        
              var chInterval = getInterval();
      db("2.chInterval",chInterval)        
              ssLast = close(0, sym(ssSymbol + "," + chInterval));
      db("3.ssLast",ssLast);  
              if(ssOpen == null || getDay(-1) != getDay(0))
              {
                  var chOpenRaw = rawtime(0);
      db("5.chOpenRaw",chOpenRaw);            
                  var ssOpenIndex = getFirstBarIndexOfDay(chOpenRaw,ssSymbol);
      db("6.ssOpenIndex",ssOpenIndex);       
                  if (ssOpenIndex != null)
                  {            
                      ssOpen = getValueAbsolute("Open",  ssOpenIndex, ssSymbol + "," + chInterval);
                               //open(ssOpenIndex, sym(ssSymbol + "," + chInterval)); .. doesn't like this
      db("7.ssOpen",ssOpen); 
                  }
              }
             
          }
          return null;
      }
      Paul Williams
      Strategy & Applications
      www.futurenets.co.uk

      Comment


      • #4
        Paul,

        Always declare all global variables at the top of your file before any function declarations.

        Always declare all local variables at the top of their respective function declarations (right after the first "{").

        Comment

        Working...
        X