Announcement

Collapse
No announcement yet.

setBarBgColor on Previous High/Low

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

  • setBarBgColor on Previous High/Low

    Sorry if this has been done somewhere...I'm searching for this right now in the past messages. But, what I am trying to do is create an EFS that colors the bar background green when the current bar is equal to or greater than the previous days high, or red when the current bar is equal to or less than the previous days low. If the current price is inbetween the previous high and low, then it would just leave the background as the default chart background. Any help would be appreciated.

    Thanks,

    cas

  • #2
    cas
    In your script you will need to specify what you mean with "current bar is equal to or greater/lower..." in other words is it the Close or the High/Low of the current bar that need to be higher/lower than the prior day's High/Low?
    Anyhow the example below shows you how you would set up the conditions assuming that by "current bar" you mean the Close. Replace close(0) with high(0) or low(0) where necessary.
    For information on the inv() function I used in the example see the EFS2 Function Reference-> Series Functions in the EFS KnowledgeBase
    Alex



    Comment


    • #3
      Thanks Alex...with that input I was able to use the Wizard and generate an EFS that works great.

      Cas



      //{{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("BackGround");
      //}}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 (
      close(0) >= high(-1, inv("d"))
      ) onAction1()
      //}}EFSWizard_Expression_1

      //{{EFSWizard_Expression_2
      else if (
      close(0) <= low(-1, inv("d"))
      ) onAction2();
      //}}EFSWizard_Expression_2

      //}}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,255,160));
      vLastAlert = 1;
      }
      //}}EFSWizard_Action_1

      //{{EFSWizard_Action_2
      function onAction2() {
      setBarBgColor(Color.RGB(255,160,160));
      vLastAlert = 2;
      }
      //}}EFSWizard_Action_2

      //}}EFSWizard_Actions

      Comment

      Working...
      X