You will find part of my strategy here below.
The idea is to have a visual representation of the bracket orders with Stop and Target (see attached pic) plus additional infos when the trade is closed.
I would like to add on the chart the value in ticks of the Stop or Target hit by price and see if there were any slippage when Stop or Target was hit.
Additionally i would like to increase the font of the draw text....Dont know how !
Any recommendations to help me improve this part of the code would be more than welcome

Happy trading
Chris
namespace NinjaTrader.Strategy
{
[Description("Momentum Pimping")]
public class AAA : Strategy
{
#region Variables
private int contract = 1;
private int barNumberOfOrder = 0;
private int lineLength = 0;
private IOrder entryOrder = null;
#endregion
protected override void Initialize()
{
TimeInForce = Cbi.TimeInForce.Day;
CalculateOnBarClose = true;
}
protected override void OnBarUpdate()
{
//LONG ENTRY CONDITIONS
if (Position.MarketPosition == MarketPosition.Flat
&& Close[0]<Close[1]
&& Close[1]<Close[2])
{
barNumberOfOrder = CurrentBar;
entryOrder = EnterLongLimit(CONTRACT, Close[0], "");
}
//SHORT ENTRY CONDITIONS
if (Position.MarketPosition == MarketPosition.Flat
&& Close[0]>Close[1]
&& Close[1]>Close[2])
{
barNumberOfOrder = CurrentBar;
entryOrder = EnterShortLimit(CONTRACT, Close[0], "");
}
}
protected override void OnExecution(IExecution execution)
{
if(execution.Name == "Stop loss") PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\StopFilled.wav");
else if(execution.Name == "Profit target") PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\TargetFilled.wav");
int Stop = 10;
int Target = 20;
if (entryOrder != null && entryOrder == execution.Order)
{
SetStopLoss(CalculationMode.Ticks, Stop);
SetProfitTarget(CalculationMode.Ticks, Target);
}
lineLength = Math.Max(CurrentBar - barNumberOfOrder, 3);
if (Position.MarketPosition == MarketPosition.Long)
{
PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\Alert2.wav");
DrawLine("Target", false, lineLength, Position.AvgPrice + (Target) * TickSize, -8*lineLength, Position.AvgPrice + (Target) * TickSize, Color.Lime, DashStyle.Solid, 2);
DrawLine("Stop", false, lineLength, Position.AvgPrice - (Stop) * TickSize,-8*lineLength, Position.AvgPrice - (Stop) * TickSize, Color.Red, DashStyle.Solid, 2);
DrawLine("Entry", false, lineLength, Position.AvgPrice, -8*lineLength, Position.AvgPrice, Color.Tan, DashStyle.Solid, 2);
DrawText("TargetValue","Target: "+Convert.ToString(Target)+" Ticks" , 0, Low[0]-12*TickSize, Color.Yellow);
DrawText("StopValue","Stop: "+Convert.ToString(Stop)+" Ticks" , 0, Low[0]-10*TickSize, Color.Yellow);
}
else if (Position.MarketPosition == MarketPosition.Short)
{
PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\Alert2.wav");
DrawLine("Target", false, lineLength, Position.AvgPrice - (Target) * TickSize, -8*lineLength, Position.AvgPrice - (Target) * TickSize, Color.Lime, DashStyle.Solid, 2);
DrawLine("Stop", false, lineLength, Position.AvgPrice + (Stop) * TickSize, -8*lineLength, Position.AvgPrice + (Stop) * TickSize, Color.Red, DashStyle.Solid, 2);
DrawLine("Entry", false, lineLength, Position.AvgPrice, -8*lineLength, Position.AvgPrice, Color.Tan, DashStyle.Solid, 2);
DrawText("TargetValue", "Target:"+Convert.ToString(Target)+" Ticks" , 0, High[0]+12*TickSize, Color.Yellow);
DrawText("StopValue","Stop:"+Convert.ToString(Stop)+" Ticks" , 0, High[0]+10*TickSize, Color.Yellow);
}
if (Position.MarketPosition == MarketPosition.Flat)
{
RemoveDrawObject("Stop");
RemoveDrawObject("Target");
RemoveDrawObject("Entry");
RemoveDrawObject("TargetValue");
RemoveDrawObject("StopValue");
}
}
#region Properties
[Description("")]
[GridCategory("3.Parameters")]
public int CONTRACT
{
get { return contract; }
set { contract = Math.Max(1, value); }
}
#endregion
}
}

Comment