Announcement

Collapse
No announcement yet.

updating getGlobalValue()

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

  • updating getGlobalValue()

    Hi,

    I would like to match the changes in background color from study pane in the price study. Say MACD above MACDSig = green background & below = red.

    I have the following in the study pane efs:

    PHP Code:
        if(vMACD vMACDSig){
            
    vBgColor Color.RGB(202,241,188);
            
    setGlobalValue("gBgColor",Color.RGB(202,241,188));
        }else if(
    vMACD vMACDSig){
            
    vBgColor Color.RGB(218,212,254);
            
    setGlobalValue("gBgColor",Color.RGB(218,212,254));
        }else  {
            
    vBgColor Color.white;
            
    setGlobalValue("gBgColor",Color.white);
        } 
    and the price pane efs that gets the global variable is:

    PHP Code:
    debugClear();
    function 
    preMain(){
        
    setPriceStudy(true);
        
    setStudyTitle("BgColor2");
    }

    function 
    main(){
        var 
    vBgColor,vBgCol0,vHighest;
        
    vBgColor getGlobalValue("gBgColor");
        
    vHighest hhv(50,high());
        
    setBarBgColor(vBgColor0nullvHighest);

    But the color in the price pane stays green and never changes to red to match background colors in the study pane.

    Seems that the global variable doesn't update after the first value is passed. I've tried using the removeGlobalValue() in several places without success.

    Thanks

    wayne
    Last edited by waynecd; 02-15-2009, 12:08 AM.

  • #2
    Wayne. you are using "null" for yMin, that may stuff the call. May be worth dropping the max and min completely and testing again.
    Also, check the efs proessing order, you may be one tick behind on the chart, although that won't matter in a fast-trading market.
    Have you used debugPrint() to verify the stored and retrieved value? [specifically, determine whether the problem in the data exchange or in the colour-setting call]
    For efficiency, look at the "Default" version of this call and dedup the call, else you have to set the colour for each tick
    Last edited by Dave180; 02-15-2009, 12:21 PM.

    Comment


    • #3
      Hi,

      It updates only in real time. All historical bar background colors are the color of the background of the last bar when the chart was loaded.

      I would post an image of the chart but I don't know how. [image] doesn't work for me.

      Thanks for the suggestions Dave. I tested using all variations I could think of for setBarBgColor() unsuccessfully.

      I don't think I can accomplish this using efsExternal() since it returns a series and not a color. All my tests were unsuccessful.

      The processing order works well in the study pane.

      I also extensively used the debugPrintln().

      Regards

      wayne

      Wayne. you sre using "null" for yMin, that may stuff the call. May be worth dropping the max and mn completely and testing again.
      Also, check the efs proessing order, you may be one tick behind on the chart, although that won't matter in a fast-trading market.
      Have you used debugPrint() to verify the stored and retrieved value?
      For efficiency, look at the "Default" version of this call and dedup the call, else you have to set the colour for each tick
      Last edited by waynecd; 02-15-2009, 04:52 PM.

      Comment


      • #4
        Wayne, It's not clear from your reply whether the GlobalValue() part of yoru code is working properly and it is only the colour call that is not functioning.

        I use background colouring and it does work. Why not try changing the colour based on some other measurement - like the candle price or time or similar. Have you dropped both the min and max arguments for now? Or find some existing efs that changes the colour and works and start to modify that (eg see a klinger volume oscillator by Alexis (kvo.efs) that does partial bar colouring, but not in the price pane; or "MA Cross Over.efs" in the efs Helpers sub dir).

        I think you should be able to use efsInternal to return a series of colour values without a problem if you want to, as long as you return a numbr it won't really care what that number is.

        Here is an edited version of the MA Cross Over.efs that is a price study and uses the min/max call

        PHP Code:
        /****************************************************************************************************
        Copyright © eSignal, a division of Interactive Data Corporation. 2006. All rights reserved. 
        This sample eSignal Formula Script (EFS) may be modified and saved under a new 
        filename; however, eSignal is no longer responsible for the functionality once modified.
        eSignal reserves the right to modify and overwrite this EFS file with each new release.
        *****************************************************************************************************/

        function preMain() {
            
        setStudyTitle("MA Cross Over djt");
            
        setShowCursorLabel(false);
            
        setShowTitleParameters(true);
            
        setPriceStudy(true);
            
            var 
        fp1 = new FunctionParameter("nInputLength"FunctionParameter.NUMBER);
                
        fp1.setName("Length");
                
        fp1.setLowerLimit(1);
                
        fp1.setDefault(50);
        }

        function 
        main(nInputLength) {
            
            var 
        vValue sma(nInputLength);
            var 
        vClose close(0);
            
            if(
        vValue != null && vClose != null) {
                if(
        vClose >= vValue) {
                    
        setBarBgColor(Color.lime,0,vValue,vClose );
                } else {
                    
        setBarBgColor(Color.red,0,vClose vValue);
                }
            }
            
            return;

        and here it is using the Default version to minimise the calls
        PHP Code:
        /****************************************************************************************************
        Copyright © eSignal, a division of Interactive Data Corporation. 2006. All rights reserved. 
        This sample eSignal Formula Script (EFS) may be modified and saved under a new 
        filename; however, eSignal is no longer responsible for the functionality once modified.
        eSignal reserves the right to modify and overwrite this EFS file with each new release.
        *****************************************************************************************************/

        function preMain() {
            
        setStudyTitle("MA Cross Over djt 2");
            
        setShowCursorLabel(false);
            
        setShowTitleParameters(true);
            
        setPriceStudy(true);
            
            var 
        fp1 = new FunctionParameter("nInputLength"FunctionParameter.NUMBER);
                
        fp1.setName("Length");
                
        fp1.setLowerLimit(1);
                
        fp1.setDefault(50);
        }

        var 
        mvValue null;
        var 
        mvClose null;
        function 
        main(nInputLength) {
            
            var 
        vValue sma(nInputLength);
            var 
        vClose close(0);
            
            if(
        mvValue != vValue || mvClose != vClose) {
                
        mvValue vValue;
                
        mvClose vClose;
                if(
        vValue != null && vClose != null) {
                    if(
        vClose >= vValue) {
                        
        setDefaultBarBgColor(Color.lime,0,vValue,vClose );
                    } else {
                        
        setDefaultBarBgColor(Color.red,0,vClose vValue);
                    }
                }
            }
            
            return;

        Comment


        • #5
          Hi Dave,

          If you have a link or know how to post images to the forum I could post a chart.

          The issue is that getGlobalValue("gBgColor") used in the simple Price Pane efs only captures the real time change in color and all bars already plotted (historical bars) are all the same color (the color of the last bar plotted while loading, i.e., BARSTATE_ALLBARS).
          Wayne, It's not clear from your reply whether the GlobalValue() part of yoru code is working properly and it is only the colour call that is not functioning.
          I wasn't clear, sorry. Your scripts work well, and represent my study pane efs which also works and colors as intended. I represent this code with the following snippet:
          PHP Code:
          if(vMACD vMACDSig){
                  
          vBgColor Color.RGB(202,241,188);
                  
          setGlobalValue("gBgColor",Color.RGB(202,241,188));
              }else if(
          vMACD vMACDSig){
                  
          vBgColor Color.RGB(218,212,254);
                  
          setGlobalValue("gBgColor",Color.RGB(218,212,254));
              }else  {
                  
          vBgColor Color.white;
                  
          setGlobalValue("gBgColor",Color.white);
              } 
          But, for the sole purpose of coloring the Price Pane background the same as the study pane was colored by the above efs, I'm using a simple script with getGlobalValue("gBgColor") to capture the background color changes from the study pane script.

          wayne

          Comment


          • #6
            to uplaod an image I use the "Attach file" optin below the text entry box. But I seem to remember that it doesn't wok if you then preview and change the post, so add it just befre you post, or as a separate follow-on post.

            The historic bars won't work the way you want as the indicators as not processed synchronously with the chart pane. You will have to use efsInernal, or simply put the computational code in an efsLib and you can call it (as a subroutine) from either the price-based indicator or the indicator pane version of your indicator.

            Comment


            • #7
              Thanks Dave,

              That explains it.

              Time for me to learn how to create an efsLib.

              wayne
              Last edited by waynecd; 02-16-2009, 04:27 PM.

              Comment


              • #8
                FYI, I started using global variables to pass small arrays of objects. Most of the advanced efs developers know how to create an array of objects. I pass the array or object back and forth from efs apps.

                Another way is to pass a string (comma or otherwise delimited) within the global variable. Like "Dir, StopPrice, TargetPrice, Whatever", then I read the string and parse the data as needed.

                When developing trading systems, you can create two different global variable strings to control "end of bar" and "RT" operations between multiple efs apps.

                If you are trying to do any of this, drop me a PM with questions?
                Brad Matheny
                eSignal Solution Provider since 2000

                Comment

                Working...
                X