Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Different results with different windows

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

    Different results with different windows

    Hi,

    I have a strategy that uses 2 series. The first series is a 10-tick series while the second is a 480-minute one. My buy condition is a straightforward one. Simply the moment current price (high of the first series 10-tick) is higher than the High of the 480-minute candle (second series), take a buy position. So, here’s how I described it in the code:

    else if (State == State.Configure)
    {
    AddDataSeries(FirstSeries);
    AddDataSeries(SecondSeries);
    }
    else if (State == State.DataLoaded)
    {
    Brush1 = new SolidColorBrush((Color)ColorConverter.ConvertFromS tring("#FFCCCCCC"));
    Brush1.Freeze();
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 1 || BarsInProgress == 2)
    return;
    if (CurrentBars[1] < 2)
    return;
    if (CurrentBars[2] < 2)
    return;

    If (Highs[1][0]>Highs[2][0])
    {
    EnterLong();
    Draw.ArrowUp(this, Up + Convert.ToString(CurrentBars[0]), true, 0, (Low[0] + (-55 * TickSize)) , Brushes.White);
    }

    I noticed a difference in my order execution when I change the window time frame. If I open a 10-tick window and apply my strategy, results are different than the ones when I open a 20-minute window.

    I added the drawing order to track the code execution. I noticed that the code works almost perfectly when I use the smaller window (10-tick). However, when I open the 20-minute window, even if the current price exceeds the high of the 480-minute candle (2nd series), it doesn’t execute it unless a close of a 20-minute candle is higher than the high of the 2 series!!

    I thought the strategy is usually applied regardless which window is open
    How can I open a 20-minute window and ensure a proper execution of my order (when the high of the 10-tick is higher than the high of the 480-minute)?


    Thanks

    #2
    Hello Abdullah_KSA,

    I see that the code only runs on the primary series.
    Code:
    if (BarsInProgress == 1 || BarsInProgress == 2)
    return;
    If the primary series is different, the bars will close at different times and the actions like drawing objects will be drawn at different times.

    When a strategy is applied to a chart, the Data Series of the primary series will be the Data Series of the chart. When applied on the Strategies tab of the Control Center the Data Series is selected in the strategy parameters.

    As a heads up, using a variable in AddDataSeries() is not supported and may cause undesired behavior (especially when optimizing). This needs to be hardcoded.
    From the help guide:
    "Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner."
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    54 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    131 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    73 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X