mlsignups Posted January 19 Report Share Posted January 19 @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? Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted January 20 Report Share Posted January 20 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) Quote Link to comment Share on other sites More sharing options...
mlsignups Posted January 20 Author Report Share Posted January 20 cool; thanks I'll try it. Quote Link to comment Share on other sites More sharing options...
mlsignups Posted January 20 Author Report Share Posted January 20 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 Quote Link to comment Share on other sites More sharing options...
mlsignups Posted January 20 Author Report Share Posted January 20 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 Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted January 20 Report Share Posted January 20 Sorry. Of course I mean TradingDay.SessionEnd Timestamp >= TradingDay.SessionEnd.AddMinutes(1) Quote Link to comment Share on other sites More sharing options...
3acor Posted January 20 Report Share Posted January 20 Could something similar be done with the Pre-market volume? I couldn't find CurrentState.PM Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted January 20 Report Share Posted January 20 Would be TradingDay.IsPreMarket Quote Link to comment Share on other sites More sharing options...
3acor Posted January 20 Report Share Posted January 20 oh yes it works now thanks. Had to modify the variable. One last thing, is it possible to compute the average pre-market volume? Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted January 21 Report Share Posted January 21 Well yes That is what FIFO queues are about - to calculate averages for last N periods. Send me your scan and I will add that. Quote Link to comment Share on other sites More sharing options...
3acor Posted January 21 Report Share Posted January 21 Great! I don't have a scan. I just want a scan that only does this. To calculate the average pre-market volume over a certain period and return it as a ScanResult. Or if possible the average turnover/dollar volume would be better. Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted January 21 Report Share Posted January 21 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; } 1 Quote Link to comment Share on other sites More sharing options...
3acor Posted January 21 Report Share Posted January 21 Thanks a lot! I appreciate it ! Quote Link to comment Share on other sites More sharing options...
3acor Posted January 22 Report Share Posted January 22 Could it be possible to have the average pre-market volume calculated up until a certain time? like for example "average pre-market volume from the open of premarket up until 9:00 am" Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted January 22 Report Share Posted January 22 Sure. Change if (TradingDay.IsPreMarket) to if (Timestamp < TradingDay.SessionStart.AddMinutes(-30)) 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.