Announcement

Collapse
No announcement yet.

TimeZone Background Color

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

  • TimeZone Background Color

    I am trying to set the background color to light gray to indicate the premarket and am having no luck with the wizard. It's seems simple enough but would appreciate some help. Following is the code I came up with:

    //{{EFSWizard_Description
    //
    // This formula was generated by the Alert Wizard
    //
    //}}EFSWizard_Description


    //{{EFSWizard_Declarations
    var vLastAlert = -1;
    //}}EFSWizard_Declarations


    function preMain() {
    /**
    * This function is called only once, before any of the bars are loaded.
    * Place any study or EFS configuration commands here.
    */
    //{{EFSWizard_PreMain
    setPriceStudy(true);
    setStudyTitle("TimeZone_MST");
    //}}EFSWizard_PreMain

    }

    function main() {
    /**
    * The main() function is called once per bar on all previous bars, once per
    * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
    * in your preMain(), it is also called on every tick.
    */

    //{{EFSWizard_Expressions
    //{{EFSWizard_Expression_1
    if (
    getHour() >= 1400 &&
    getHour() <= 0700
    ) onAction1();
    //}}EFSWizard_Expression_1

    //}}EFSWizard_Expressions


    //{{EFSWizard_Return
    return null;
    //}}EFSWizard_Return

    }

    function postMain() {
    /**
    * The postMain() function is called only once, when the EFS is no longer used for
    * the current symbol (ie, symbol change, chart closing, or application shutdown).
    */
    }

    //{{EFSWizard_Actions
    //{{EFSWizard_Action_1
    function onAction1() {
    setBarBgColor(Color.RGB(192,220,192));
    vLastAlert = 1;
    }
    //}}EFSWizard_Action_1

    //}}EFSWizard_Actions

  • #2
    Re: TimeZone Background Color

    mdk
    Assuming I understood correctly what you are trying to do the condition will never be true ie the hour cannot be greater than or equal to 14 AND at the same time less than or equal to 7. To correct this replace && (ie AND) in your condition with || (ie OR)
    Also you are looking for the value of the hour to be greater than 1400 and less than 0700. These however are not the values returned by the function getHour() so to resolve this you need to either multiply getHour() by 100 or adjust the hour values in your condition. Either solution should work (see the examples enclosed below)
    Hope this helps
    Alex


    PHP Code:
    if (
    getHour() >= 14 ||
    getHour() <= 7
    onAction1(); 
    PHP Code:
    if (
    (
    getHour()*100) >= 1400 ||
    (
    getHour()*100) <= 700
    onAction1(); 

    Originally posted by mdk
    I am trying to set the background color to light gray to indicate the premarket and am having no luck with the wizard. It's seems simple enough but would appreciate some help. Following is the code I came up with:

    //{{EFSWizard_Description
    //
    // This formula was generated by the Alert Wizard
    //
    //}}EFSWizard_Description


    //{{EFSWizard_Declarations
    var vLastAlert = -1;
    //}}EFSWizard_Declarations


    function preMain() {
    /**
    * This function is called only once, before any of the bars are loaded.
    * Place any study or EFS configuration commands here.
    */
    //{{EFSWizard_PreMain
    setPriceStudy(true);
    setStudyTitle("TimeZone_MST");
    //}}EFSWizard_PreMain

    }

    function main() {
    /**
    * The main() function is called once per bar on all previous bars, once per
    * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
    * in your preMain(), it is also called on every tick.
    */

    //{{EFSWizard_Expressions
    //{{EFSWizard_Expression_1
    if (
    getHour() >= 1400 &&
    getHour() <= 0700
    ) onAction1();
    //}}EFSWizard_Expression_1

    //}}EFSWizard_Expressions


    //{{EFSWizard_Return
    return null;
    //}}EFSWizard_Return

    }

    function postMain() {
    /**
    * The postMain() function is called only once, when the EFS is no longer used for
    * the current symbol (ie, symbol change, chart closing, or application shutdown).
    */
    }

    //{{EFSWizard_Actions
    //{{EFSWizard_Action_1
    function onAction1() {
    setBarBgColor(Color.RGB(192,220,192));
    vLastAlert = 1;
    }
    //}}EFSWizard_Action_1

    //}}EFSWizard_Actions

    Comment


    • #3
      This gets me closer, thanks Alex. However, look at the image. How can I get the background color to be in the background instead of on top of the price bars?
      Attached Files

      Comment


      • #4
        mdk
        The issue you are seeing is due to a bug in version 10 that should be fixed in one of the next releases
        Alex


        Originally posted by mdk
        This gets me closer, thanks Alex. However, look at the image. How can I get the background color to be in the background instead of on top of the price bars?

        Comment


        • #5
          How can the "setBarBgColor" (in the below efs be extended (also appear) behind (i.e) a Stochastic indicator at the bottom (or top) of the chart?

          & BTW, yes in the very latest v10.1 the BgColor appears behind the Bars.

          Comment


          • #6
            RainerAustralia
            An efs will only paint the background of the pane in which it is running. You will need to add the required code logic to each study in which you want the background painted
            Alex


            Originally posted by RainerAustralia
            How can the "setBarBgColor" (in the below efs be extended (also appear) behind (i.e) a Stochastic indicator at the bottom (or top) of the chart?

            & BTW, yes in the very latest v10.1 the BgColor appears behind the Bars.

            Comment

            Working...
            X