Announcement

Collapse
No announcement yet.

How do I prevent EFS's from using data older than current day for indicators ?

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

  • How do I prevent EFS's from using data older than current day for indicators ?

    What I'd like to do:

    *) Assume I have an SMA (e.g 50 periods)
    *) will plot/calculate on an intraday chart

    Now, If I load the efs with the SMA into a lets say 3min chart the advanced chart retrieves alot of past data. The last 50 values of yesterday are used for calculating the first value of the current day (1st bar). This is what I want to prevent - I want my indicators to start from scratch every new day i.e. the MA would not plot calculate until 50 bars in the current session have arrived.

    This should happen for all my indicators (different period-lenghts). What is the best way to achieve this ?

    Thanx,
    EZ-T

  • #2
    I put together a working efs with the functionality you desire (I believe) with one 50 bar delay and another 25 bar delay.

    You will need to copy those sections identified to your code, then declare an object for each variable you want delayed. While somewhat complex, there are only 5 lines you need to modify to suit your needs surrounded by:

    // @@@@@@@@@@@modify lines only@@@@@@@@@

    Then include those lines as commented / delineated into your efs. If you have any problems, post your code and we can work through any issues.

    PHP Code:
    //---------------------------------------------------------
    /**************************************************
    Steve Hare © December 2004                          
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a 
    description of any changes you make.                      

    Title:  barcountdown.efs
    By:         Steve Hare
    Email:      [email][email protected][/email]
    Version:    initial release 12/04/2004

    Description:   Creates objects to allow for a countdown of a certain number of bars once the 
    day changes.  While counting down, the variable being returned to the chart is made the same 
    color as the chart background

    disclaimer: For educational purposes only! Obviously, no guarantees 
    whatsoever and use at your own risk.
    *************************************************/

    var nbars50;
    var 
    nbars25;
    var 
    CurrentDay null;
    var 
    B_init false;

    function 
    barcounter_variable_class(num,nCount,nColor1,nColor2){// (# bars delayed, return value, display color, chart bg color)
     
    this.number_of_bars num;
     
    this.zero_bar bcount.num();
     
    this.nCount nCount;
     
    this.color1 nColor1;
     
    this.color2 nColor2;
     
    this.flag =  BG;
     function 
    BG(){
      if((
    bcount.num()-this.zero_bar)>=this.number_of_bars){
       
    setBarFgColor(this.color1this.nCount);
      }
      else{
       
    setBarFgColor(this.color2this.nCount);
      }
     }
    }

    var 
    bcount;
    function 
    barcount_variable_class(){
     
    this.num=function(){return(1+getCurrentBarIndex()-getOldestBarIndex());}
    }

    function 
    delay_MA(){
     if (
    getBarState() == BARSTATE_ALLBARS) {//true once during initial load and subsequent reload
      
    bcount = new barcount_variable_class();//bcount.num()
      
    setChartBG(cBgColor);
     }
     if (
    getBarState() == BARSTATE_NEWBAR || !B_init){
      if (
    getDay(0) !=CurrentDay){
       
    CurrentDay getDay(0);
    // @@@@@@@@@@@modify lines below only@@@@@@@@@
       
    nbars50 = new barcounter_variable_class(50,0,Color.red,cBgColor);//declare one for each variable you want delayed
       
    nbars25 = new barcounter_variable_class(25,1,Color.blue,cBgColor);// (# bars delayed, return value, display color, chart bg color)
      
    }
     }
     
    nbars25.flag();
     
    nbars50.flag();
    }
    var 
    cBgColor Color.white;//chart background color change to whatever you use
    // @@@@@@@@@@@modify lines above  only@@@@@@@@@
    //-----------include within lines outside MAIN -------------------

     
     
    function preMain(){
     
    setPriceStudy(true);
     
    setShowTitleParameters(false);
     
    setStudyTitle("barcountdown");
     
    setShowCursorLabel(true);
     
    setCursorLabelName("MA50"0);
     
    setCursorLabelName("MA25"1);
     
    setDefaultBarFgColor(Color.red0);
     
    setDefaultBarFgColor(Color.blue1);
     
    setDefaultBarThickness(2,0);
     
    setDefaultBarThickness(2,1);
    }

    var 
    vMA null;

    function 
    main(){
    //-----------------------------------------------------------
    delay_MA();
    //-----------include within lines in MAIN--------------------

     
    if (vMA == nullvMA = new MAStudy(100"Close"MAStudy.SIMPLE);
     
     var 
    vX vMA.getValue(MAStudy.MA);
     if(
    vX==null||vX==0) return;

     var 
    vX1 vX+5;

     return new Array(
    vX,vX1);

    Comment


    • #3
      MANY thanks, Steve!

      I think this might be the holy grail to my problem - I'll try to implement my studies accordingly to what you have said.

      Best regards,

      EZ-T

      Comment

      Working...
      X