mlsignups Posted August 25, 2021 Report Share Posted August 25, 2021 Is it possible to draw lines on an intraday chart (say 5 minute chart) showing the highs and lows from a specific point yesterday? For instance, highs and lows after 11am the day before? Quote Link to comment Share on other sites More sharing options...
Jerry Medved Posted August 25, 2021 Report Share Posted August 25, 2021 there is nothing built in like that. With the new beta supporting custom lines from Paintbars, you could do it in a Paintbar, but would have to do a bit of work in Advanced Mode. Quote Link to comment Share on other sites More sharing options...
mlsignups Posted August 25, 2021 Author Report Share Posted August 25, 2021 Thanks. Regarding doing it w/ a paintbar... I'll work to figure out the code but can you get me started by explaining if there is an easy way to just get the high and/or low of the 11am bar from the day before? Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 27, 2021 Report Share Posted August 27, 2021 Double Today11amHigh = 0; Double Today11amLow = 0; int Today11amCandleNumber = -1; Double Prev11amHigh = 0; Double Prev11amLow = 0; int Prev11amCandleNumber = -1; int DayNumber = -1; public void MainCalculation() { var today = TradingDay; if (today.DayNumber!=DayNumber) { Prev11amHigh = Today11amHigh; Prev11amLow = Today11amLow; Prev11amCandleNumber = Today11amCandleNumber; Today11amHigh = 0; Today11amLow = 0; DayNumber = today.DayNumber; } if (Today11amHigh==0 && Timestamp>=today.SessionStart.AddHours(1.5)) { Today11amHigh = High; Today11amLow = Low; Today11amCandleNumber = CandleNumber; } if (Prev11amHigh!=0) { var highColor = GetNamedColor("High", SysColor.Positive); SetLine(1, highColor, Prev11amCandleNumber,Prev11amHigh, 100000, Prev11amHigh, 1, "11H", LineTextPosition.RightAbove); var lowColor = GetNamedColor("Low", SysColor.Negative); SetLine(2, lowColor, Prev11amCandleNumber,Prev11amLow, 100000, Prev11amLow, 1, "11L", LineTextPosition.RightBelow); } } Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 27, 2021 Report Share Posted August 27, 2021 Quote Link to comment Share on other sites More sharing options...
mlsignups Posted August 28, 2021 Author Report Share Posted August 28, 2021 Thanks Mike. That's pretty cool. I'll give it a try. Quote Link to comment Share on other sites More sharing options...
mlsignups Posted August 28, 2021 Author Report Share Posted August 28, 2021 Thanks again; working great. One variation...if I wanted to get the high from yesterday SINCE the 11am bar; would I add a loop into the code to keep checking the 5 minute bars from the prior day; or is there any easier way? for instance, change addhours(1.5) to a variable and loop in 5 minute increments checking if the high is higher or the low is lower? Quote Link to comment Share on other sites More sharing options...
mlsignups Posted August 28, 2021 Author Report Share Posted August 28, 2021 Also, trying really hard to learn how to code paintbars. Something like Candlenumber looks like a built in function or variable? Is that right? To a question I asked elsewhere tonight, is there documentation for this and similar things? Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 28, 2021 Report Share Posted August 28, 2021 Ok - first of all, documentation - yes. Either press F1 in MT or go to https://www.medvedtrader.com/trader/WebHelp/ - it is a pretty comprehensive help file for MT in general. All the available variables and MT specific functions are found here: https://www.medvedtrader.com/trader/WebHelp/advanced_-_all_available_funct.htm CandleNumber is recent so it has not been compiled into the help yet, I will ask Jerry to do that and put it up Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 28, 2021 Report Share Posted August 28, 2021 As to your question how to do the high/low not AT 11am but since 11am - it is a fairly small change in the paintbar code.. Double Today11amHigh = 0; Double Today11amLow = 0; int Today11amCandleNumberHigh = -1; int Today11amCandleNumberLow = -1; Double Prev11amHigh = 0; Double Prev11amLow = 0; int Prev11amCandleNumberHigh = -1; int Prev11amCandleNumberLow = -1; int DayNumber = -1; public void MainCalculation() { var today = TradingDay; if (today.DayNumber!=DayNumber) { Prev11amHigh = Today11amHigh; Prev11amLow = Today11amLow; Prev11amCandleNumberHigh = Today11amCandleNumberHigh; Prev11amCandleNumberLow = Today11amCandleNumberLow; Today11amHigh = 0; Today11amLow = 0; DayNumber = today.DayNumber; } if (Timestamp>=today.SessionStart.AddHours(1.5)) { if (High>Today11amHigh) { Today11amHigh = High; Today11amCandleNumberHigh = CandleNumber; } if (Today11amLow==0 || Low<Today11amLow) { Today11amLow = Low; Today11amCandleNumberLow = CandleNumber; } } if (Prev11amHigh!=0) { var highColor = GetNamedColor("High", SysColor.Positive); SetLine(1, highColor, Prev11amCandleNumberHigh,Prev11amHigh, 100000, Prev11amHigh, 1, "11H", LineTextPosition.RightAbove); } if (Prev11amLow!=0) { var lowColor = GetNamedColor("Low", SysColor.Negative); SetLine(2, lowColor, Prev11amCandleNumberLow,Prev11amLow, 100000, Prev11amLow, 1, "11L", LineTextPosition.RightBelow); } } Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 28, 2021 Report Share Posted August 28, 2021 As for your other questions - in general, it is pretty inefficient to use loops in paintbar code, because it executes so often. So you have to take advantage of the fact that at start the paintbar code is called for every candle, and then it is called for the last candle every time it updates with incoming data. Take a look at the code I provided here and see if you can understand how it works. Quote Link to comment Share on other sites More sharing options...
mlsignups Posted August 28, 2021 Author Report Share Posted August 28, 2021 Thanks Mike. Great code and I'll study it and let you know. Quote Link to comment Share on other sites More sharing options...
mlsignups Posted August 28, 2021 Author Report Share Posted August 28, 2021 Hey Mike, a few questions: - what are the parameters for setline. Are they listed somewhere? - also, trying to understand the code... when you run this as a paintbar and it goes bar by bar - do the values/variables carry over from one bar to the next bar? I previously used another product and they did not but the code seems to be written that way ? Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 28, 2021 Report Share Posted August 28, 2021 SetLine parameters - in the help file. I just gave it to Jerry he will put it up on the web later today. The variables - I guess you have to know C# a little. Variables that are defined inside the function are scoped in the function - they get reinitialized every time the function is entered. Variables defined outside the function stay there between function calls. There are also "State Variables" you can have in paintbars - that is a bit more complicated. Basically the state is saved and restored for the same-candle calls. The code above didn't need that but some things that need to be done (for example, EMA calculations) need that. The way to do that and why it should be done is explained in help as well: https://www.medvedtrader.com/trader/WebHelp/state_keeping.htm Basically you can think of the paintbar as a "state machine". When the MainCalculation is called, it is given a "state" and it generates the new "state" for the next candle. When the MainCalculation is entered for the same candle again (which is what happens when the paintbar is calculated on the newly incoming data) it is again given a "state" for the previous candle. Example: for EMA calculation, you always need the previous candle's EMA. So if you put that in the State, the new candle's EMA can always be calculated from the State's EMA - and the State's EMA will stay the same (and contain the previous candle's EMA) no matter how many times the MainCalculation is called for this candle. When it is called for the next candle, the saved State will contain the previous candle's state again. CurrentState structure can contain only simple variables. If you want to do state-machine with the FIFOQueues (for things like averages, standard deviation calcs, or stuff like looking at what some calculated value was N candles ago, use the StateFIFOQueue classes, and do the Save/Restore in the for them in the appropriate functions in the code - again, look in Help for examples. Quote Link to comment Share on other sites More sharing options...
mlsignups Posted August 28, 2021 Author Report Share Posted August 28, 2021 Thanks. The variable discussion will help. But more importantly; if the data gets saved from one candle to the next candle then the code makes a lot more sense to me. 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.