How to plot a line with 2 colour
- This topic has 3 replies, 2 voices, and was last updated 2 years ago by .
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
Similar topics:
Forums › ProRealTime English forum › ProBuilder support › How to plot a line with 2 colour
This is the code I made from Average Filter Regression in this library:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// K = 500 ({1...2000}) Series = (Open + High + Low + Close) / 4 ONCE Pred = Series IF BarIndex = 0 THEN AFR = Series ELSE Smooth = Pred + (Series - Pred) * SQRT((K / 10000) * 2) Velo = Velo + ((K / 10000) * (Series - Pred)) Pred = Smooth + Velo AFR = Pred ENDIF RETURN AFR |
It looks like the first screenshot. How can I make it look like the second screenshot: If Velo > 0 then the line is green, If Velo <= 0 then the line is red?
Thank you
Hi.. I think this follows you description.
The ‘if’ statement follows your logical criteria of ‘ Velo’ which set the value’s for ‘r’ and ‘g’. Then the addition of the ‘coloured’ modifier uses them to set the RGB colour of your ‘AFR’ line.
Additional lines 16-22, modified line 24.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
// K = 500 ({1...2000}) Series = (Open + High + Low + Close) / 4 ONCE Pred = Series IF BarIndex = 0 THEN AFR = Series ELSE Smooth = Pred + (Series - Pred) * SQRT((K / 10000) * 2) Velo = Velo + ((K / 10000) * (Series - Pred)) Pred = Smooth + Velo AFR = Pred ENDIF if velo > 0 then g = 255 r = 0 else g=0 r=255 endif RETURN AFR coloured(r,g,0) |
Thanks for you kind comment.
I recall a saying – If it’s not broken don’t try and fix it! Bare that in mind.
Since I’m on a steep learning curve trying to get in to PRT and the coding side, I decided to analyse the code you posted as an exercise. If this is beyond or distracting to what your doing, feel free to ignore. Just sharing.
The code here is just main code but the .itf file has a lot more comments in it, why I changed and/or added things.
I’ve learned a lot doing this and wouldn’t have done it if it wasn’t for your post and well laid out request/spec.
In analyzing I have, replaced/altered/created some variables with stock/new, replaced original ‘if’ block and added a value guard, error message and logic control to the ‘K’ variable if invalid.
Additionally, it made me figure out a couple of technique when checking that code changers give same outcome’s. These such as creating alternate, by a numbered index, variable’s to calculate a kind of before and after type scenario and by subtracting one from the other it should result in zero if there the same
Also by having a indicator panel with original and a new file with the original copied in it, as changes are made you can see if expected result are obtained. Also have a original in price window. A plan is better than no plan.
Not possibly rocket science or ground breaking but, kept me focused on the task for a while. As always do your own testing.
All the best.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
// include dynamic variable // 'K' decimal/integer, default 500 ONCE AFR = totalPrice // Input Guard - Limits 'K' input range +(1 to 2000) @ 1 d.p. validK = round(max(min(K,2000), 1),1) // Calculate CONSTANT CONSTANT = validK/10000 // Input gaurd error code - if 'K' exceeds set limit's give warning! if K < 1 or K > 2000 then drawtext("ERROR! ~ K = #K# Out of Range (1-2000)",0,8,Dialog,Bold,15)Anchor(bottom)coloured("RED") else // else run the number cruncher - calculate new AFR Smooth = AFR + (totalPrice - AFR) * SQRT(CONSTANT * 2) Velo = Velo + CONSTANT * (totalPrice - AFR) AFR = Smooth + Velo // Set colour value's for 'AFR' line, 'green' velo > 0, 'red' velo <= 0 if Velo > 0 then g = 255 r = 0 else g=0 r=255 endif endif RETURN AFR coloured(r,g,0) // new AFR value set to required colour's |
Find exclusive trading pro-tools on