Announcement

Collapse
No announcement yet.

Coloring intraday price bars based on certain criteria

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

  • Coloring intraday price bars based on certain criteria

    Hello,

    I tried to use the Formula Wizard to create a study with the following criteria.

    1. First, this formula was designed to be used with a 65-minute chart during regular trading hours for equities (8:30 am - 3 pm CST).

    2. I want the price bar to be a different color if the volume of that bar is the highest volume for that time slot during the past 5 days. In other words, if the volume for the 9:35 time slot is higher than that of the 9:35 time slot for the previous 4 days, then the bar should be a different color.

    3. I also want the price bar to be a different color if the volume of that bar is higher than the volume for the first bar of that day. So if the volume for the 9:35 bar is higher than the volume for the 8:30 bar on the same day, then the 9:35 bar should be a different color.

    Unfortunately, the study doesn't work properly. It colors some of the bars but not others. I haven't figured out a pattern as to why certain bars are not being colored. I will paste the code below in hopes that someone can help me. As an aside, I'll note that I'd prefer to color the volume bars rather than the price bars, but I didn't see a way to do this.

    Thanks,
    Jason


    Here is the code generated by the Formula Wizard:

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


    //{{EFSWizard_Declarations

    var vLastAlert = -1;

    //}}EFSWizard_Declarations 2482


    function preMain() {
    //{{EFSWizard_Code_PreMain_setPriceBarColor
    setColorPriceBars(true);
    //}}EFSWizard_Code_PreMain_setPriceBarColor 3448
    /**
    * 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("Colored bars based on time of day");
    //}}EFSWizard_PreMain 9803

    }

    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() == 8 &&
    getMinute() == 30 &&
    volume() > volume(-6) &&
    volume() > volume(-12) &&
    volume() > volume(-18) &&
    volume() > volume(-24)
    ) onAction1()
    //}}EFSWizard_Expression_1 24559

    //{{EFSWizard_Expression_2
    else if (
    getHour() == 9 &&
    getMinute() == 35 &&
    volume() > volume(-6) &&
    volume() > volume(-12) &&
    volume() > volume(-18) &&
    volume() > volume(-24) &&
    volume() > volume(-1)
    ) onAction2()
    //}}EFSWizard_Expression_2 33259

    //{{EFSWizard_Expression_3
    else if (
    getHour() == 10 &&
    getMinute() == 40 &&
    volume() > volume(-6) &&
    volume() > volume(-12) &&
    volume() > volume(-18) &&
    volume() > volume(-24) &&
    volume() > volume(-2)
    ) onAction3()
    //}}EFSWizard_Expression_3 32265

    //{{EFSWizard_Expression_4
    else if (
    getHour() == 11 &&
    getMinute() == 45 &&
    volume() > volume(-6) &&
    volume() > volume(-12) &&
    volume() > volume(-18) &&
    volume() > volume(-24) &&
    volume() > volume(-3)
    ) onAction4()
    //}}EFSWizard_Expression_4 33667

    //{{EFSWizard_Expression_5
    else if (
    getHour() == 12 &&
    getMinute() == 50 &&
    volume() > volume(-6) &&
    volume() > volume(-12) &&
    volume() > volume(-18) &&
    volume() > volume(-24) &&
    volume() > volume(-4)
    ) onAction5()
    //}}EFSWizard_Expression_5 32942

    //{{EFSWizard_Expression_6
    else if (
    getHour() == 1 &&
    getMinute() == 55 &&
    volume() > volume(-6) &&
    volume() > volume(-12) &&
    volume() > volume(-18) &&
    volume() > volume(-24) &&
    volume() > volume(-5)
    ) onAction6();
    //}}EFSWizard_Expression_6 31726

    //}}EFSWizard_Expressions 265579


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

    }

    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() {
    setPriceBarColor(Color.RGB(255,0,255));
    vLastAlert = 1;
    }
    //}}EFSWizard_Action_1 11061

    //{{EFSWizard_Action_2
    function onAction2() {
    setPriceBarColor(Color.RGB(255,0,255));
    vLastAlert = 2;
    }
    //}}EFSWizard_Action_2 11228

    //{{EFSWizard_Action_3
    function onAction3() {
    setPriceBarColor(Color.RGB(255,0,255));
    vLastAlert = 3;
    }
    //}}EFSWizard_Action_3 11643

    //{{EFSWizard_Action_4
    function onAction4() {
    setPriceBarColor(Color.RGB(255,0,255));
    vLastAlert = 4;
    }
    //}}EFSWizard_Action_4 10397

    //{{EFSWizard_Action_5
    function onAction5() {
    setPriceBarColor(Color.RGB(255,0,255));
    vLastAlert = 5;
    }
    //}}EFSWizard_Action_5 11213

    //{{EFSWizard_Action_6
    function onAction6() {
    setPriceBarColor(Color.RGB(255,0,255));
    vLastAlert = 6;
    }
    //}}EFSWizard_Action_6 12260

    //}}EFSWizard_Actions 129282

  • #2
    Hello Jason,

    The time restriction needs to be set with a custom time template. Also, specify the number of days of data to load to something like 10 or 20 days.

    Your study needs to be a non-price study that returns volume data to the chart as a histogram. Use two actions to do your coloring. Use setPriceBarColor to color the price bars and setBarFgColor to color the volume bars. The formula wizard is a bit limited in what it can do. To have the formula consider multiple conditions to set the price bar color where one condition supercedes the other (#2 and #3) would require some custom editing through the editor. You also might want to add two more Sets of conditions after your volume Sets to color the price bar a default color where close(0) > open(0) and close(0) <= open(0). Otherwise, the price bars will all be the same default color where none of your volume conditions evaluate to true.
    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
      JasonK,

      Thanks for the reply. Your suggestions worked beautifully. I didn't know what kind of custom editing you were referring to, so I created two different studies. One of them colors the price bars and volume bars blue if the volume is the highest for that time slot over the past 5 days. The second study colors the price bars and volume bars blue if the volume is higher than the volume for the first bar of that day. This gets me very close to what I want, but I'd rather have it in one study instead of two. Would you mind elaborating on how I could edit it so that I could combine both of these studies into one study?

      Thanks again,
      Jason

      Comment


      • #4
        Hello Jason

        The type of logic that you need is not be possible in a single formula wizard formula. You need to take one of the formulas and add some custom modifications (manual coding) using the EFS Editor. You have multiple conditions that can evaluate to true at the same time, but with different colors. The price bars can only be painted one color at a time. Therefore, you need write some code that determines which condition will override the other. One way to do that is to evaluate all the conditions separately where the last one evaluated has the highest priority. The formula wizard creates a series of if...else statements, which won't work for you. Try something like below.

        // volume bar color
        if (least_importantVol_condition == true) {
        setBarFgColor(someColor);
        }
        if (most_importantVol_condition == true) {
        setBarFgColor(someOtherColor);
        }

        // price bar color
        if (least_importantPrice_condition == true) {
        setBarFgColor(somePriceColor);
        }
        if (most_importantPrice_condition == true) {
        setBarFgColor(someOtherPriceColor);
        }
        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

        Working...
        X