Announcement

Collapse
No announcement yet.

Plot first 15min High

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

  • Plot first 15min High

    Hi~

    I am trying to create an efs study that would plot the high of the first 15min bar.

    I am using the one below, but that one prints the high for every 15min bar. and I only want to plot the high of the first 15min bar.

    I assume the issue is with this line:
    xHigh = high(inv(15));

    Please let me know what I am doing wrong.

    Thanks,
    anarco

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("OR High 15 min");
    setCursorLabelName("TH");

    setDefaultBarStyle(PS_DASH);
    setDefaultBarFgColor(Color.red);
    setDefaultBarThickness(2);
    setPlotType(PLOTTYPE_FLATLINES);
    }

    var bInit = false;
    var xHigh = null;

    function main() {

    if(isMonthly() || isWeekly() || isDaily())
    return;

    if(bInit == false){
    xHigh = high(inv(15));
    bInit = true;
    }

    var vHigh = getSeries(xHigh);

    return (vHigh);
    }

  • #2
    The one thing to keep in mind is that main() is executed once for each bar as it's being displayed on the chart and then for each tick [during market hours].

    The way your code is structured, xHigh is initialized once when the first bar is displayed; its values are basically the highs for each 15-minute bar. bInit prevents xHigh from being set each time main() is executed. However, vHigh is [re]set each time main() is executed and it's value is always going to be the high for the current bar. Your script is no different than if your main() simply returned high(0), e.g.,

    function main()
    {
    return( high(0) );
    }

    Although want you want to do sounds fairly easy and straightforward, it's actually a bit tricky!

    What you want to do is, for the first bar of each day, determine the high for the 9:30 bar [for a 15-minute interval] and have that value be returned [by main()] for each bar for that day. When the day changes, repeat the above process. I say it's tricky because you have to do some date and time comparisons. In addition, series values do not always come in the order you expect them.

    I've attached an EFS script that will display the 15-minute high for any minute interval (I haven't been able to get it to work for a Daily interval yet). In addition, you can have it display just for the [most] current day only. Please keep in mind that since I wrote it today, Sat, while the market is closed, I don't know yet if there will be any issues during market hours. Like any script, I'm sure there will be a need to make some modifications/corrections once it's used during a trading day.

    Hope this helps...best of luck.

    David
    Attached Files
    Last edited by dlee8989; 05-11-2008, 09:28 AM.

    Comment

    Working...
    X