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 |

Creating portable indicator of indicators (i.e., resolving an indicator reference at creation) Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
sundeep
Posted : Saturday, July 10, 2010 2:48:30 AM
Registered User
Joined: 3/9/2006
Posts: 39
Hello,

I'd like to create a reusable indicator which operates on any arbritrary indicator on my chart, not just the price array.


Details:

I'd like to be able to create and add an indicator to the library (e.g., MyScoreIndicator) which prompts for an active indicator on the chart (e.g.,1: A/D line for active watchlist; e.g.2: MyCustomIndicator etc.) and then plots itself (based on the value of the assigned indicator).

I don't see how to provide a placeholder reference in realcode for the target indicator that get's resolved dynamically .... Is this possible?

thanks.
jas0501
Posted : Saturday, July 10, 2010 4:07:35 PM
Registered User
Joined: 12/31/2005
Posts: 2,499

No. You could include all possible indicators and then user a userinput.integer combined with a select statement to make a generic dynamice function. Not efficient by at least marginally dynamic

'# num = userinput.integer = 12
'# Ind01 = char.indicatorW
...
...
'# Ind12 = chart.indicator.somethingelse


dim val to use as single

select case num
  case 1
      val = Ind01.value
  case 2
      val = Ind02.value
  case ...
   ...
   ...
  case 12
      val = Ind12.value
end select
'
' then just use val in the logic that follows
'



Alternately you could use 

'# name = userinput.string = "W"

with

select case name
    case "W"
       val = Ind01.value
...
...
to better associate the dynamic assignment. 


You still need to include all indicators that you would hope to plot. I'm not sure what the performance hit would be. It could be substantial.

jas0501
Posted : Sunday, July 11, 2010 10:14:31 PM
Registered User
Joined: 12/31/2005
Posts: 2,499

Thinking about it a little more, VB.NET does support compile time directives.

So this should do the trick

#const Test = "W"
#If Test = "W"
'# MA = chart.MovingAverage.3
#Elseif test = "X"
'# MA = chart.MovingAverage.4
#else
'# MA = chart.MovingAverage.5
#EndIf

plot = MA.close


but it doesn't, as the StockFinder preprocessor does not like multiple occurrances of MA.

So

#const Test = "X"
#If Test = "W"
'# MAW = chart.MovingAverage.3
#Elseif test = "X"
'# MAX = chart.MovingAverage.4
#else
'# MA = chart.MovingAverage.5
#EndIf

#If Test = "W"
plot = MAW.close
#Elseif test = "X"
plot = MAX.close
#else
plot = MA.close
#EndIf


works. Though you will need to edit the code a change the value of 
#const Test = "W"
manually.


Not perfect but closer at least.


jas0501
Posted : Sunday, July 11, 2010 11:43:38 PM
Registered User
Joined: 12/31/2005
Posts: 2,499

Note: saving the indicator with this type of compile time directive construct a block diagram with all the "conditional" indicators included. This means the complexity of the block diagram is still created even though the plot code is streamlined and only reference just one indicator.




Currently the process flow is

StockFinder preprocess ==> VB.net compile( preprocess--> compile)


To get a streamlined save indicator referencing only 1 indicator the process would need to be modified:

VB.net preprocess==>StockFinder preprocess-->VB.net compile



Alternately StockFinder could offer preprocess compile directives similar to VB.net's as in '#const and '#if, etc.
Then the code could have multiple MA references and still compile:
'#const test = "X"
'#if test = "W"
'# MA.chart.movingaverage.3
'#elseif test = "X"
'# MA.chart.movingaverage.4
'#else
'# MA chart.movingaverage.5
'#endif
plot = MA.close

which would result in code of

'# MA.chart.movingaverage.4
plot = MA.close

Then saving it would produce a block diagram with only 1 indicator embedded in the diagram.

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.