Jump to content
Medved Trader Forums

Projected volume in paintbar


Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
                 }
}

MT.png

Link to comment
Share on other sites

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 by Donald Q.
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...