Announcement

Collapse
No announcement yet.

study only works properly when "refreshed"

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

  • study only works properly when "refreshed"

    My study is suppose to paint a bar red if something specific happens by the end of that bar.

    It works perfectly when I start the study or refresh the study.
    However if the chart remains open and DURING the time frame of that bar the bar gets painted red if at the end of the time frame of that bar it should no longer be red it remains the color red.

    Any suggestions on what I am missing ?
    Thank you

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("MARC");
    setShowCursorLabel(false);
    }

    var vColor = null;

    function main() {
    if (getBarState() == BARSTATE_NEWBAR)
    vColor = null;

    var c = close();
    var c1 = close(-1);
    var o = open();
    var h = high();
    var h1 = high(-1);
    var h2 = high(-2);
    var h3 = high(-3);
    var h4 = high(-4);
    var h5 = high(-5);
    var h6 = high(-6);
    var h7 = high(-7);
    var h8 = high(-8);
    var h9 = high(-9);
    var h10 = high(-10);
    var l = low();
    var l1 = low(-1);
    var l2 = low(-2);
    var l3 = low(-3);
    var l4 = low(-4);
    var l5 = low(-5);
    var l6 = low(-6);
    var l7 = low(-7);
    var l8 = low(-8);
    var l9 = low(-9);
    var l10 = low(-10);

    if (c == null || c1 == null)
    return;

    if (c >= c1 && l <= l1 && l <= l2 && l <= l3 && l <= l4 && l <= l5 && l <= l6 && l <= l7 && l <= l8 && l <= l9 && l <= l10)
    vColor = Color.red;
    if (c <= c1 && h >= h1 && h >= h2 && h >= h3 && h >= h4 && h >= h5 && h >= h6 && h >= h7 && h >= h8 && h >= h9 && h >= h10)
    vColor = Color.red;

    if (vColor != null)
    setPriceBarColor(vColor);
    setDefaultPriceBarColor( Color.black );
    return;
    }

  • #2
    mjforex
    As I indicated in my reply to you in this thread you need to add setColorPriceBars(true) and setDefaultPriceBarColor(Color.your_color) in the preMain function whenever you are painting the price bars.
    After you have made the change I suggested remove the setDefaultPriceBarColor(Color.black) that you have at the end of your main function and remove also the following two lines of code that are not required
    if (getBarState() == BARSTATE_NEWBAR)
    vColor = null;

    Once you make these changes the formula should work correctly
    Alex


    Originally posted by mjforex
    My study is suppose to paint a bar red if something specific happens by the end of that bar.

    It works perfectly when I start the study or refresh the study.
    However if the chart remains open and DURING the time frame of that bar the bar gets painted red if at the end of the time frame of that bar it should no longer be red it remains the color red.

    Any suggestions on what I am missing ?
    Thank you

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("MARC");
    setShowCursorLabel(false);
    }

    var vColor = null;

    function main() {
    if (getBarState() == BARSTATE_NEWBAR)
    vColor = null;

    var c = close();
    var c1 = close(-1);
    var o = open();
    var h = high();
    var h1 = high(-1);
    var h2 = high(-2);
    var h3 = high(-3);
    var h4 = high(-4);
    var h5 = high(-5);
    var h6 = high(-6);
    var h7 = high(-7);
    var h8 = high(-8);
    var h9 = high(-9);
    var h10 = high(-10);
    var l = low();
    var l1 = low(-1);
    var l2 = low(-2);
    var l3 = low(-3);
    var l4 = low(-4);
    var l5 = low(-5);
    var l6 = low(-6);
    var l7 = low(-7);
    var l8 = low(-8);
    var l9 = low(-9);
    var l10 = low(-10);

    if (c == null || c1 == null)
    return;

    if (c >= c1 && l <= l1 && l <= l2 && l <= l3 && l <= l4 && l <= l5 && l <= l6 && l <= l7 && l <= l8 && l <= l9 && l <= l10)
    vColor = Color.red;
    if (c <= c1 && h >= h1 && h >= h2 && h >= h3 && h >= h4 && h >= h5 && h >= h6 && h >= h7 && h >= h8 && h >= h9 && h >= h10)
    vColor = Color.red;

    if (vColor != null)
    setPriceBarColor(vColor);
    setDefaultPriceBarColor( Color.black );
    return;
    }

    Comment

    Working...
    X