Announcement

Collapse
No announcement yet.

getCurrentBarIndex() equivalent for external Interval

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

  • getCurrentBarIndex() equivalent for external Interval

    Is there a "getCurrentBarIndex() " equivalent for external Intervals?

    I don't believe that there is an eSignal function for it but if anyone knows of a way to accomplish the same thing for an external interval I would appreciate it.

    Wayne

  • #2
    An example from Stevehare2003's file share does the trick on first load but as soon as a new bar in the lower time frame forms the index synchronization is lost.

    Running it on a 100T chart and and external interval of 3 minutes the arrows show each new bar of the 3 min interval and the chart bar index at that 3 min bar matches the Formula Output window bar index on first load. But once a new bar is plotted on the 100T chart the synchronization is lost.

    Any ideas on how to keep the bar indexes synchronized are appreciated.

    PHP Code:
    //see "BARCOUNT_OF_EXTERNAL_INTERVAL_EXAMPLE.EFS" from Stevehare2003 fileshare
    //debugClear();
    var aFPArray = new Array();
    function 
    preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("NEW BAR MARKER & SYM() Bar Index.EFS");
        
    setCursorLabelName("Symbol Index",0);
        
    setCursorLabelName("Chart Index",1);
        
    //setColorPriceBars(true);
        
    setDefaultPriceBarColor(Color.grey);
        var 
    x=0;
        
    aFPArray[x] = new FunctionParameter("Symbol"FunctionParameter.STRING);
        
    with(aFPArray[x++]){
            
    setDefault();
        }
        
    aFPArray[x] = new FunctionParameter"Interval"FunctionParameter.STRING); 
        
    withaFPArray[x++] ) { 
            
    setName"Price Interval" ); 
            
    addOption"2250V" ); 
            
    addOption"55T" ); 
            
    addOption"233T" ); 
            
    addOption"512T" ); 
            
    addOption"1" );
            
    addOption"3" );
            
    addOption"5" );
            
    addOption"10" );
            
    addOption"15" );
            
    addOption"30" );
            
    addOption"60" );
            
    addOption"120" );
            
    addOption"240" );
            
    addOption"D" );
            
    addOption"W" );
            
    addOption"M" );
            
    addOption"Default" );
            
    setDefault); 
        }   
        
    aFPArray[x] = new FunctionParameter"ShapeColor"FunctionParameter.COLOR);
        
    withaFPArray[x++] ) {
            
    setName"If Shape: Shape Color");
            
    setDefaultColor.green );
        }  
        
    aFPArray[x] = new FunctionParameter"OffsetCorrection"FunctionParameter.STRING);
        
    withaFPArray[x++] ) {
            
    setName"If Winding: Text Offset" );
            
    setLowerLimit(0);        
            
    addOption); 
            
    addOption10 ); 
            
    addOption19 ); 
            
    addOption28 ); 
            
    addOption37 ); 
            
    addOption(46 ); 
            
    setDefault37 ); 
        }  
        
    aFPArray[x] = new FunctionParameter"CtrOffset"FunctionParameter.STRING);
        
    withaFPArray[x++] ) {
            
    setName"If Winding: Text Offset" );
            
    addOption); 
            
    addOption( -); 
            
    addOption10 ); 
            
    addOption( -10 ); 
            
    addOption12 ); 
            
    addOption( -12 ); 
            
    setDefault12 ); 
        }  
    }
    var 
    grID 0;
    var 
    vSymbol null;
    var 
    vCtr = -1;
    var 
    barCtTSeriesT;
    var 
    xIdx;
    var 
    IdxIntvl 0;
    var 
    vSymBarIndex;
    var 
    vNewBarCnt 0;
    //var vNewBarCnt1 = 0;
    var bInit false;
    function 
    main(Symbol,Interval,ShapeColor,OffsetCorrection,CtrOffset) {
        var 
    vInterval,nState,nBarIndex,Temp;
        
    nBarIndex getCurrentBarIndex();
        
    //if(getBarState() == BARSTATE_ALLBARS){
        
    if(!bInit){
            if(
    Symbol == nullSymbol getSymbol();
            if(
    Interval == "Default" || Interval == nullInterval getInterval();
            
    vInterval Interval;
            
    vSymbol Symbol+","+vInterval;
            
    series1 efsInternal("fInvBarCnt"vSymbol);//sym(vSymbol));
            
    barCtTSeriesT getSeries(series10);
            
    xIdx getSeries(series11);
            
    bInit true;
        }
        if(
    nBarIndex === 0){
            if(
    getBarState() == BARSTATE_NEWBAR){
                
    vNewBarCnt getCurrentBarCount();
            }
        }
        
    nState getBarStateSymbol(vSymbol);
        if(
    vSymBarIndex == null || vSymBarIndex == undefinedvSymBarIndex IdxIntvl;
        if (
    nState == BARSTATE_NEWBAR){
            
    vCtr += 1;
            if(
    vInterval != getInterval()){
                
    drawTextRelative(0,OffsetCorrection,"\u00E2",ShapeColor,null,
                    
    Text.VCENTER Text.RELATIVETOTOP |Text.CENTER|Text.BOLD,"Wingdings",10,"Wing"gID());
                
    drawTextRelative(0,OffsetCorrection-CtrOffset,vCtr,ShapeColor,null,
                    
    Text.VCENTER Text.RELATIVETOTOP |Text.CENTER|Text.BOLD,null,10,"Wing"gID());
            }
            if(
    nBarIndex != 0)
                
    vSymBarIndex = -1*(Math.abs(nBarIndex)-(getCurrentBarCount()-xIdx.getValue(0)));
            else{
                
    //vNewBarCnt1 = getCurrentBarCount();
                
    vSymBarIndex = -1*(vNewBarCnt-xIdx.getValue(0));
            }
        }
        
    Temp getCurrentBarCount() - xIdx.getValue(0)
        
    vSymBarIndex vSymBarIndex Temp;
        return new Array(
    vSymBarIndex+"",nBarIndex+"");
    }
    var 
    barCtSym=0;
    var 
    CrntBarCnt 0;
    function 
    fInvBarCnt(a) { // retains constant value
        
    var barStateT,barStateSym;
        
    barStateSym getBarStateSymbol);
        if (
    barStateSym === 0) { //~  BARSTATE_NEWBAR condition
            
    barCtSym += 1;
            
    CrntBarCnt getCurrentBarCount();
        }
        return new Array(
    barCtSym,CrntBarCnt);
    }
    function 
    gID() {
        
    grID ++;
        return( 
    grID );

    Attached Files
    Last edited by waynecd; 11-12-2010, 02:53 AM.

    Comment


    • #3
      I should have added in case it helps explain:

      I get the same lack of synchronization even when I put "sym(vSymbol) at the end of the efsInternal call as in:

      PHP Code:
      series1 efsInternal("fInvBarCnt"sym(vSymbol)); 
      and of course change the "getBarState..." in the efsInternal function accordingly as in:

      PHP Code:
      function fInvBarCnt(a) {
          var 
      barStateT,barStateSym;
           
      barStateSym getBarState();
          if (
      barStateSym == BARSTATE_NEWBAR ){ 
             
      barCtSym += 1;
              
      CrntBarCnt getCurrentBarCount();
          }
          return new Array(
      barCtSym,CrntBarCnt);

      Wayne
      Last edited by waynecd; 11-12-2010, 11:07 AM.

      Comment


      • #4
        In case anyone can use it here is my version: (it keeps track of the bar index of the current chart that corresponds to each bar of a higher external interval.

        PHP Code:
        //see "BARCOUNT_OF_EXTERNAL_INTERVAL_EXAMPLE.EFS" from Stevehare2003 fileshare

        debugClear();
        var 
        aFPArray = new Array();
        function 
        preMain() {
            
        setPriceStudy(true);
            var 
        x=0;
            
        aFPArray[x] = new FunctionParameter("Symbol"FunctionParameter.STRING);
            
        with(aFPArray[x++]){
                
        setDefault();
            }
            
        aFPArray[x] = new FunctionParameter"Interval"FunctionParameter.STRING); 
            
        withaFPArray[x++] ) { 
                
        setName"Price Interval" ); 
                
        addOption"3" );
                
        addOption"Default" );
                
        setDefault"3" ); 
            }   
            
        aFPArray[x] = new FunctionParameter"vdebug"FunctionParameter.BOOLEAN); 
            
        withaFPArray[x++] ) { 
                
        setName"Enable debug to Formula Ouput" ); 
                
        setDefaultfalse ); 
            }   
        }
        var 
        barCtTSeriesT;
        var 
        xIdx;
        var 
        vSymbol;
        var 
        xObj = new Object();
        var 
        CorrectionLimiter 0;
        var 
        vAdjustment 0;
        var 
        vTemp1;
        var 
        Flag 0;

        function 
        main(Symbol,Interval,vdebug){
            var 
        vTemp2,nState;
            
            if(
        getBarState() == BARSTATE_ALLBARS){
                
        setCursorLabelName("Tmp1",0);
                
        setCursorLabelName("Tmp3",1);
                
        setCursorLabelName("xIdx",2);
                if(
        Symbol == nullSymbol getSymbol();
                if(
        Interval == "Default" || Interval == nullInterval getInterval();
                
        vSymbol Symbol+","+Interval;
                
        series1 efsInternal("fInvBarCnt"vSymbol);
                
        barCtTSeriesT getSeries(series10);
                
        xIdx getSeries(series11);
            }
            
        vAdjustment vTemp1;
            
        vTemp1 barCtTSeriesT.getValue(0);//counts each seleted "getBarStateSymbol" external interval bar
            
        vTemp2 xIdx.getValue(0) - getCurrentBarCount();//counts the # of current interval bars in each seleted "getBarStateSymbol" bar
            
        nState getBarStateSymbol(vSymbol);//get external symbol barstate
            
        if (nState == BARSTATE_NEWBAR){
                
        xObj[vTemp1] = getCurrentBarIndex();
                if(
        vdebugdebugPrintln("55: vTemp1: "+vTemp1+", " "xObj[vTemp1]: " xObj[vTemp1]);
            }
            if(
        getCurrentBarIndex() == 0){
                if(
        getBarState() == BARSTATE_NEWBAR){
                    if(!
        CorrectionLimiter){
                        for (
        1;i<= vTemp1;i++){
                            if(
        vdebugdebugPrintln("61 Idx: " getCurrentBarIndex() + ", xObj." " = " xObj[i] );
                        }
                        
        CorrectionLimiter true;
                    }else{
                            if(
        vAdjustment != vTemp1 && Flag != 1){
                                if(
        vdebugdebugPrintln("71: "+vAdjustment+", "+vTemp1);
                                
        xObj[vTemp1] = xObj[vTemp1] + 1;
                                
        Flag 0;
                            }
                            for (
        1;i<= vTemp1;i++){
                                
        xObj[i] = xObj[i] - 1;
                                if(
        vdebugdebugPrintln("77 Idx: " getCurrentBarIndex() + ", xObj." " = " xObj[i] );
                            }
                    }
                }
            }
            if(
        vTemp2 == 0){
                
        drawLineRelative0low(0)-10000high(0)+10000PS_SOLID2Color.bluevTemp1);
                
        drawTextRelative(0,37,vTemp1,Color.black,null,
                    
        Text.VCENTER Text.RELATIVETOTOP |Text.CENTER|Text.BOLD,null,10,"Wing""L"+vTemp1);
            }

            return new Array(
        vTemp1+"",vTemp2+"");
        }
        var 
        barCtSym=0;
        var 
        CrntBarCnt 0;
        function 
        fInvBarCnt(a) { // retains constant value
            
        var barStateT,barStateSym,CrntBarIdx;
            
        barStateSym getBarStateSymbol);
            if (
        barStateSym ==  BARSTATE_NEWBAR){
                
        barCtSym += 1;
                
        CrntBarCnt getCurrentBarCount();
            }
            return new Array(
        barCtSym,CrntBarCnt);

        Wayne
        Last edited by waynecd; 11-15-2010, 12:54 AM.

        Comment

        Working...
        X