3acor Posted September 23 Report Share Posted September 23 Hey, I am looking to scan for stocks on the historical chart that are up a certain % within a certain frequency Something like High -Any(Low(0,120) > 100% What would be the function for that? Thanks! Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted September 23 Report Share Posted September 23 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. 1 Quote Link to comment Share on other sites More sharing options...
3acor Posted September 23 Author Report Share Posted September 23 Thanks a lot! If you can send me the un-sloppy way I would really appreciate it ! Quote Link to comment Share on other sites More sharing options...
3acor Posted September 23 Author Report Share Posted September 23 What would be the code If I want to do it for the last 120 candles only? Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted September 23 Report Share Posted September 23 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(); } 1 Quote Link to comment Share on other sites More sharing options...
3acor Posted September 23 Author Report Share Posted September 23 Thanks a lot Mike. I appreciate it ! Quote Link to comment Share on other sites More sharing options...
3acor Posted September 23 Author Report Share Posted September 23 (edited) I am running the code but I am getting results I shouldn't be getting Edited September 23 by 3acor Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted September 23 Report Share Posted September 23 Instead of SetScanResult("yes") Do a debugging SetScanResult(low.ToString()+" "+High.ToString()); to see what those values are. And then stop the feed and see if there is actually a low THAT low in the last 120. Quote Link to comment Share on other sites More sharing options...
3acor Posted September 23 Author Report Share Posted September 23 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% Quote Link to comment Share on other sites More sharing options...
3acor Posted September 24 Author Report Share Posted September 24 (edited) I changed the code to this and I think it works now. Didn't use the Perc variable if (100*(SymbolData.Last-low)/low > 500 //500 as in 500% Edited September 24 by 3acor 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.