Plot DataSeries with gaps (Double.NaN)
Author: rk089
Creation Date: 6/7/2013 6:01 PM
profile picture

rk089

#1
Hello,

i wonder if it's possible to have gaps in dataseries that are plotted on the PricePane, e.g.

DataSeries StopLoss = ....
PlotSeries(PricePane, StopLoss, ...

If the strategie is not in the market i would like to skip the stopp loss line. Setting to zero would distort the scale. I tried Double.NaN which seems to be predestined as gap-marker but it did not work. What should i do?

Thank you,
Robin
profile picture

Eugene

#2
For plotting stop/limit levels, simply call PlotStops() once and it will do the rest (more information in the QuickRef).

An alternative is to SetBarColor to Color.Transparent on bars when the strategy is not in the market. Unlike PlotStops, this is called on every bar in the trading loop.
profile picture

aykuts

#3

Hi,

I am using a certain "state series" (one double[] array) which:
* carries a certain value (say, a value between 1 and 2) while the strategy is at position,
* carries a NaN value (i.e. double.NaN) while the strategy is not at a position.

A section of such state array would look like this:
{NaN, NaN, NaN, 1.001, 1.002, 1.004, NaN, NaN, 2.00, 1.19, 1.45, NaN, NaN, ...}


My question is;
* As you have observed, this state timeseries is discrete in the sense that it carries certain double values when the strategy is at position, and carries a double.NaN value otherwise,So, how can plot this kind of variables with a non-continuous and discrete nature?

* i.e. when I manage to plot this variable on the, say, the pricePane, I am expecting to see:
- some values printed on the pricePane when the position is open,
- nothing (similar to excel's #N/A value) when the position is not open.

***

I already worked on a workaround and assigned "0" for the times when the strategy is out of the position. Yes, it works, but:

* assigning 0 (for the bars with no position) brings in rescale of the graph (to make the value 0 visible) and that reduces to a great extent the visibility of the chart (chart squeezes the actual values such that even big trends of the price seems like a straight line)

* It is quite possible that this variable might take values around 0 when the strategy is at position, which might create confusion for the user.


***

So, what might be your suggestion? How can I plot a discrete timeseries with certain double values when it is at position and NaN when it is not?

Kind regards,

profile picture

Eugene

#4
Hi,

You can not plot a series containing NaN normally because NaN is not a number. As assigning a fictituous value like 0 is not always acceptable for the reason you expressed, please see my reply #2 above for the SetBarColor workaround (not SetBarColors).

Indicators | How to Plot a Discontinuous Indicator
profile picture

Cone

#5
In a custom case like this, you can create your own plot routine with DrawLine() that plots values only when required to [draw a line or something else]

At the end of script processing, just call the custom plot routine. [Good] Example:

CODE:
Please log in to see this code.



profile picture

aykuts

#6

Cone, the idea of coding such customized plotting routine is a splendid idea. Thank you very much.

Kind regards,


This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).