Announcement

Collapse
No announcement yet.

getCurrentBarIndex is always -1, How do I get it to be 0 (zero)?

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

  • getCurrentBarIndex is always -1, How do I get it to be 0 (zero)?

    I downloaded the program called "BidAskVolume" and ran it. It will only give me the total volume and not the bid or ask volume. I narrowed it down to the statement that is causing the problem:

    if (getCurrentBarIndex() < 0) return;

    it appears that getCurrentBarIndex is never 0, it is always -1. What am I doing wrong?

    The program is below:
    PHP Code:
    function preMain() {
        
    setStudyTitle("Bid\/Ask Volume ");
        
    setCursorLabelName("Ask Vol"0);
        
    setCursorLabelName("Inside Vol"1);
        
    setCursorLabelName("Bid Vol"2);
        
    setDefaultBarFgColor(Color.green0);
        
    setDefaultBarFgColor(Color.black1);
        
    setDefaultBarFgColor(Color.red2);
        
    setDefaultBarThickness(40);
        
    setDefaultBarThickness(61);
        
    setDefaultBarThickness(42);
        
    setPlotType(PLOTTYPE_HISTOGRAM0);
        
    setPlotType(PLOTTYPE_HISTOGRAM1);
        
    setPlotType(PLOTTYPE_HISTOGRAM2);

        var 
    fp0 = new FunctionParameter("sType"FunctionParameter.STRING);
            
    fp0.setName("Analysis");
            
    fp0.addOption("Bar");
            
    fp0.addOption("Cumulative");
            
    fp0.setDefault("Bar");
    }

    var 
    nBidVol 0;
    var 
    nInsideVol 0;
    var 
    nAskVol 0;
    var 
    vVol null;
    var 
    bPrimed false;
    var 
    nAsk null;
    var 
    nBid null;

    function 
    main(sType) {
        if (
    getCurrentBarIndex() < -1) return; // ******  This is where the problem is?  ******
        
    var nState getBarState();    
        if (
    nState == BARSTATE_NEWBAR) {
            if (
    sType == "Bar" || day(0) != day(-1)) {
                
    nBidVol 0;
                
    nInsideVol 0;
                
    nAskVol 0;
            }
            
    vVol 0;
        }
       
        var 
    vPrevVol null;
        if (
    vVol != null && bPrimed == truevPrevVol vVol;
        
        var 
    nTempAsk getMostRecentAsk();
        var 
    nTempBid getMostRecentBid();
     
        if (
    nTempAsk != null && nTempAsk != 0nAsk nTempAsk;
        if (
    nTempBid != null && nTempBid != 0nBid nTempBid;

        var 
    vClose close();
        
    vVol volume();
        
        var 
    vTradeVol vVol vPrevVol;
        
        if (
    bPrimed == false && vVol != null) {
            
    bPrimed true;
            return;
        } else {
            if (
    vClose <= nBid) {
                
    nBidVol += vTradeVol;
            } else if (
    vClose >= nAsk) {
                
    nAskVol += vTradeVol;
            } else {
                
    nInsideVol += vTradeVol;
            }
        }

        return new Array(
    nAskVolnInsideVolnBidVol);

Working...
X