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...
ahujat Posted December 14, 2023 Report Share Posted December 14, 2023 On 8/28/2021 at 11:07 AM, Mike Medved said: 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.. Hi Mike Will this work across system reboot and MT restart or even system crash/hang (where I have to forcibly reboot the system without closing MT)? I also need something like this, high/low for a particular time range from the previous trading session. Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted December 14, 2023 Report Share Posted December 14, 2023 1 hour ago, ahujat said: Hi Mike Will this work across system reboot and MT restart or even system crash/hang (where I have to forcibly reboot the system without closing MT)? I also need something like this, high/low for a particular time range from the previous trading session. If you backfill (so that the gap is filled) sure it will work. And yes, that code works for every day. It only draws the line for the last day though. You can change it so it draws the line for every day. Quote Link to comment Share on other sites More sharing options...
ahujat Posted December 14, 2023 Report Share Posted December 14, 2023 What I meant to ask was that there is a one-day delay before I get the correct data. If I start the application today, it won't have the data for yesterday, and then get the correct data the next day. Let's say MT is restarted the next day or the system crashes, I don't MT will retain the highs/lows from today, and then there will be a day delay. Moreover, even if MT retains the data over restarts, if MT is restarted after five days, the Prev11amLow/high will be wrong because it will be 5 days old. No? Basically, what I want is that if I start MT today, I want yesterday's data to be available today or if I restart after 5 days, the Prev11amLow/High should be 4 days from now. Any way to do that taking into account partial days and holidays? Quote Link to comment Share on other sites More sharing options...
Jerry Medved Posted December 15, 2023 Report Share Posted December 15, 2023 very confused. Why would you not retain data for previous days? MT shows intraday charts for many days - all data is stored. You can have paintbars tracking high/low for whatever period or just reference Opening Range indicator with however amount of time you want to count from the start of each day Quote Link to comment Share on other sites More sharing options...
ahujat Posted December 18, 2023 Report Share Posted December 18, 2023 I was specifically referring to Mike's code above, which he provided as an example and is quite simplistic. I wanted something similar but a little more nuanced. But I figured it out, so it's all good. 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.