Hello,
What is the best way to avoid opening a long and a short position on the same bar for SP strategies?
I have an entry condition, which can be true for both long and short entries on one bar. But my main purpose is to have only one position, either long or short (depending on which was opened first).
I apologize in advance for the silly question (i'm only in the beginning of my Wealth-Lab coding experience).
CODE:
Please log in to see this code.
Size:
Color:
Hi Vitaly,
Each trading method used to enter long and short Positions returns a new Position object that represents the newly established position. The idea is to create a Position with the different "sign" if you haven't yet established a Position, as indicated by the returned Position being equal to
null:
CODE:
Please log in to see this code.
For more illustrations of this design pattern, see the built-in Strategies "Bandwagon Trade" and "Channel Breakout VT".
Size:
Color:
Eugene, thank you very much. All clear now.
I have one more question related to plotting DataSeries which was converted to double.
In the code I have created:
DataSeries mid = Close - Close;
mid[bar] = (High[bar-period] + Low[bar-period])/2;
What is the best way to plot mid? Or where is the best way to insert PlotSeries?
In my code I realized it right before closing the bracket for "for loop", but I see very long list label "Close-Close" on the chart. Where am I wrong?
Thanks.
CODE:
Please log in to see this code.
Size:
Color:
QUOTE:
What is the best way to plot mid?
The best way to plot the
mid is to simply use AveragePrice instead:
Standard Indicators >
AveragePriceQUOTE:
In my code I realized it right before closing the bracket for "for loop", but I see very long list label "Close-Close" on the chart. Where am I wrong?
Do not place a
PlotSeries call in the loop. Move that line outside the
for loop. This applies to any DataSeries, be it the one created on-the-fly (e.g.
mid) or a 'formal' indicator like
AveragePrice.
Size:
Color:
Great, thanks for all advises.
Size:
Color: