Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Reusable realcode painbrush Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
sundeep
Posted : Saturday, July 10, 2010 2:56:34 AM
Registered User
Joined: 3/9/2006
Posts: 39
Hi,

I have an indicator that plots six discreet value of -15, -10, -5, +5, +10, +15. I can create a painscheme in realcode (please see below) and save it to this indicator.

However, I have 18 of these indicators (multiple time frames). Since the realcode below references a specific indicator, I have to edit each of the 18 indicator to chage the reference W. Once the reference are changed, opening and closing the layout seems to loose these references.

Is there some generic way of specifying the color scheme without a reference to a specific chart?

'# W = chart.CycleforIndexA/D
If W.value() = 15 Then PlotColor = color.Green
If W.value() = 10 Then PlotColor = color.Yellow
If W.value() = 5 Then plotcolor = color.orange
If W.value() = -15 Then plotcolor = color.red
If w.value() = -10 Then plotcolor = color.Magenta
if w.value() = -5 then plotcolor = color.Aqua

thanks in advance.
jas0501
Posted : Saturday, July 10, 2010 3:47:01 PM
Registered User
Joined: 12/31/2005
Posts: 2,499
Given the nature of W, this coloring scheme code might be faster:


'# W = chart.CycleforIndexA/D
static isAllSet as boolean
static colors(7) as color
if not isAllSet then
  isAllset = True
 colors(2) = color.Aqua
 colors(1) = color.Magenta
 colors(0) = color.red
 colors(4) = color.orange
 colors(5) = color.Yellow
 colors(6) = color.Green
end if
plotColor = colors((W.value+15)/5)

This doesn't help with the question but may improve performance. 


Having W return vales of  (0,1,2,4,5,6) would eliminate any math for the subscript. PlotColor = colors(W.value)



If plotting W around 0 is a concern then values of (-3,-2,-1,1,2,3) would just require addition
PlotColor = colors(W.value+3) and avoid any division
jas0501
Posted : Saturday, July 10, 2010 3:47:31 PM
Registered User
Joined: 12/31/2005
Posts: 2,499
QUOTE (jas0501)
Given the nature of W, this coloring scheme code might be faster:


'# W = chart.CycleforIndexA/D
static isAllSet as boolean
static colors(7) as color
if not isAllSet then
  isAllset = True
 colors(2) = color.Aqua
 colors(1) = color.Magenta
 colors(0) = color.red
 colors(4) = color.orange
 colors(5) = color.Yellow
 colors ( 6 ) = color.Green
end if
plotColor = colors((W.value+15)/5)

This doesn't help with the question but may improve performance. 


Having W return vales of  (0,1,2,4,5,6) would eliminate any math for the subscript. PlotColor = colors(W.value)



If plotting W around 0 is a concern then values of (-3,-2,-1,1,2,3) would just require addition
PlotColor = colors(W.value+3) and avoid any division
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.