Announcement

Collapse
No announcement yet.

efsInternal and/or getValue() help

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

  • efsInternal and/or getValue() help

    I am writing a script that needs to update the returned values as new bars come in.

    Here is an example EFS to demonstrate and reproduce the problem I am having.

    It's a simple EFS that returns the number of bars away it is from the current bar. When the script is first loaded, all values are correct. Once a new bar comes in, all values are now wrong (off by 1). So, the bar that was 5 bars away from the current bar should now be "6" when a new bar comes in, and so on.

    Should I use efsInternal() in this situation? How do I make them auto-update?

    Once I get that working as expected, I will then need to handle having drawText() labels also auto-update as new bars come in. (not in the script below)

    Any help is greatly appreciated!

    PHP Code:
    function preMain()
    {
        
    setStudyTitle("Bars From Current");
        
    setCursorLabelName("BFC"0);

        
    setPriceStudy(true);
        
    setShowCursorLabeltrue );
        
    setShowTitleParameters(false);
    }

    var 
    bInit false;
    var 
    studyBarsFromCurrent null;

    function 
    main()
    {
        if(!
    bInit)
        {
            
    studyPivotSwings efsInternal("BarsFromCurrent");
            
    bInit true;
        }

        return 
    studyPivotSwings.getValue(0);
    }


    function 
    BarsFromCurrent()
    {
        var 
    FoundCurBar false;
        var 
    BarCount 0;

        
    // Loop until we reach the current bar
        
    do
        {
            
    FoundCurBar = (close(BarCount) == null);

            if (!
    FoundCurBar)
                
    BarCount++;
        }
        while(!
    FoundCurBar)

        return 
    BarCount-1;    // subtract 1 to force 0-based

    eSignal File Share: http://share.esignal.com/groupcontents.jsp?groupid=1130

  • #2
    Perhaps each bar I need to reload the script? This seems terribly inefficient, but perhaps I don't have a choice.
    eSignal File Share: http://share.esignal.com/groupcontents.jsp?groupid=1130

    Comment


    • #3
      Hi neoikon,

      Not sure what you need here, but check out efs's entitled "barState Play" and "barCount of external Interval Example" in my fileShare, perhaps they will help.

      Originally posted by neoikon
      Perhaps each bar I need to reload the script? This seems terribly inefficient, but perhaps I don't have a choice.

      Comment


      • #4
        Thanks for the reply. The example EFS I post is nothing like what I am working on, but merely demonstrates the behavior I am looking for. Instead of just updating an offset, there is a calculation and logic that is done on each bar.

        My feeling is I just need to re-run the whole logic on all bars each bar.

        Thanks for the link, though. Perhaps that will help me with another problem, when the chart is loading new bars (when the user drags the chart to the right, causing new bars to load (not the initial load)), being able to tell the script to not do anything and wait. Playing with various getBarState() and getCurrentBarIndex() combinations has left me empty.
        eSignal File Share: http://share.esignal.com/groupcontents.jsp?groupid=1130

        Comment


        • #5
          You are welcome.

          I wrote the efs's when I was trying to figure out the inter-relationships and the sequence of how the external and different interval data was loaded. I posted these initial efs's for demonstration hoping they may help others.

          Once I figured out the sequences are repeatable regardless of how the chart was updated, I was able to move on and develop more substantive code -w- logic as you seem to be trying.

          As you noted, reloading the chart every bar is impractical. From personal experience, the added complexity shouldn't be necessary.

          Good luck on your coding, and hope you are not on "empty" for long.

          Steve

          Originally posted by neoikon
          Thanks for the reply. The example EFS I post is nothing like what I am working on, but merely demonstrates the behavior I am looking for. Instead of just updating an offset, there is a calculation and logic that is done on each bar.

          My feeling is I just need to re-run the whole logic on all bars each bar.

          Thanks for the link, though. Perhaps that will help me with another problem, when the chart is loading new bars (when the user drags the chart to the right, causing new bars to load (not the initial load)), being able to tell the script to not do anything and wait. Playing with various getBarState() and getCurrentBarIndex() combinations has left me empty.

          Comment

          Working...
          X