Jump to content
Medved Trader Forums

New functionality in paintbars - try it out


Recommended Posts

By popular request (well, a few people asked)...

* added ability to draw "bands" in paintbars. You just do SetYValue(value1, value2) for upper/lower values of the band, and do SetColor(0,..) SetColor(1,...) for the band borders and SetColor(2,...) for the band fill if you want one.

* added ability to draw lines on the chart from paintbar (this is not in beta yet, if you want to try it, email me. But will be in next beta).

* the lines function will also allow you to put text on the chart from a paintbar. Just draw a 0-width line with text on it.

Here is an example paintbar that draws High and Low lines on the chart every N minutes:

double PeriodHigh;
double PeriodLow;
double PrevPeriod;
int PeriodStart;

public void MainCalculation()
{
    if (CandleNumber == 0) // just starting
    {
        PrevPeriod = -1; 
    }
    var MinFromSessionStart = (Timestamp-TradingDay.SessionStart).Ticks / TimeSpan.TicksPerMinute;
    if (MinFromSessionStart<0) return;
    DefinePaintbarParameter("Period", "Minutes", true, 5, 1000, 1, 30);
    var min    = Convert.ToInt32(GetPaintbarParameter("Period"));
    var Period = MinFromSessionStart/min;  
    if (Period!=PrevPeriod)
    {
        PeriodHigh  = High;
        PeriodLow   = Low;
        PeriodStart = CandleNumber;
        PrevPeriod  = Period;
    }

    PeriodHigh = Math.Max(PeriodHigh, High);
    PeriodLow  = Math.Min(PeriodLow, Low);

    Color HColor = GetNamedColor("High", SysColor.MainIndicator1);
    SetLine(TradingDay.DayNumber*1000+Period, HColor, PeriodStart, PeriodHigh, CandleNumber + 1, PeriodHigh, 1, "H", LineTextPosition.RightAbove, 0.8);
    Color LColor = GetNamedColor("Low", SysColor.MainIndicator2);
    SetLine(TradingDay.DayNumber*2000+Period, LColor, PeriodStart, PeriodLow, CandleNumber + 1, PeriodLow, 1, "L", LineTextPosition.RightBelow, 0.8);
    
}
Link to comment
Share on other sites

  • Mike Medved changed the title to New functionality in paintbars - try it out

Hey Mike:

Thanks for the update.   Question:   I may have been one of the requesters because I like to mark high volume closes on the chart and draw a line from the high volume close (close of a bar with exceptionally high volume relative to other days).      A month back you did some code for me to do this but the code most of the time doesn't work that well and I have not gotten back to you on it.   Would this feature provide an easier way to have the system draw a horizontal line from a high volume close to the last day on the chart?

Thanks

Link to comment
Share on other sites

My goal was that if a stock trades - for instance 3x (or 5x) the normal average volume, then I want to draw a horizontal line from that close across the right of the chart.   In theory it could be forever but even a 1 yr timeframe would be fine.    Also, sometimes stocks will have a cluster over 3 or 4 days of unusually high volume, in that case I also needed some logic that would look backward over some set of time - say 30 days - and only pick the highest one.

Link to comment
Share on other sites

Yeah; something like 30 ema or sma of volume.    So basically if you look at PLTR; you had unusually high volume on Thursday.   So the idea is to be able to paint a line from the close of that high volume bar and go to the right end of the chart from there.

Meanwhile, something like UPST has had 3 extremely high volume days in a row now; but you don't want all 3; so you'd find the largest of the group and only draw from there.

Link to comment
Share on other sites

This is one that will draw the line from the high of the day with the highest turnover volume (that is, volume times price) in the last 300 days.
It will also show you what the line's ratio is of the volume turnover to the average volume turnover for the last 30 days.

Note that since there is only one line being drawn, it just has an ID of 1.


Most of the code is housekeeping, the important code is at the top.

StateFIFOQueue Volumes;  // to find the SMA of $volumes
double MaxRatio = 0;

public void MainCalculation()
{
    Volumes.Add(BarVolume*Close);  // maintain the SMA
    
    if (Timestamp<DateTime.Now.Date.AddDays(-300))  // look only at the last 300 days
        return;
    
    if (Volumes.Average>0 && BarVolume*Close/Volumes.Average > MaxRatio)  // if this is the highest volume ratio reset line
    {
        MaxRatio = BarVolume*Close/Volumes.Average;
        var Col  = GetNamedColor("Line", SysColor.MainIndicator1);
        SetLine(1, Col, CandleNumber, High, CandleNumber+100000, High, 1, Convert.ToString(Math.Round(MaxRatio,2)), LineTextPosition.RightAbove, 1);
    }
}

/// <summary>
/// Is called at start of paintbar calculation, should be used to initialize anything needed for the paintbar
/// </summary>
private void PaintbarInitialize()
{
    Volumes  = new StateFIFOQueue(30);
    MaxRatio = 0;
}

/// <summary>
/// Holds paintbar state - fill with variables needed to be preserved for next paintbar calc
/// </summary>
private struct PaintbarState
{

}

/// <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
/// </summary>
private void PaintbarClearState()
{
    CurrentState = new PaintbarState();
    Volumes.Clear();
}

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

/// <summary>
/// Restores paintbar state (called internally).
/// </summary>
private void PaintbarRestoreState()
{
    CurrentState = SavedState;
    Volumes.RestoreState();
}

 

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.

 Share

×
×
  • Create New...