Jump to content
Medved Trader Forums

Request to make 52 Week High and 52 Week Low values available variables in Paintbar


Recommended Posts

Hello,

I was wondering if there was a variable inside the paintbar that already has in it the value for the 52 week high and 52 week low for a particular security. I know it is simple to calculate, i.e.:

YearlyHigh = Max(0, 261, High);

YearlyLow = Max(0, 261, Low);

However, when this scan is done for many thousands of candlesticks, it makes the program run quite a bit slower and cause quite a bit of lag as it needs to calculate these two values for each bar (calculate 261 candles behind it, that is).  So I was wondering if these two values could be added to the available variables list for paintbars.

Edited by Thebattlefront
Link to comment
Share on other sites

Posted (edited)

Mike,

I have a suspicion that those two values don't update as the paintbar goes backward. I'm having some weird errors in my program that get solved when I replace SymbolData.High52 and Symbol.DataLow52 with Max(0, 260, High) and Min(0, 260, Low). 

Any thoughts? So to explain what I mean, let's say my paintbar is examining a bar 260 bars ago. I want my program to calculate the 52 week high and 52 week low from that point, and then make calculations based on those values. So, for bar[260] the yearly range would be between the bars bar[261] and bar[521]. Not from bar[0] to bar[260] which would be the current yearly range.

EDIT to clarify: I don't ACTUALLY want my program to calculate that as it makes a lot of lag from the paintbar having to do a very heavy amount of calculations. What i was hoping for was that the historical yearly high and yearly low was cataloged and I could access it directly without having my computer struggle from having to calculate it for each individual bar.

 

Edited by Thebattlefront
Link to comment
Share on other sites

No they definitely do not update as you go backwards. Any SymbolData values are current values.

If you want to keep track of things like that yourself, efficiently, you need to switch to doing Advanced (I guess you already are) and use the StateFIFOQueue machinery with the state-keeping.

Here's an example (obviously this is for historical chart)

I will bold the lines that are not just filler:


 

StateFIFOQueue HighLow;

public void MainCalculation()
{
      HighLow.Add(High);
      HighLow.Add(Low);
      double High52, Low52;
      HighLow.GetHighLow(out High52, out Low52);
      // at this point High52 has the 52 week high, Low52 has 52 week low
}

/// <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 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
/// and initialize whatever variables you place into it. This is called AFTER PaintbarInitialize
/// </summary>
private void PaintbarClearState()
{
    CurrentState = new PaintbarState();
    HighLow      = new StateFIFOQueue(520); // double of 260
}

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

/// <summary>
/// Restores paintbar state (called internally).
/// </summary>
private void PaintbarRestoreState()
{
    CurrentState = SavedState;
    HighLow.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...