nasdorq Posted May 16, 2022 Report Share Posted May 16, 2022 I'm trying to use Projected Volume in a paintbar. One variation of the calculation would be: BarVolume * (Total seconds in a bar / Current # of seconds into a bar) Are there any pre-programmed keywords or functions for the part in brackets? Or is there a better way to accomplish this? Thank you Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted May 17, 2022 Report Share Posted May 17, 2022 Well, first of all make sure you're only doing it on the last candle - that is IsLastCandle is true. # of seconds in a bar is CandeSizeInSeconds Current # of seconds into a bar is harder. I guess it can be estimated by (MTUtil.UtcNowSynced - Timestamp).Ticks/TimeSpan.TicksPerSecond The only problem is that UtcNowSynced may be off compared to the candle depending on the lag of the quotes. And of course check for 0 for the # of seconds into a bar so you don't divide by it. Quote Link to comment Share on other sites More sharing options...
nasdorq Posted May 23, 2022 Author Report Share Posted May 23, 2022 Thank you for the suggestions. I managed to get "Bar Volume", "Total Seconds in a bar", and "Current # of seconds into a bar" working as variables. However, when I try to combine them into a Projected Volume calculation, the value in the watchlist Scan Result value is Infinity. I've copied the simple paintbar code below. As you can see in the attached picture, I use the Scan Result in a watchlist to make sure each variable is correct. Since BARVOLUME, SIZE, and SECONDS all work individually, I'm not sure why combining them into straightforward formula would produce infinity. (BARVOLUME / (SECONDS / SIZE)) is the Projected Volume calculation. Is this a potential bug, or have I constructed this incorrectly? //////////////////////////////////////////////////// public void MainCalculation() { var BARVOLUME = BarVolume; // volume of current bar var SIZE = CandleSizeInSec; // number of seconds in a bar var SECONDS = (MTUtil.UtcNowSynced - Timestamp).Ticks/TimeSpan.TicksPerSecond; //seconds into current bar var PROJ = (BARVOLUME/(SECONDS/SIZE)); // projected volume for current bar if ( IsLastCandle) // current bar only { SetColor(Color.Aqua); SetScanResult(PROJ); } } Quote Link to comment Share on other sites More sharing options...
Donald Q. Posted May 24, 2022 Report Share Posted May 24, 2022 (edited) When SIZE is greater than SECONDS, you have division by zero since C# is implying int as the type on that ratio. Division by zero will have unexpected results in general and looks like MT is showing that as infinity. Change all var to double and you'll be in good shape. Edited May 24, 2022 by Donald Q. Quote Link to comment Share on other sites More sharing options...
nasdorq Posted May 24, 2022 Author Report Share Posted May 24, 2022 Thank you Donald. That did the trick. Cheers Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted May 24, 2022 Report Share Posted May 24, 2022 Don is a pro 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.