Announcement

Collapse
No announcement yet.

Coding start time from a previous day to current day

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

  • Coding start time from a previous day to current day

    I like to monitor all trading activity for emini futures such as S&P premarket. Because globex (premarket) data starts the previous calendar day and runs through midnight before start of the new trading session proper - can someone advise how to capture the beginning of the globex data.

    I want to then find the high/low of this trading activity before new session start. I have attempted various coding methods and just end up starting at midnight without capturing the time from the end of previous day session right through midnight and to the beginning of new trading session so that hi/lo lines can be drawn from the exact bar when the premarket/globex session commences to when it ends.

    The code that I have done so far is attached
    Attached Files

  • #2
    In the following code the user has to manually add the start/end times but it works over midnight. Start/end times can be 930/1630, 1700/930, etc.
    I did not use your code, I'm just posting something I did a while ago that you might be able to incorporate into your original code.
    PHP Code:
    inSession HL.efs
    //see"inSession Hours with Midnight Time Change.efs"
    //see "inSession RT Only BEST.efs"
    function preMain() {
        var 
    aFPArray = new Array();
        
    setPriceStudy(true);
        var 
    x=0;
        
    aFPArray[x] = new FunctionParameter("StartTime"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("Start Time (930)");
            
    setDefault(930);
        }
        
    aFPArray[x] = new FunctionParameter("EndTime"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("End Time (1630)");
            
    setDefault(1630);
        }
        
    aFPArray[x] = new FunctionParameter("RTM_Only"FunctionParameter.BOOLEAN);
        
    with(aFPArray[x++]){
            
    setName("Real Time Only");
            
    setDefault(false);
        }
        
    aFPArray[x] = new FunctionParameter("ColorBg"FunctionParameter.BOOLEAN);
        
    with(aFPArray[x++]){
            
    setName("Color Bg When in Session");
            
    setDefault(true);
        }
        
    aFPArray[x] = new FunctionParameter("drawLines"FunctionParameter.BOOLEAN);
        
    with(aFPArray[x++]){
            
    setName("Draw Lines at Start/End Times");
            
    setDefault(true);
        }
    }
    var 
    startFlag=endFlag=false;
    var 
    runIt_1=false;
    var 
    sessionCtr=0;
    var 
    sessionH,sessionL;
    function 
    main(StartTime,EndTime,RTM_Only,ColorBg,drawLines){
        if(
    RTM_Only) if(!isLastBarOnChart()) return;
        if(
    StartTime==null || EndTime==null || StartTime==EndTime){
            
    displayError(9050" Error: Start and End Times are not properly defined. Please correct. ""T1");
            return;
        }
        var 
    runIt false;
        
    //var hms0=(((getHour(0)*100)+getMinute(0))*100)+getSecond(0);debugPrintln("24: "+hms0);
        
    var hms0=((getHour(0)*100)+getMinute(0))+getSecond(0);//debugPrintln("24: "+hms0+"\t"+StartTime+"\t"+EndTime+"\t"+(hms0 >= StartTime)+"\t"+(EndTime>hms0));
        
    var barState getBarState();
        if(
    EndTime>StartTime){
            if(
    hms0 >= StartTime){
                if(
    EndTime>hms0){
                    
    runIt true;
                }
            }

        }else{
            if(
    EndTime>hms0){
                
    runIt true;
                
    //debugPrintln("19: "+hms0+"\t"+EndTime);
            
    }
            if(
    hms0 >= StartTime){
                
    runIt true;
                
    //debugPrintln("22: "+hms0+"\t"+(StartTime-( getInterval()*3)));
            
    }
        }

        if(
    runIt){
            
    //enter code here
            
    if(!startFlag){//marks bar when "runIt" changes to true
                
    sessionCtr++;
                
    sessionH high(0);
                
    sessionL=low(0);
                if(
    drawLinesdrawLineRelative(0,0,0,100000,PS_SOLID2Color.blue"36"+gID());
                if(
    hms0<EndTimeendFlag false;
                
    startFlag=true;
            }
            if(
    high(0)>sessionHsessionH high(0);
            if(
    sessionL>low(0)) sessionL=low(0);
            if(
    ColorBgsetBarBgColor(Color.RGB(200,255,150),0);
        }else{
            if(
    hms0==EndTime || (!endFlag && sessionCtr>0)){//marks bar when "runIt" changes to false
                
    if(drawLinesdrawLineRelative(0,0,0,100000,PS_SOLID2Color.red"78"+gID());
                
    startFlag=false;
                
    endFlag=true;
            }
        }
        return [
    sessionH,sessionL];
    }
    var 
    grID=0;
    function 
    gID() {
        
    grID++;
        return (
    grID);
    }

    //== displayError function displays an error to the user
    function displayErrora,b,ErrStr ,lbl) {
        
    removeText("xError");  
        
    drawTextRelative(abErrStrColor.maroonColor.lightgrey,  Text.FRAME Text.ONTOP Text.RELATIVETOLEFT Text.RELATIVETOBOTTOMnull16"lbl");    

    Wayne

    Comment


    • #3
      If anyone has a better way to span a session period through midnight (i.e., from 1700 thru to 900 the next day)
      and is willing to post it I would really appreciate it.

      Wayne

      Comment


      • #4
        PHP Code:
        debugClear();
        function 
        preMain(){
            
        setPriceStudy(true);
        }
        var 
        StartTime=900,EndTime=1700;
        //var StartTime=1700,EndTime=900;
        function main(){
            return 
        calcSession(StartTime,EndTime);
        }
        function 
        calcSession(StartTime,EndTime){
            var 
        hms0=(getHour(0)*100)+getMinute(0);
            var 
        inSession=false;
            if(
        StartTime>EndTime){//1700 thru 900
                
        inSession=true;
                if(
        hms0>=EndTime && StartTime>hms0){
                    
        //debugPrintln("16:\tv: "+hms0+"\ts: "+StartTime+"\te: "+EndTime);
                    
        inSession=false;
                }
            }else if(
        hms0>=StartTime && EndTime>hms0inSession=true;
            else if(
        StartTime==EndTimeinSession=true;

            
        //debugPrintln("23:\tv: "+hms0+"\ts: "+StartTime+"\te: "+EndTime);
            
        if(inSessionsetBarBgColor(Color.RGB(200,255,150));
            return 
        inSession;

        wayne

        Comment

        Working...
        X