Fil75 Posted October 25, 2021 Report Share Posted October 25, 2021 Good morning, Id’ like to screen the market in order get the stocks that have an >70% distance from 52 week low. Could you please help me how to write this code? Many Thanks, Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted October 25, 2021 Report Share Posted October 25, 2021 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)); } Quote Link to comment Share on other sites More sharing options...
coupster Posted December 18, 2021 Report Share Posted December 18, 2021 Hi Mike, Could you show me an example of how to do the above but with 75% drawdowns from 52 week high....... The problem I have with the above code is that the crypto exchanges don't populate the 52 week high and low columns in MT. thanks Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted December 18, 2021 Report Share Posted December 18, 2021 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; } Quote Link to comment Share on other sites More sharing options...
coupster Posted December 18, 2021 Report Share Posted December 18, 2021 Wow thank you for taking your time on a Saturday to reply! You guys are the absolute best! Sorry to hijack another thread but might help someone in the future. Thanks again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.