RadianChoi Posted December 30, 2017 Report Posted December 30, 2017 Hey Guys, I was hoping to create a simple price drop scanner that would alert if a stock dropped more than X% in Y minutes. I feel like this should be easy to do but can't seem to figure it out. Any help would be appreciated Thanks, RC Quote
Mike Medved Posted December 30, 2017 Report Posted December 30, 2017 You would have to use advanced mode of that. Create a FIFOQueue of the Y (as in Y minutes) size as a state variable and add the Close to it. Then you can get the high and low from the FIFOQueue and compare it to the current value. Help for FIFOQueue: https://www.medvedtrader.com/trader/WebHelp/circbuffer_class.htm the example at the end of this page should help too: https://www.medvedtrader.com/trader/WebHelp/state_keeping.htm Quote
RadianChoi Posted December 30, 2017 Author Report Posted December 30, 2017 Thanks, Mike! I'll give it a go and report back. Quote
RadianChoi Posted December 30, 2017 Author Report Posted December 30, 2017 @Mike Medved I've read through both of those posts and I honestly don't even know where to start. Not sure how to create a FIFOQueue or do the comparison you are talking about. Do you have any more basic explanations written up? Or could you possibly start me off? Would really appreciate it. Quote
Mike Medved Posted December 30, 2017 Report Posted December 30, 2017 LOL. Advanced mode is really for people who know (somewhat) how to code and a little of C# syntax. Ok I will make one and post it in a bit. Quote
Mike Medved Posted December 30, 2017 Report Posted December 30, 2017 FIFOQueue SavedPrevCloses; FIFOQueue PrevCloses; /// <summary> /// Is called at start of paintbar calculation, should be used to initialize anything needed for the paintbar /// </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; Double PercentDrop = 0; /// <summary> /// Is called at start of paintbar calculation, should be used to clear the paintbar state /// </summary> private void PaintbarClearState() { DefinePaintbarParameter("Period", "Period", true, 1, 1000, 1, 10); DefinePaintbarParameter("Percent", "Drop %", false, 0.001, 100, 0.1, 0.1); var N = Convert.ToInt32(GetPaintbarParameter("Period")); PercentDrop = Convert.ToInt32(GetPaintbarParameter("Percent")); CurrentState = new PaintbarState(); SavedPrevCloses = new FIFOQueue(N); PrevCloses = new FIFOQueue(N); } /// <summary> /// Saves paintbar state (called internally). /// </summary> private void PaintbarSaveState() { SavedState = CurrentState; PrevCloses.CopyTo(SavedPrevCloses); } /// <summary> /// Restores paintbar state (called internally). /// </summary> private void PaintbarRestoreState() { CurrentState = SavedState; SavedPrevCloses.CopyTo(PrevCloses); } public void MainCalculation() { // calculate the EMA of the EMA PrevCloses.Add(Close); Double high, low; PrevCloses.GetHighLow(out high, out low); if (Close < high*(1-PercentDrop/100)) { SetColor(Color.Lime); // if used as a paintbar SetScanResult("Dropped!"); // if used as a scan } } Quote
RadianChoi Posted December 31, 2017 Author Report Posted December 31, 2017 Thanks, Mike! Really appreciate it. Where do I input values for my percentage drop variable and time variable? Also, does the scanner constantly run and then alert me when conditions are met for a certain company? Quote
Mike Medved Posted December 31, 2017 Report Posted December 31, 2017 In the Scanning tab there is a button to edit parameters - they are at bottom. As long as the portfolio updates with RT quotes, the scanner runs on every update in it and lights up the results. That's the whole point Quote
RadianChoi Posted December 31, 2017 Author Report Posted December 31, 2017 Okay, cool! I have it all set up and running now. Thanks again, Mike. Happy New Years Quote
Mike Medved Posted December 31, 2017 Report Posted December 31, 2017 Hope it is profitable Happy New Years to you and yours. Quote
RadianChoi Posted January 1, 2018 Author Report Posted January 1, 2018 (edited) Hey @Mike Medved just wondering if there is an option to have the scanner alert you with a sound and popup? I typically keep the scanner running in the background and need these notifications to ensure I can jump to the chart. Edited January 1, 2018 by RadianChoi Quote
Mike Medved Posted January 3, 2018 Report Posted January 3, 2018 Just add a TriggerAlert to the code as well as SetScanResult Quote
RadianChoi Posted January 13, 2018 Author Report Posted January 13, 2018 @Mike Medved Hey Mike, I added it to the last paragraph as so: Double high, low; PrevCloses.GetHighLow(out high, out low); if (Close < high*(1-PercentDrop/100)) { SetColor(Color.Lime); // if used as a paintbar SetScanResult("Dropped!"); // if used as a scan string Msg = "Base Broken"; TriggerAlert(Msg); } and it's still not popping up? Should I be adding it somewhere else? Quote
Mike Medved Posted January 13, 2018 Report Posted January 13, 2018 No, that should be it. When you're editing scan parameters, you can see the "Alert" button - you have to set various alert parameters and notifications. Quote
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.