Announcement

Collapse
No announcement yet.

Scaling problem

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

  • Scaling problem

    Hi. Is there a function or a work-a-round anyone is aware of that can tell how many bars are currently visible in a given chart, as opposed to how many bars are actually loaded? I have several computationally intense studies which require a flexible type of restriction to conserve CPU consumption. As a result they need to be periodically rescaled from within the study rather than by the regular esignal scaling. I’m now doing that by defining a global that tells these studies I am want to look at say 100 bars and the studies respond by scaling their indicator panes to the highest high and lowest low of the last 100 bars. But it’s cumbersome manually adjusting the global when I want a different temporal perspective. It’d be great if I could just expand or compress the number of bars in the chart in the standard way and have the studies somehow recognize the new number of visible bars and adjust their scale accordingly. Does anyone have an idea how this might be done? Thanks in advance.

    Mike
    Last edited by mikejhelms; 08-18-2008, 06:28 PM.

  • #2
    Hello Mike,

    The functionality you are describing does not exist in EFS.

    Are you using a formula parameter through Edit Studies to change your global variable or are you doing this manually through the EFS Editor? If not, I would suggest setting this up using the FunctionParameter Object so you can change this parameter more easily. A change to Edit Studies also reloads the formula for you.
    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
      Yeah, I'm already using the FunctionParameter Object but it's still a drag. No big deal though. Thanks for your response.

      Mike

      Comment


      • #4
        One work-a-round that seems to do pretty well is to have a small separate study to create a few buttons which can set a single global to various values. Since this program is not returning any values its CPU consumption is minimal. The global is picked up by the program whose output is to be rescaled which then compares it to the previous value of the global. If it detects a change, that is that you've clicked on one of the buttons, it reloads itself using reloadEFS(). It then uses the global to rescale using a loop to check the lowest and highest values back x number of bars. The x being the broadcasted global. It can also use the global to restrict the look-back period to conserve CPU with a statement like “if(getCurrentBarIndex() < -x) return;” immediately after “function main()”. Since the global broadcasting study can be put on the same chart below the study that requires periodic rescaling, the buttons are conveniently located.

        Mike

        Comment


        • #5
          Hi Mike,

          If already developed, is there any way you might share a prototype efs/code?

          Thanks,

          Wayne

          Comment


          • #6
            Sure. Below is the Button Rescaling program. Some of my returned values are drawn using “drawLineRelative()” so I set this version up as a separate study because when I tried incorporating it into the program requiring periodic rescaling either my drawn returned values overwrote the buttons or vice versa. But I suppose if none of your returned values are drawn, the Button Rescaling program could be incorporated into the program that requires rescaling. As you can see I’m using three buttons which set the global value “BackG” to either -50, -100 or -200. It also changes the displayed study title to indicate how far back it’s scaling. Below this program are the code snippets I’ve inserted into the study which requires periodic rescaling.

            Button Rescaling Program:

            var binit = false;
            var bButtons = false;

            function preMain() {
            setPriceStudy(false);
            setStudyTitle("Button Rescaling");
            }

            function main() {

            if(getCurrentBarIndex() < -200) return;

            if (bButtons == false ) {
            drawButtons();
            bButtons = true;
            }

            if(binit == false){
            setGlobalValue("BackG", -200);
            binit = true;
            }

            return null;
            }

            function drawButtons() {

            drawTextPixel(240, 5, " 50 "+"@URL=EFS:fifty", null, null,
            Text.BUTTON|Text.RELATIVETOLEFT|Text.RELATIVETOBOT TOM|Text.CENTER,
            null, 10, "fifty");

            drawTextPixel(270, 5, " 100 "+"@URL=EFS:hundred", null, null,
            Text.BUTTON|Text.RELATIVETOLEFT|Text.RELATIVETOBOT TOM|Text.CENTER,
            null, 10, "hundred");

            drawTextPixel(310, 5, " 200 "+"@URL=EFS:twohundred", null, null,
            Text.BUTTON|Text.RELATIVETOLEFT|Text.RELATIVETOBOT TOM|Text.CENTER,
            null, 10, "twohundred");
            }

            function fifty() {
            setGlobalValue("BackG", -50);
            setStudyTitle("Button Rescaling 50");
            }

            function hundred() {
            setGlobalValue("BackG", -100);
            setStudyTitle(“Button Rescaling 100");
            }

            function twohundred() {
            setGlobalValue("BackG", -200);
            setStudyTitle("Button Rescaling 200");
            }

            **************************************************


            Here are the two code snippets I’ve inserted into the study which requires periodic rescaling. The first goes immediately after “function main()” and retrieves the global scaling value broadcasted by the button program, compares it to its previous value and if it the two are found to be different, that is that you’ve clicked on one of the buttons, reloads the program with either 50, 100 or 200 bars depending on which button you clicked.

            var Back = -200;
            var BackPrev = -200;
            var Scaler = 200;

            function main() {

            BackPrev = Back;

            Back = getGlobalValue("BackG");

            if(BackPrev != Back){
            BackPrev = Back;
            reloadEFS();
            }

            if(getCurrentBarIndex() < Back) return;

            Below is the second snippet I put in after all the values to be returned have been calculated but before the return statement. In my particular program I draw returnedvalue1 which is a value not a series and because I only display its value for the current bar I include it in the Math.min and Math.max statements but don’t have to check its previous values (-i) to determine the lowest low (LL) and highest high (HH). I then tack on and subtract half a point to HH and LL respectively and reset the setStudyMin() and setStudyMax(). I’ve only been using this for a couple of days but so far it seems to be working pretty well.

            Mike

            if (getBarState() == BARSTATE_NEWBAR) {

            Scaler = Back * -1;

            LL = 10000;
            for(i = 0; i < Scaler; i++) {
            LL = Math.min(LL, returnedValue, returnedSeries(-i), low(-i));
            }
            setStudyMin(LL - .50);

            HH = 0;
            for(i = 0; i < Scaler; i++) {
            HH = Math.max(HH, returnedValue, returnedSeries(-i) , high(-i));
            }
            setStudyMax(HH + .50);
            }
            Attached Files

            Comment

            Working...
            X