- ago
Is there a straightforward way to add a zero line to a coded indicator?
0
152
Solved
4 Replies

Reply

Bookmark

Sort
- ago
#1
What do you mean a "zero line", is this what you accomplish by calling DrawHorzLine at 0 in a pane? Indicators aren't meant to add extra chart objects (exceptions apply e.g. custom overbought/oversold levels).
0
- ago
#2
You could (miss-)use the Oversold level for such a purpose

- or -

If you want to trick the system (never a good idea) you could declare a "Companion Indicator" for your coded indicator and make this companion (another custom coded Indicator) draw your horizontal line.

If dropped at a chart your indicator will automagically draw that companion also.

Well, this is neither straightforward nor recommended, just a (technical) possibility...
0
Best Answer
- ago
#3
Got it. Thank you both.
0
- ago
#4
@TraderGuy - the following is something that may make things a bit simpler than writing companion indicators.

Some of my indicators calculate and plot additional values. To plot these values I add an instance method. Then to plot the indicator, instead of calling say PlotIndicator, I call that instance method from my various strategies passing in the UserStrategyBase instance and any additional parameters it takes. The instance's plot method plots the additional values. This keeps it simple, and you don't have to mess around with writing companion indicators. Of course, the additional values won't plot if you drag the indicator into a chart. But, I'm presuming you want to use your indicators from strategy code.

For example, I have a VWAP indicator that allows various standard deviation values of interest to be defined. The various defined standard deviation values are called levels. In turn the indicator has a PlotLevels method that plots the standard deviation lines according to the levels associated values. There are additional methods that help with other calculations in relation to these levels.

So, say I have an instance of my VWAP indicator in a property named Vwap. Hence, to plot the levels -1, 0 and 1 then strategy code calls as follows (zero level is VWAP itself and is always plotted):

CODE:
Vwap.PlotLevels(this, -1, 1);

2

Reply

Bookmark

Sort