Jump to content
Medved Trader Forums

Create scanner with stocks price >70% distance from 52 week low


Recommended Posts

MT only scans stocks on the data that comes in . Which means you have to enter all the symbols you want to scan into a portfolio, then put the scan on the portfolio.

The code for the scan in question would be simple:

    if (SymbolData.Low52 != SymbolData.High52)
    {
        var RangePer = (Close - SymbolData.Low52)/(SymbolData.High52 - SymbolData.High52);
        SetScanResult(Convert.ToInt32(RangePer));
    }

 

Link to comment
Share on other sites

  • 1 month later...

Hm, if you don't have 52 week high, you have to calculate it yourself. You'd need to do the state machine machinery...
The following code would work on Historical chart of cryptos with one day candles (if you have more than 365 days of data):

StateFIFOQueue HighLows;

public void MainCalculation()
{
    HighLows.Add(High);
    HighLows.Add(Low);
    double _high,_low;
    int at;
    HighLows.GetHighLow(out _high, out _low, out at, out at);
    if (_high!=_low)
    {
        var RangePer = (Close - _low)*100/(_high-_low);
        SetScanResult(Convert.ToInt32(RangePer));
    }   
}

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

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

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

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