Announcement

Collapse
No announcement yet.

Calculating 3 day H/L Question?

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

  • Calculating 3 day H/L Question?

    I've modified one of the previous day OHLC studies so that it just gets the High & Low successfully.

    The question I have is how do I get it to just return the highest high and lowest low of the last 3 days? Right now it just gets the High/Low from 3 days ago.

    Thanks,
    jphillips

    Here is the code -

    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("3DayH-L");
        
    setCursorLabelName("3D-H"0); // High
        
    setCursorLabelName("3D-L"1); // Low

        
    setDefaultBarStyle(PS_SOLID0); // High  
        
    setDefaultBarStyle(PS_SOLID1); // Low   

        
    setDefaultBarFgColor(Color.grey1);    // High  
        
    setDefaultBarFgColor(Color.maroon2);    // Low   

        
    setDefaultBarThickness(30); // High  
        
    setDefaultBarThickness(31); // Low   

        
    setPlotType(PLOTTYPE_FLATLINES0);    // High  
        
    setPlotType(PLOTTYPE_FLATLINES1);    // Low   
    }

    var 
    bInit false;
    var 
    xHigh  null;
    var 
    xLow   null;

    function 
    main() {
        
        if(
    isMonthly() || isWeekly() || isDaily())
        return;
        
        if(
    bInit == false){
            
    xHigh  high(inv("D"));
            
    xLow   low(inv("D"));
            
    bInit true;
        }
        
        var 
    vHigh  xHigh.getValue(-3);
        var 
    vLow   xLow.getValue(-3);
        if(
    vHigh == null || vLow == null)
        return;
        
        
        return new Array (
    vHigh,vLow);


  • #2
    Hello jphillips,

    You can use the Donchian studies to get the highest high and low low for the daily high and low series (see below). For your vHigh and vLow varialbes you just assign them to the current bar 0 value since the xHigh and xLow studies are based on 3 periods.

    PHP Code:
    function main() {
        
        if(
    isMonthly() || isWeekly() || isDaily())
        return;
        
        if(
    bInit == false){
            
    xHigh  upperDonchian(3high(inv("D")));
            
    xLow   lowerDonchian(3low(inv("D")));
            
    bInit true;
        }
        
        var 
    vHigh  xHigh.getValue(0);
        var 
    vLow   xLow.getValue(0);
        if(
    vHigh == null || vLow == null)
        return;
        
        
        return new Array (
    vHigh,vLow);

    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