Announcement

Collapse
No announcement yet.

Study Reload

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

  • Study Reload

    Hi,

    I need some help with the reload of a study.

    This study, is loaded by reading a set of forecasted prices that are computed by one of our servers.

    The prices are saved on an external txt file, and access through the http object. This is working great. I've added the access to the http in a fuction, called loaddata() and saved that on a library.

    This forecasted price, is protected with a user and pass that are loaded as external variables to the efs.

    The code is as follows.

    function main(frUser, frPassword, frColor){
    if (getBarState() == BARSTATE_ALLBARS) {
    sSymbol = getSymbol(); //grab the name of the symbol being charted for later use
    nInterval = getInterval(); //grab the bar interval we are using for later use
    frUserPub = frUser;
    frPasswordPub = frPassword;
    var nData = PLLibrary.loadData(); //call loadData to load the Prediction data that corresponds to the Charted Series
    return;
    }

    if (nBarState == BARSTATE_NEWBAR) {
    var nResult = PLLibrary.Position(); //call Position to know where to start plotting.
    var Offset = MyCount;
    var PastBar = 0;
    for (var x=2; x<=Offset; x++){
    drawLineRelative(x-1-Correction,aPrediction[x-1],x-Correction,aPrediction[x] ,PS_SOLID,3,Color.grey,"plot"+x);
    }
    }

    The problem I have is that the study loads perfect on the first load, but does not update on new bar, as I think it shoudl using the nBarState == BARSTATE_NEWBAR.

    The Study looks like this.



    Any help is very weolcomed.

    Thanks,

    Dan

  • #2
    Hello Dan,

    It looks like the routine that loads the new data is inside a check for BARSTATE_ALLBARS, which will only happen when the study is first applied to the chart. Try adding to that condition a check for NEWBAR and bar index of 0 to allow the newest data to be downloaded while processing in real time.

    PHP Code:
    function main(frUserfrPasswordfrColor){ 
        var 
    nState getBarState();
        var 
    nIndex getCurrentBarIndex();
        
        if (
    nState == BARSTATE_ALLBARS || (nState == BARSTATE_NEWBAR && nIndex == 0) ) { 
            
    sSymbol getSymbol(); //grab the name of the symbol being charted for later use 
            
    nInterval getInterval(); //grab the bar interval we are using for later use 
            
    frUserPub frUser;
            
    frPasswordPub frPassword
            var 
    nData PLLibrary.loadData(); //call loadData to load the Prediction data that corresponds to the Charted Series
        
    }

        return;

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Hello JasonK,

      Thank you for your answer. I've tried it but did not work.

      This is all the code in main. What Im trying to do is chart the prediction on Load Chart, and then every 5 minutes. (Chart has to be in 5 minutes time)

      I thought that BARSTATE_NEWBAR was the even when the nowbar is printed. Is that right? If that is so, on every bar I believe the 2 conditions should be true.

      Any help is very welcomed.

      Thank you,

      Dan

      PHP Code:

      function main(frUserfrPasswordfrColor){ 
           var 
      nState getBarState();
           var 
      nIndex getCurrentBarIndex();
         
          if (
      nState == BARSTATE_ALLBARS || (nState == BARSTATE_NEWBAR && nIndex == 0) ) { 

              
      sSymbol getSymbol(); //grab the name of the symbol being charted for later use 
              
      nInterval getInterval(); //grab the bar interval we are using for later use 
              
      frUserPub frUser;
              
      frPasswordPub frPassword
              var 
      nData PLLibrary.loadData(); //call loadData to load the Prediction data that corresponds to the Charted Series
              //debugprint("Reloaded:"+nIndex); 
              
      return;
              } 

          if (
      nState == BARSTATE_NEWBAR) { 
              var 
      nResult PLLibrary.Position(); //call Position to know where to start plotting. 
              
      var Offset MyCount;
              var 
      PastBar 0
              for (var 
      x=2x<=Offsetx++){
              
      drawLineRelative(x-1-Correction,aPrediction[x-1],x-Correction,aPrediction[x] ,PS_SOLID,3,Color.grey,"plot"+x);
              
      //debugprint("Reloaded:"+nIndex); 
              

          }






      Originally posted by JasonK
      Hello Dan,

      It looks like the routine that loads the new data is inside a check for BARSTATE_ALLBARS, which will only happen when the study is first applied to the chart. Try adding to that condition a check for NEWBAR and bar index of 0 to allow the newest data to be downloaded while processing in real time.

      PHP Code:
      function main(frUserfrPasswordfrColor){ 
          var 
      nState getBarState();
          var 
      nIndex getCurrentBarIndex();
          
          if (
      nState == BARSTATE_ALLBARS || (nState == BARSTATE_NEWBAR && nIndex == 0) ) { 
              
      sSymbol getSymbol(); //grab the name of the symbol being charted for later use 
              
      nInterval getInterval(); //grab the bar interval we are using for later use 
              
      frUserPub frUser;
              
      frPasswordPub frPassword
              var 
      nData PLLibrary.loadData(); //call loadData to load the Prediction data that corresponds to the Charted Series
          
      }

          return;

      Comment


      • #4
        Dan,

        You are correct, that when NEWBAR is true on the first tick of a new bar of data. Note that this might be different value from the last full interval close (not that I think that is your issue).

        If the two conditions you talk about being true are:

        (nState == BARSTATE_NEWBAR && nIndex == 0)

        then that matches my understanding. When running in realtime this condition should be true for each new bars first tick. This will not by true for each historical bar however as nIndex will not be zero when loading old data.

        I would:

        1) Look at the formula output window and look for errors
        2) Add a few debug statements

        Also, you say that the new condition still doesn't work, but you don't tell us if the failure looks the same as what you were seeing the first time.

        Garth
        Garth

        Comment

        Working...
        X