Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Management orders with Custom TimeFrame

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Management orders with Custom TimeFrame

    Hello! I'm developing an strategy and I have some problem.

    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
    World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.

    World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


    But I see on the 1 second chart the price is no real, 17742 8:50:31 and 17743 8:50:43
    World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


    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

    #2
    Hello David,

    Thank you for your post.

    Is this what you see on historical data or in backtesting? Renko bars are not accurate in backtesting as the ticks that built the bars are not available. Meaning the bar is built from Open, High, Low, and Close.
    Do you see the same behavior when running on NinjaTrader Renko bars (not the custom ones) in backtesting?

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X