Jason Posted August 7, 2018 Report Share Posted August 7, 2018 Quote Link to comment Share on other sites More sharing options...
Jason Posted August 7, 2018 Author Report Share Posted August 7, 2018 (edited) Sorry, not sure why this is happening but I often submit a post that ends up empty somehow which forces me to rewrite everything. Okay, so because I need to use it for the paintbars I want to create I went back and tested SymbolData.High as I have encountered unexpected results in using it previously. Using the simple code below I am able to highlight the candle where the high of the day occurs for the symbol ONCE but cannot get it to work on any of the other symbols I've tested. I've tried it on TWLO, Z, HTZ, WTW, DF... I have tried it with and without state keeping, just in case, and cannot get it to work reliably. I don't know why it would matter but I've tested this on a 5 minute chart in after hourse trading. Also, the code has been the same across all tests and there are not any other indicators on the chart. public void MainCalculation() { if ( High == SymbolData.High ) { SetColor(SysColor.Positive); } } Edited August 7, 2018 by Jason Code wouldn't show up. Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 8, 2018 Report Share Posted August 8, 2018 Ok, it is a bit of a glitch, but - the SymbolData values are stored as Double in MT, and the Candle values are stored as Float (because they take half the space). So I would suggest doing if (Math.Abs(High-SymbolData.High)<0.00001) Quote Link to comment Share on other sites More sharing options...
Jason Posted August 10, 2018 Author Report Share Posted August 10, 2018 Well, I have tried making this change but am still getting very inconsistent results. On many symbols it works, but on others it doesn't. It works, for example, on ROKU, YELP, SQ, but not on XRAY, GOOGL or MCHP. I have tried using: if ( High == (float)SymbolData.High ) which fixes the problem for GOOGL but not the others. Here is the code as it stands now: public void MainCalculation() { if ( Math.Abs(High-SymbolData.High)<0.00001 ) { SetColor(SysColor.Positive); } } Quote Link to comment Share on other sites More sharing options...
Jason Posted August 12, 2018 Author Report Share Posted August 12, 2018 Okay, I think I've figured out what's happening. When I use SymbolData.High it's pulling the high of the day as stored from all market activity that occurred from both before the opening bell and after the closing bell. Technically this makes sense, however, my intent is to test if the high of the day throughout the period from 9:30 AM to 4:00 PM is the same as the high of the first 5 minute candlestick. Is there an alternative to SymbolData.High which would present a better comparison to achieve this? Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 13, 2018 Report Share Posted August 13, 2018 Sure - you can calculate the high yourself instead of using the SymbolData.High. You're already checking the high of the first five minutes, so it is similar code. 1. Use Advanced mode. 2. In CurrentState, define int LastDayNumber; Float DayHigh; 3. in PaintbarClearState, set LastDayNumber to -1 4. var SessionInformation = GetTradingSessionInfo(Timestamp); if (SessionInformation.DayNumber != LastDayNumber) { CurrentState.LastDayNumber = SessionInformation.DayNumber; CurrentState.DayHigh=High; } CurrentState.DayHigh = Math.Max(CurrentState.DayHigh, High); if (High == CurrentState.DayHigh) { ..... } Note: this will trigger at any time the high is the same as the daily high SO FAR in the session. Quote Link to comment Share on other sites More sharing options...
Jason Posted August 18, 2018 Author Report Share Posted August 18, 2018 Okay, thanks because that worked pretty nicely. It does trigger on the chart whenever a new high is reached but I have developed it into the code I have below and am encountering a new issue. I have tested and confirmed that the code below using just the comparison is able to highlight the first candlestick of the day when the high of that candlestick is equal to the high of the day. Now need to use further conditions to narrow down which candlesticks get highlighted given that the two are equivalent. Given that the high of the first candlestick is equal to the high of the day, I need the paintbar to highlight the candlestick that crosses up over an indicator like an EMA. When I eliminate the first requirement I can get it to highlight cross-overs and other conditions but as soon as I implement the requirement for the highs to be the same the paintbar doesn't display anything on the chart. I have tried compounding both conditions with "&&" in one line and separating them out into nested IF statements to no avail. Here is the code: public void MainCalculation() { var SessionInformation = GetTradingSessionInfo(Timestamp); if (SessionInformation.DayNumber != CurrentState.LastDayNumber) { CurrentState.LastDayNumber = SessionInformation.DayNumber; CurrentState.DayHigh = High; } CurrentState.DayHigh = Math.Max(CurrentState.DayHigh, High); if (Timestamp <= SessionInformation.SessionStart.AddMinutes(5)) { CurrentState.FirstCandleHigh = High; } if ((CurrentState.FirstCandleHigh == CurrentState.DayHigh)) { if (Close.CrossesUp(EMA_10, 0)) { SetColor(SysColor.Positive); } } } /// <summary> /// Is called at start of paintbar calculation, should be used to initialize anything needed for the paintbar /// </summary> private void PaintbarInitialize() { CurrentState.FirstCandleHigh = 0.00; } /// <summary> /// Holds paintbar state - fill with variables needed to be preserved for next paintbar calc /// </summary> private struct PaintbarState { public double FirstCandleHigh; public int LastDayNumber; public double DayHigh; } /// <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(); CurrentState.LastDayNumber = -1; } /// <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...
Mike Medved Posted August 19, 2018 Report Share Posted August 19, 2018 A few things. First, I am not sure if you mean to compare the highs for exact match. That is unlikely to happen. Maybe you mean the high is higher than the first candle high? Second, I don't know if you really want to check for the "crosses up" condition. It is very unlikely that the candle that matches the first candle high will cross the EMA as well. You probably mean if Close is above the EMA? And third - your code will only register the first five minutes' high if you use five-minute candles. If you use one-minute candles, you'd have to change the code. Do you only use this on five-min candles? Quote Link to comment Share on other sites More sharing options...
Jason Posted August 19, 2018 Author Report Share Posted August 19, 2018 (edited) 47 minutes ago, Mike Medved said: > A few things. First, I am not sure if you mean to compare the highs for exact match. That is unlikely to happen. Maybe you mean the high is higher than the first candle high? Yes, an exact match. Because the point is to make sure that the cross up over the EMA is only detected in a chart where the price action up to that point in the day has moved down from the first candlestick in the session. In other words, the high of the first 5 minute candle is the highest price reached in the session up to the point of the EMA cross over. >Second, I don't know if you really want to check for the "crosses up" condition. It is very unlikely that the candle that matches the first candle high will cross the EMA as well. You probably mean if Close is above the EMA? The idea, was to store the high of the first 5 minute candlestick so that it could be retrieved and used later at some point. Then, to store the highest price reached for the day thus far. These two values wouldn't change so long as the price action never moved above the high of the first 5 minute candle. Those two values would be retrieved and compared later at the time of the EMA test. The code I use for the EMA crossover, when I test it independently works perfectly. I was hoping that the code wouldn't be requiring the EMA crossover to occur on the first 5 minute candlestick. If the high of the day and first candle high are variables that have been stored properly it shouldn't do that. >And third - your code will only register the first five minutes' high if you use five-minute candles. If you use one-minute candles, you'd have to change the code. Do you only use this on five-min candles? I was planning on designing it for the 5 minute chart as that is the most important to me and the parameterizing the code later to expand it's capabilities. Edited August 19, 2018 by Jason Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 19, 2018 Report Share Posted August 19, 2018 "CrossUp" means previous candle's EMA is lower than the current candle's high and the current candle's EMA is higher than the high. Is that what you meant to do? If you remove the "crossUp" - do you see a stretch in the chart where the paintbar's condition is satisfied? If there is, and you add the CrossUp, and the CrossUp condition is within that stretch, it should work. Quote Link to comment Share on other sites More sharing options...
Jason Posted August 19, 2018 Author Report Share Posted August 19, 2018 If I remove the condition for the crossup over the EMA the paintbar highlights just the first candlestick of the day. But because the high of that candlestick is equal to the high of the day for every candlestick in the chart the paintbar should be highlighting every candlestick. The comparison should return true for each candlestick. The chart that I'm using is for AMAT for Friday's activity. Here is the relevant code: public void MainCalculation() { var SessionInformation = GetTradingSessionInfo(Timestamp); if (SessionInformation.DayNumber != CurrentState.LastDayNumber) { CurrentState.LastDayNumber = SessionInformation.DayNumber; CurrentState.DayHigh = High; } CurrentState.DayHigh = Math.Max(CurrentState.DayHigh, High); if (Timestamp <= SessionInformation.SessionStart.AddMinutes(5)) { CurrentState.FirstCandleHigh = High; } if ((CurrentState.FirstCandleHigh == CurrentState.DayHigh)) { SetColor(SysColor.Positive); } } Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 19, 2018 Report Share Posted August 19, 2018 Ok, the problem is that the line if (Timestamp <= SessionInformation.SessionStart.AddMinutes(5)) should be if (Timestamp < SessionInformation.SessionStart.AddMinutes(5)) Quote Link to comment Share on other sites More sharing options...
Jason Posted August 19, 2018 Author Report Share Posted August 19, 2018 I just caught it myself in playing with it. The equals changes the value of FirstCandleHigh to the high of the second candlestick which borks everything else. Thanks for your patience. 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.