Coding an Indicator line so that it changes colour as it crosses key threshold
Forums › ProRealTime English forum › ProBuilder support › Coding an Indicator line so that it changes colour as it crosses key threshold
- This topic has 22 replies, 5 voices, and was last updated 2 years ago by iac381.
-
-
06/21/2022 at 4:45 PM #19577006/21/2022 at 5:05 PM #195773
Hi @iac381
The code runs at the end of each bar.
Suppose your time frame is 5 minutes and in these 5 minutes the momentum goes from negative to positive then it meets the conditions that the momentum crosses the zero line (from bottom to top) and this whole 5 minute line will turn green.
The smaller your time frame, the more accurately the (color) line will be drawn.
You can have as many lines drawn as you want and at what level you want.
Suppose you calculate the momentum over a longer period of time and for example 100 comes out and your central zone is 25, for example, then you can have a horizontal line drawn on: DrawHLine(100/25) Coloured (0,0,255)
1 user thanked author for this post.
06/22/2022 at 9:10 AM #195809“The term “Coloured” behind DrawHLine ensures that the horizontal line gets a certain color. Coloured(R,G,B) means R = Red, G = Green, B = Blue and you can set these colors with a certain value (0 to 255). (0 is no color)”
One thing that intrigues me is that you make no mention of B (blue) in your code, and yet the HLine is blue? How does that work?
And can one use e.g. W -white, Y – yellow, P – pink/purple? etc
06/22/2022 at 12:41 PM #195851Hi @iac381
DrawHLine(HLine) Coloured(0,0,200)
The term “Coloured” after “DrawHLine” provides the color of the horizontal line, here (0.0.200) Red=0 Green=0 and Blue=200
These are the defined color names (screenshot 1)
This allows you to compose your own colours so, by combining the values of R, G and B (screenshot 2)
1 user thanked author for this post.
06/23/2022 at 10:32 AM #195934I know it is a rough way to do it, i’m using segment, but we should calculate the line slope coefficient in order to get the same visual as the original indicator, but question of topic is just about colors, so here it is:
1234567891011121314151617181920212223242526272829Once n = 20Once Hline = 0xMom = Momentum[n]DrawHLine(HLine) Coloured(0,0,200)cross=0if xMom crosses over 0 thencross=1r = 0g = 255elsif xMom crosses under 0 thencross=-1r = 255g = 0endifif cross=1 thendrawsegment(barindex[1],0,barindex,xmom)coloured(0,255,0)drawsegment(barindex[1],0,barindex[1],xmom[1])coloured(255,0,0)elsif cross=-1 thendrawsegment(barindex[1],xmom[1],barindex,0)coloured(0,255,0)drawsegment(barindex[0],0,barindex[0],xmom[0])coloured(255,0,0)elsedrawsegment(barindex[1],xmom[1],barindex,xmom)coloured(r,g,0)endifReturn xMom coloured(r,g,0,0)06/23/2022 at 4:26 PM #195962@ Nicholas @JS,
Thank you very much. That is very helpful. I take the point about the coding request coming under the topic heading I gave it, limiting scope at this stage. It is relevant, even if the final solution will be revealed under a modified heading which you may like to suggest?
I am attaching three screen captures all of the same time period today, 1 x Dax 5m IG Platform DFB and 2 x PRT through IG. The chart with golden circles is highlighting the result of implementing your adjustments. The chart with white circles implements @JS’s briefer code, but with my introduction of a separate horizontal line in white, that seems to be necessary in order to create a Colour Zone that DOES change colour exactly at the line (like the Histogram version of Momentum!). The differences are only minor but they raise the question of how to get it as precise as the ‘original’ IG version.
Finally, in your version I was unable to make the Momentum line bolder so it is more difficult to see. There is still some peculiarity to the line as you can see in close up.
06/23/2022 at 5:21 PM #195970Yes, like I said, i’m using SEGMENT (graphical line plotted), not real value. So in order to draw a segment from point A to point B, we need to calculate an affine function with the correct slope. It is tricky, but doable of course, but time consuming I guess for just a color change purely esthetic? BTW it could be an interesting example. I do not have time now until next Tuesday.
1 user thanked author for this post.
06/23/2022 at 6:12 PM #195975@Nicholas,
The finer points of coding segment and real value are well above my pay grade (as you may have gathered from my ‘conversation’ with @JS!).
Tuesday is fine with me. It is aesthetics, but it is also about ease of reference when you look up at the screen without having to be distracted by details that need elimination. Thank you once more.
-
AuthorPosts
Find exclusive trading pro-tools on