Announcement

Collapse
No announcement yet.

5 min high & low every min in a 5 min study

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

  • 5 min high & low every min in a 5 min study

    I want to know the High & Low over the past 5 min every min in a real time 5 min study. To put it another way, I want to do a 5 min study every min.

    I was thinking of using an array of 5 for the high & low and every min push the high & low for the last min on it. Then loop thorugh it to find the high & low over the last 5 min every min.

    I also thought I could use a series somehow to do this. I found information on the different functions in a series but no real doc on putting it all together or any examples of what I want to do. I know it is their someplace, but I could not find it. Can someone point me to it?

    I also saw something on having multiple time studies in one study. Maybe could do a 1 min study and reference the last 5 bars with in the 5 min study?

    Any thoughts on the best way to do this?

    Thanks

  • #2
    windswepttom
    Assuming I understood correctly what you are trying to accomplish which is to calculate the 5 minute High and Low while plotting a 1 minute chart then there are several ways you can do that.
    The simplest one is to use the inv() function which allows you to base a price series or study on an interval that is different from the one being charted (see the link for the required syntax)
    Enclosed below is a very basic example of a script that will return the 5 minute High and Low using the inv() function. A fully adjustable version of this script is available in this post.
    Alex

    PHP Code:
    function preMain(){
        
    setPriceStudy(true);
        
    setDefaultBarFgColor(Color.blue,0);
        
    setDefaultBarFgColor(Color.red,1);
        
    setCursorLabelName("High",0);
        
    setCursorLabelName("Low",1);
    }

    function 
    main(){

        var 
    xHigh high(inv(5));
        var 
    xLow  low(inv(5));
        
        return new Array (
    xHigh,xLow);

    Comment


    • #3
      Thanks Alexis for your input, but
      I want to plot a 5 min chart and in real time and I want to get the high & low for the last 5 min every min. So say I have a 5 min chart that printed a new bar at 10:05. Then at 10:06 I want to know the high and low between 10:01 and 10:06 and then at 10:07 I want the high and low between 10:02 and 10:07 and so on.

      Comment


      • #4
        windswepttom
        If you want to retrieve the High and Low of a specific bar of a lower interval then create a price series based on that interval eg
        var xHigh = high(inv(1));
        var xLow = low(inv(1));

        at which point you can retrieve the values of the individual 1 minute bars by using the getValue() method and specifying a bar index eg
        var nHigh_1 = xHigh.getValue(-1);//High of the prior 1 minute
        var nLow_2 = xLow.getValue(-2);//Low of 2 bars ago of the 1 min chart

        If instead you want to calculate the highest and lowest values based on the last five 1 minute bars then replace
        var xHigh = high(inv(1));
        var xLow = low(inv(1));

        with
        var xHigh = upperDonchian(5,inv(1));
        var xLow = lowerDonchian(5,inv(1));

        and return the following to the chart
        return new Array (xHigh.getValue(0), xLow.getValue(0));
        Note that on historical bars the plots will obviously match the High and Low of the 5 minute bars but on the current bar you will get the highest and lowest values of the High and Low based on the last five 1 minute bars.
        Enclosed below is a basic script that uses the latter example
        Alex

        PHP Code:
        function preMain(){
            
        setPriceStudy(true);
            
        setPlotType(PLOTTYPE_SQUAREWAVE,0);
            
        setPlotType(PLOTTYPE_SQUAREWAVE,1);
            
        setDefaultBarFgColor(Color.blue,0);
            
        setDefaultBarFgColor(Color.red,1);
            
        setCursorLabelName("High",0);
            
        setCursorLabelName("Low",1);
        }

        var 
        xHigh null;
        var 
        xLow  null;

        function 
        main(){

            if(
        xHigh==nullxHigh upperDonchian(5,inv(1));
            if(
        xLow==null)  xLow  lowerDonchian(5,inv(1));

            return new Array (
        xHigh.getValue(0), xLow.getValue(0));

        Comment


        • #5
          Alexis, Thank you very much.
          Just what I was looking for.

          Comment


          • #6
            windswepttom
            You are most welcome
            Alex

            Comment

            Working...
            X