Posted Friday February 03 2017
|
Hello, I need help to plot my stops next bar on chart. I created the following method.
public void PlotStopLoss(double stopLoss) { DateTime point = Bars.Current.BarStartTime; ChartPoint centerPoint = new ChartPoint(point, stopLoss); ChartPoint outerPoint = new ChartPoint(point, stopLoss + 0.0005 * stopLoss); ChartCircle circle = new ChartCircle(centerPoint, outerPoint, Color.Red, 2); SystemData.ChartObjects.Add(Symbol, circle); }
I insert the code in list of pending orders and I can see my stops.
public override void NewBar() { foreach (Position p in OpenPositions) { stopLoss = p.EntryPrice.SymbolPrice - 1 * atr10.Current; foreach (Order o in p.Orders) { PlotStopLoss(stopLoss); }
The problem is that they appear as I coded in the DateTime point = Bars.Current.BarStartTime; But I need to see them in the next bar, the bar that they have effect. I need to add one Bar, not a TimeSpan.

Thanks in advance.
|
Posted Monday February 06 2017
|
Hello, I just come up with this solution, but it does not work for holidays. I am newbie as you can see, and I cannot imagine that there is no solution based on bars instead of DateTime to plot on chart. Any help is very much appreciated.
if (point.DayOfWeek == DayOfWeek.Friday) { point = Bars.Current.BarStartTime.AddDays(3); } else { point = Bars.Current.BarStartTime.AddDays(1); }
|
Posted Tuesday February 07 2017
|
To all courageous newbies!
public class MySymbolScript : MySymbolScriptBase { double stopLoss; public override void NewBar() { PlotStopLoss(stopLoss); stopLoss = double.NaN;
foreach (Position p in OpenPositions) { stopLoss = Low.Current; } } public void PlotStopLoss(double stopLoss) { DateTime point = Bars.Current.BarStartTime; ChartPoint centerPoint = new ChartPoint(point, stopLoss); ChartPoint outerPoint = new ChartPoint(point, stopLoss + 0.0005 * stopLoss); ChartCircle circle = new ChartCircle(centerPoint, outerPoint, Color.Red, 2); circle.FillColor = Color.Red; circle.Filled = false; circle.FillTransparency = 255; SystemData.ChartObjects.Add(Symbol,"Stop", circle); } }
|