Using PlotSeries to plot trailing stops
Author: jackmanjls
Creation Date: 8/10/2009 10:18 PM
profile picture

jackmanjls

#1
I am using PlotSeries to plot my trailing stop loss(sl). I can plot the sl but there are 2 issues that I would like to clean up.

1. I init the dataseries using the following: DataSeries stopLossValue = Close - Close and then run my strategy to populate the stopLossValue series, this all works fine. When I look at the resultant chart on the left side I see 20 to 30 lines of the text "Close - Close". I suspect this is a init problem with the stopLossValue but I don't know how to fix.

2. Also, when I run my strategy and I enter a position I immediately set a stop loss and my dataseries (stopLossValue) starts getting values written to it. At the end of the strategy I run PlotSeries to plot the stopLossValues for the bars where my position was active. The problem is the from the bottom of the chart to the point where the position was entered there's a solid veritical line. Once this vertical line meets where I entered my trade it follows my stopLossValue as expected. When I close my trade I see a vertical line that falls back to the bottom of the chart. I would like to know how to eliminate the vertical lines when I enter and leave my position.

Thank You.
profile picture

Cone

#2
1. The a more straightforward way to initialize an ad-hoc DataSeries is as follows:
CODE:
Please log in to see this code.
See also, DataSeries Object > Description in the QuickRef.

2. Use LineStyle.Dots instead of .Solid and make sure the Dots are thick enough to see; use a width of 3 or 4.

Although, the reason for the vertical line is that your series has zero values in it and that's what's being drawn. Even with Dots, the plot will probably distort your vertical axis, so, the full solution is to save the last value of your stop in a variable and make sure to assign it to your plotted series on every bar.
profile picture

jackmanjls

#3
All did not work exactly as depicted but real close.

1. I init'd the stop lose using the following:
DataSeries stopLossValue = new DataSeries(Bars, "");
In the description if I put anything but "", for instance "Stop Loss", it shows up on the left side of the chart about 10-20 instances, each instance is a single line.

2. This works fine.

Any suggestions on #1?
profile picture

Eugene

#4
QUOTE:
In the description if I put anything but "", for instance "Stop Loss", it shows up on the left side of the chart about 10-20 instances, each instance is a single line.

Sounds like you're unnecessarily creating the same data series over and over in the loop, many times. Instead, define it once outside of any loops and only fill it with values in the main loop.
profile picture

jackmanjls

#5
I looked at the implementation and it is created immediately after: protected override void Execute()
so I don't think that's the issue.
profile picture

Eugene

#6
Please show the code and we'll tell you what's causing the issue.
profile picture

jackmanjls

#7
1. See line#130 for the ISSUE. I've labelled the statement:
DataSeries stopLossValue = new DataSeries(Bars, "ISSUE"); // <<==== this is the issue.

2. Also on line#135 there's the statement labelled ClearDebug(). For a data set having several symbols I want to execute this statement 1 time for the complete data set, this keeps the result of the data run in the debug buffer. Right now for each symbol it will clear the debug buffer and I loose all the info from the previous symbols. I think what I want is a constructor but I don't know where to put it. Can you advise where to put and the exact syntax?

CODE:
Please log in to see this code.
profile picture

Eugene

#8
1. Almost like I said:
CODE:
Please log in to see this code.

You're unnecessarily plotting the stopLossValue series in the loop. Instead, use something like this:
CODE:
Please log in to see this code.
profile picture

jackmanjls

#9
The solution you offered works just fine, thanks for your effort. In the process I now see the diff between the PlotSeries and DrawCircle, I wasn't clear on these prior to this. Thanks.

Do you have any comments on my second question?

2. Also on line#135 there's the statement labelled ClearDebug(). For a data set having several symbols I want to execute this statement 1 time for the complete data set, this keeps the result of the data run in the debug buffer. Right now for each symbol it will clear the debug buffer and I loose all the info from the previous symbols. I think what I want is a constructor but I don't know where to put it. Can you advise where to put and the exact syntax?

I'm not sure of the syntax nor exactly where it would be placed.
profile picture

Eugene

#10
QUOTE:
For a data set having several symbols I want to execute this statement 1 time for the complete data set, this keeps the result of the data run in the debug buffer.

I was busy with some forum management task and thought to myself, "Let's do some necroposting here":

Executing some code only once

In case somebody stumbles onto this question. ;)
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).