1º) I use two time frame: 1) RenkoSpectrumBarsType (10,1) 2) Second (1)
I add the second in the Initialize: base.Add(PeriodType.Second, 1);
2º) I get the entry flag on the BarsInProgress == 0 and I send the orders on the BarsInProgress == 1 for not to wait to the next renko candle
if (BarsInProgress == 0)
{
flag = true;
entry = MyIndicator(BarsArray[0]).Entry[0];
}
if (BarsInProgress == 1)
{
if (flag && (entryOrder1 == null && entryOrder2 == null))
{
if (entry == 1)
{
entryOrder1 = EnterLong(1, "MyEntry1");
entryOrder2 = EnterLong(1, "MyEntry2");
}
if (entry == -1)
{
entryOrder1 = EnterShort(1, "MyEntry1");
entryOrder2 = EnterShort(1, "MyEntry2");
}
}
flag = false;
}
3º) I set the target and stop loss on OnExecution
protected override void OnExecution(IExecution execution)
{
if (entryOrder1 != null && entryOrder1 == execution.Order)
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
if (Position.MarketPosition == MarketPosition.Long)
{
// Stop-Loss order 4 ticks below our entry price
stopOrder1 = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - stop * TickSize, "MyStop1", "MyEntry1");
// Target order 8 ticks above our entry price
targetOrder1 = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + target * TickSize, "MyTarget1", "MyEntry1");
}
else
{
// Stop-Loss order 4 ticks above our entry price
stopOrder1 = ExitShortStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + stop * TickSize, "MyStop1", "MyEntry1");
// Target order 8 ticks above our entry price
targetOrder1 = ExitShortLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - target * TickSize, "MyTarget1", "MyEntry1");
}
// Resets the entryOrder object to null after the order has been filled
if (execution.Order.OrderState != OrderState.PartFilled)
{
entryOrder1 = null;
}
}
}
if (entryOrder2 != null && entryOrder2 == execution.Order)
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
if (Position.MarketPosition == MarketPosition.Long)
{
// Stop-Loss order 4 ticks below our entry price
stopOrder2 = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - stop * TickSize, "MyStop2", "MyEntry2");
}
else
{
// Stop-Loss order 4 ticks above our entry price
stopOrder2 = ExitShortStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + stop * TickSize, "MyStop2", "MyEntry2");
}
// Target order 8 ticks above our entry price
//targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 8 * TickSize, "MyTarget", "MyEntry");
// Resets the entryOrder object to null after the order has been filled
if (execution.Order.OrderState != OrderState.PartFilled)
{
entryOrder2 = null;
}
}
}
// Reset our stop order and target orders' IOrder objects after our position is closed.
if ((stopOrder1 != null && stopOrder1 == execution.Order) || (targetOrder1 != null && targetOrder1 == execution.Order))
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
{
stopOrder1 = null;
targetOrder1 = null;
}
}
// Reset our stop order and target orders' IOrder objects after our position is closed.
if ((stopOrder2 != null && stopOrder1 == execution.Order) || (targetOrder2 != null && targetOrder2 == execution.Order))
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
{
stopOrder2 = null;
targetOrder2 = null;
}
}
}
4º) I run the strategy with 6 ticks of stop loss and Target, and I see the error in all orders.
For example with the las order:
Entry Price 17742 8:50:31 and exit price stop loss 17752 8:50:43
But I see on the 1 second chart the price is no real, 17742 8:50:31 and 17743 8:50:43
So I think the strategy are closing the order because the height renko candle, but it's no a real simulator.
I don't know how to fix it.
I have thought
1º) Adding the RenkoSpectrumBarsType on the second time frame on the Add() but I don't know how do it with the two params.
Add(PeriodType.Custom4, 10 ,1) ??
I see on the code:
public RenkoSpectrumBarsType() : base(PeriodType.Custom4)
{
this.NewBarMode = true;
}
2º) I dont know how to management the orders only in the secondary time frame (Second, 1)
Best regards
David
Comment