Jump to content
Medved Trader Forums
Sign in to follow this  
Jason

Intermittent functionality with simple paintbar.

Recommended Posts

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 by Jason
Code wouldn't show up.

Share this post


Link to post
Share on other sites

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)

 

 

 

 

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×