Announcement

Collapse
No announcement yet.

Current Bar Wierdness

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

  • Current Bar Wierdness

    I am new to writing code in JavaScript. On my first efs studies, the lines plot correctly, except for the current bar. They are essentially exp. moving averages. As the ticks accumulate on the current bar the line moves up into the current bar's value.

    How can I prevent this? Thanks, Ron

    Here is the calculation portion of the code:

    function main() {

    //Check for initial null values
    if (nn == null) {

    nn = 1;
    Osc1_1=(high(0)+low(0))/2
    Osc2_1=(high(0)+low(0))/2
    Osc3_1=(high(0)+low(0))/2
    Osc3_2=(high(0)+low(0))/2
    Osc3_3=(high(0)+low(0))/2
    Osc3_4=(high(0)+low(0))/2
    Osc4_1=(high(0)+low(0))/2
    Osc4_2=(high(0)+low(0))/2
    Osc4_3=(high(0)+low(0))/2
    Osc4_4=(high(0)+low(0))/2
    }


    // If we are past the first bar, store away current osc values as prev values, calc new osc values

    if (nn>=1){

    Osc1=(0.53*Osc1_1)+(0.47*close(0));
    Osc2=(0.53*Osc2_1)+(0.47*Osc1);
    Osc1_1=Osc1;
    Osc2_1=Osc2;



    }

    nn++

    return (Osc2);

    }

  • #2
    your issue is

    with historical (past bar data) vs. realtime (tick-by-tick) data...

    What you need to do is create two routines in your code..

    the first handles the past bar data (just as you have done now).

    the second handles the RT data and needs to inlcude a funtion to test for a new bar, then run your calcs on the previous bars data and continue like this.

    here is a simple example..

    PHP Code:

    var nLastRawTime 0;
    var 
    BLBarOffset 0;

      var 
    vHour;
      var 
    vMin;
      var 
    vSec;
      var 
    vDay;
      var 
    vMonth;

    function 
    main() {


      var 
    vTime = new Date();
    //---------------------------------------------------
    //  Get Time Variables 
      
    vTime getValue("Time"0);
      
    vHour vTime.getHours();
      
    vMin vTime.getMinutes();
      
    vSec vTime.getSeconds();
      
    vDay vTime.getDate();
      
    vMonth vTime.getMonth() +1;

    if (
    getCurrentbarIndex() != 0) {
      
    // past bars...
    ..  do your stuff here

    }
    if (
    getCurrentbarIndex() == 0) {
      
    // RT ticks...
      //-------------------------------------
      //  check for new day
     
    if (getValue("rawtime"0) != nLastRawTime) {
         
    nLastRawTime getValue("rawtime"0);
         
    BLBarOffset += 1;


    ..  do 
    your stuff here

      
    // end if new bar

    }




    Brad Matheny
    eSignal Solution Provider since 2000

    Comment

    Working...
    X