Jump to content
Medved Trader Forums

After Hrs Volume


Recommended Posts

@Mike Medved

Sometime last year you gave me some code to calculate after hrs volume.   it helped but never seemed to give me the exact right numbers.  the code is here:

Looking at it in detail, it seems to be picking up the closing bar - right at 4pm on my system - and treating it as part of after hrs.

For instance, Today TSLA had 2M shares trade in the last minute (at 4pm) and this is being picked up in after hrs volume.

If I'm correct, is there a way to adjust the code or the session times to not pick up 4pm bar but start at 4:01 or something like that?

 

Link to comment
Share on other sites

Thing is, 4pm candle (anything that is traded at or after 4pm) is considered afterhours.

IsAfterHours in TradingDay is defined as

                Timestamp >= SessionEnd && Timestamp <= DayEnd

So instead of IsAfterHours in your code, if you want to give a 1 min buffer you can just say

    Timestamp >= SessionEnd.SessionEnd.AddMinutes(1)

 

Link to comment
Share on other sites

Sorry, I know this is only because I'm not that experienced at coding, but I had:





And when I replace it TradingDay.IsAfterHours with TradingDay.Timestamp >= SessionEnd.SessionEnd.AddMinutes(1)

I get this error:

13, 42    CS1061    'System.DateTime' does not contain a definition for 'SessionEnd' and no extension method 'SessionEnd' accepting a first argument of type 'System.DateTime' could be found (are you missing a using directive or an assembly reference?)    
 

And if instead I replace TradingDay>isAfterHours with Timestamp >= SessionEnd.SessionEnd.AddMinutes(1)

I get this error: 13, 20    CS0103    The name 'SessionEnd' does not exist in the current context    
 

 

Link to comment
Share on other sites

Just now, mlsignups said:

Sorry, I know this is only because I'm not that experienced at coding, but I had:

 
 

And when I replace it TradingDay.IsAfterHours with TradingDay.Timestamp >= SessionEnd.SessionEnd.AddMinutes(1)

I get this error:

13, 42    CS1061    'System.DateTime' does not contain a definition for 'SessionEnd' and no extension method 'SessionEnd' accepting a first argument of type 'System.DateTime' could be found (are you missing a using directive or an assembly reference?)    
 

And if instead I replace TradingDay>isAfterHours with Timestamp >= SessionEnd.SessionEnd.AddMinutes(1)

I get this error: 13, 20    CS0103    The name 'SessionEnd' does not exist in the current context    
 

 

 

May have gotten it... using this only one sessionend

 
Link to comment
Share on other sites

Note that everything *after* MainCalculation is just standard code inserted by MT when you make it a state machine.
Also - to make it work right, it has to be run as an Intraday scan, with the extended hours set to Always.

====================================================================================================================

private struct PaintbarState
{
    public Double PreMarketVolume;
}
int LastDayNumber = -1;

FIFOQueue PreMarketVolumes = new FIFOQueue(5);  // averaging on 5 days period
Boolean WasPreMarket       = false;

public void MainCalculation()
{
    SetDaysNeeded(5); // need 5 day's data for this to work
    if (TradingDay.DayNumber != LastDayNumber)  // initialize to 0 start of every day
    {
        CurrentState.PreMarketVolume = 0;
        LastDayNumber                = TradingDay.DayNumber;
    }
    if (TradingDay.IsPreMarket)
    {
        CurrentState.PreMarketVolume += BarVolume;
        WasPreMarket = true;
    }
    else
    {
        if (WasPreMarket) // add the premarket volume AFTER the premarket ends to the average queue
        {
            WasPreMarket = false;
            PreMarketVolumes.Add(CurrentState.PreMarketVolume);
        }
    }
    SetScanResultColumnName(0, "Avg Premarket");
    SetScanResult(0, Convert.ToInt64(PreMarketVolumes.Average));
}

/// <summary>
/// INITIALIZES paintbar. Is called at start of paintbar calculation, should be used to initialize anything needed for the paintbar
/// NOTE: do NOT initialize the CurrentState here - the PaintbarClearState will be called AFTER this call, and will wipe it out.
/// </summary>
private void PaintbarInitialize()
{

}


/// <summary>
/// Holds current PB state - use to calc PB, changes to it carry over to next PB calc
/// </summary>
private PaintbarState CurrentState;

/// <summary>
/// Holds saved PB state - internal
/// </summary>
private PaintbarState SavedState;

/// <summary>
/// Is called at start of paintbar calculation, should be used to clear the paintbar state
/// and initialize whatever variables you place into it. This is called AFTER PaintbarInitialize
/// </summary>
private void PaintbarClearState()
{
    CurrentState = new PaintbarState();
}

/// <summary>
/// Saves paintbar state (called internally).
/// </summary>
private void PaintbarSaveState()
{
    SavedState = CurrentState;
}

/// <summary>
/// Restores paintbar state (called internally).
/// </summary>
private void PaintbarRestoreState()
{
    CurrentState = SavedState;
}
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...