Announcement

Collapse
No announcement yet.

Creating Array of Highs/Lows of X minute bars

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

  • bmatheny
    replied
    Two separate questions here...

    First, you can pull the high/low data into arrays using the call of price function

    var last10highs = high(0, -10, "INTC, 5");
    var last10lows = low(0, -10, "INTC, 5");

    If you require something more than that, you'll have to write a custom script to pull the data from the chart or from another data source. I don't quite understand how you want to pull the data (in what format/structure/interval) for your use in an array? If you could provide more details, I'm sure I could help?

    Second question:

    Use the Alert functions to generate a pop-up or play a sound.


    Alert.email( sText, [ sSubject ] )

    • sText: Text to display in the email
    • sSubject: Optional. Text to print on Subject line of email.
    Alert.addToList( sSymbol, sDescription, nFG, nBG )

    • sSymbol: Symbol to add to alert list
    • sDescription: Text description you want to add
    • nFG: Foreground color value
    • nBG: Background color value
    Alert.email( sText, [ sSubject ] )

    • sText: Text to display in the email
    • sSubject: Optional. Text to print on Subject line of email.


    Leave a comment:


  • peterbritto
    replied
    Hi Alex, How can I add a popup alert and play a sound every time price crosses above or below the vHigh or vLow?

    Leave a comment:


  • waynecd
    started a topic Creating Array of Highs/Lows of X minute bars

    Creating Array of Highs/Lows of X minute bars

    I would like to create an array of the highs and lows of every X number of minutes, say every 15 minute bar starting at 9:30 EST and ending at 16:30 EST.

    A search gave me two possible candidates to modify (see below).

    Problem: my modifications haven’t worked so far.
    If anyone knows of an EFS that already does this or can tell me which of the attached (or any other) EFS would give me the best results I would really appreciate it.

    hilo_firstxminutes2.efs
    PHP Code:
    /*********************************************************
    Alexis C. Montenegro © June 2005                          
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a 
    description of any changes you make.                      
    **********************************************************/

    var fpArray = new Array();

    function 
    preMain() {

        
    setPriceStudy(true);
        
    setStudyTitle("HiLo_firstXminutes");
        
    setCursorLabelName("High"0);
        
    setCursorLabelName("Low"1);
        
    setPlotType(PLOTTYPE_FLATLINES,0);
        
    setPlotType(PLOTTYPE_FLATLINES,1);
        
    setDefaultBarFgColor(Color.blue,0);
        
    setDefaultBarFgColor(Color.red,1);
        
        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("xStart"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Start Time");
            
    setLowerLimit(0);        
            
    setDefault(930);
        }
        
    fpArray[x] = new FunctionParameter("xEnd"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("End Time");
            
    setLowerLimit(0);        
            
    setDefault(1030);
        }
        
    fpArray[x] = new FunctionParameter("xInterval"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Ext Interval Used");
            
    setLowerLimit(1);        
            
    setDefault(5);
        }
        
    fpArray[x] = new FunctionParameter("xDisplay"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    setName("Display");
            
    addOption("Show");
            
    addOption("Hide");
            
    setDefault("Show");
        }
    }

    var 
    bInit false;
    var 
    xRange null;

    function 
    main(xStart,xEnd,xInterval,xDisplay) {

        if(
    bInit==false){
            
    xRange efsInternal("calcOR",xStart,xEnd,xDisplay,inv(xInterval));
            
    bInit=true;
        }

        return new Array(
    getSeries(xRange,0),getSeries(xRange,1));
    }


    var 
    vFlag true;
    var 
    vFlag2 true
    var vHigh null;
    var 
    vLow null;
    var 
    vClose null;
    var 
    vDay1 null;
    var 
    vDay2 null;

    function 
    calcOR(start,end,display,source){

        if (
    getBarState() == BARSTATE_NEWBAR) {
            if (
    vDay1 == null) {
                
    vDay2 getDay(0);
            } else {
                
    vDay2 vDay1;
            }
            
    vDay1 getDay(0);
            if (
    vDay1 != vDay2) {
                
    vHigh null;
                
    vLow null;
                
    vFlag true;
                
    vFlag2 false;
            }
            var 
    vHour1 = (getHour()*100)+getMinute();
            if(
    vHour1 >= start){
                
    vFlag2=true;
            }
            var 
    vHour = (getHour()*100)+getMinute();
            if (
    vHour >= end) {
                
    vFlag false;
                
    vFlag2=false;
            }
        }

        if (
    vFlag == true&&vFlag2==true) {
            if (
    vHigh == null) {
                
    vHigh high(0);
            }
            if (
    vLow == null) {
                
    vLow low(0);
            }
            
    vHigh Math.max(high(0), vHigh);
            
    vLow Math.min(low(0), vLow);
        }
        
        if(
    display=="Hide"){
            if(
    vFlag==false&&vHigh!=null&&vLow!=null){
                var 
    vHigh2 vHigh;
                var 
    vLow2 vLow;
            }
        }else if(
    display=="Show"){
            var 
    vHigh2 vHigh;
            var 
    vLow2 vLow;
        }

        return new Array(
    vHigh2,vLow2);

    session_hilo.efs
    PHP Code:
    /*********************************************************
    Alexis C. Montenegro © March 2005                         
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a 
    description of any changes you make.                      
    **********************************************************/
    /*[url]http://forum.esignalcentral.com/showthread.php?threadid=12856&perpage=15&pagenumber=5[/url]
    The attached efs is a variation of the one first posted here. 
    As in the original script this efs computes the daily High and Low using only the intraday data plotted in the chart. 
    The main difference is that this script will calculate the High and Low over the entire 24 hour period beginning from the 
    session's start time which can be modified in Edit Studies (set to 16:30 by default). 
    Another difference is that the plots of the session's High and Low can be back adjusted across all the historical bars 
    within the session (by default the script is set to display non back adjusted plots).
    Lastly this efs can be used also on issues that do not trade overnight (however if you do want to plot the High and Low 
    of only the overnight session then you need to use the original script.)
    Other user defined parameters include the options to color the plots and to display/hide the parameters in the study's title.
    Note that this efs is intended for use only with intraday data.
    Alex


    */
    var fpArray = new Array();

    function 
    preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Session HiLo (chart data)");
        
    // High
        
    setDefaultBarStyle(PS_SOLID0);
        
    setPlotType(PLOTTYPE_FLATLINES,0)
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarThickness(20);
        
    // Low
        
    setDefaultBarStyle(PS_SOLID1);
        
    setPlotType(PLOTTYPE_FLATLINES,1)
        
    setDefaultBarFgColor(Color.red1);
        
    setDefaultBarThickness(21);
        
        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("SessionStartTime"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Session Start Time");
            
    setDefault(930);
        }
        
    fpArray[x] = new FunctionParameter("Adjust"FunctionParameter.BOOLEAN);
        
    with(fpArray[x++]){
            
    setName("Back adjust Hi-Lo");
            
    setDefault(false);
        }
        
    fpArray[x] = new FunctionParameter("ColorHi"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
            
    setName("Color High");
            
    setDefault(Color.blue);
        }
        
    fpArray[x] = new FunctionParameter("ColorLo"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
            
    setName("Color Low");
            
    setDefault(Color.red);
        }
        
    fpArray[x] = new FunctionParameter("Params"FunctionParameter.BOOLEAN);
        
    with(fpArray[x++]){
            
    setName("Show Parameters");
            
    setDefault(false);
        }    
    }

    var 
    bInit false;
    var 
    vHigh  null;
    var 
    vLow   null;
    var 
    bDone   false;
    var 
    vCounter 0;
    var 
    vStart 0;

    function 
    main(SessionStartTime,Adjust,ColorHi,ColorLo,Params) {

        if(
    isDWM()) return;

        if(
    bInit == false){
            
    setDefaultBarFgColor(ColorHi,0);
            
    setDefaultBarFgColor(ColorLo,1);
            
    setShowTitleParameters(eval(Params));
            
    bInit true;
        }
        
        if(
    getBarState()==BARSTATE_NEWBAR&&day(0)!=day(-1)){
            
    bDone false;
            
    vCounter++;
        }
        
        if(
    vCounter<1) return;
     
        if(
    getBarState()==BARSTATE_NEWBAR&&(hour(0)*100)+minute(0)>=SessionStartTime&&bDone==false){
            
    vHigh  high(0);
            
    vLow   low(0);
            
    vStart getCurrentBarCount();
            
    bDone  true;
        }
        
        if(
    vHigh==null||vLow==null) return;
        
        
    vHigh Math.max(high(0), vHigh);
        
    vLow Math.min(low(0), vLow);
        
        if(
    Adjust==true){
            for (var 
    i=0i<=(getCurrentBarCount()-vStart); i++){
                
    setBar(Bar.Value,-i,0,vHigh);
                
    setBar(Bar.Value,-i,1,vLow);
            }
        }

        return new Array(
    vHigh,vLow);

Working...
X