Jump to content
Medved Trader Forums

Scan for stocks on historical based on %


Recommended Posts

There is a sloppy way to do this:

    var MinLow = Min(120, Low);
    var Perc   = MinLow==0?0:100*(High/MinLow);
    if (Perc>100)
        ...

It is "sloppy" because it has to loop through 120 candles on every run.

The un-sloppy/efficient way is to do it with "Advanced" state model, 
with a StateFIFOQueue of size 120 that contains the Low of every candle in 
the last 120 and doing the  GetHighLow() on it.

 

 

  • Thanks 1
Link to comment
Share on other sites

StateFIFOQueue Lows;

public void MainCalculation()
{
    Lows.Add(Low);
    Double high,low;
    Lows.GetHighLow(out high, out low);
    // at this point low contains the lowest low for the last 120 candles
    var Perc = low==0?0:100*(High/low);
    if (Perc>100)    
        ...
}  

/// <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()
{
    Lows = new StateFIFOQueue(120);

}

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

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

/// <summary>
/// Restores paintbar state (called internally).
/// </summary>
private void PaintbarRestoreState()
{
    CurrentState = SavedState;
    Lows.RestoreState();
}
  • Thanks 1
Link to comment
Share on other sites

I did that. So it looks like the code is taking into account the High and Low regardless if the LAST price is above or below the high. 
So it is taking into accounts stocks that are well below the high. (Stocks that fell down recently from their high)
Will doing something like the code below solve the issue? 



 

 

For Example I am setting Perc>500 and I am getting ticker ZS in the scan result but ZS is no where near up 500%

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...