Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 ghoul, Today, 06:02 PM
    0 responses
    2 views
    0 likes
    Last Post ghoul
    by ghoul
     
    Started by Barry Milan, Yesterday, 10:35 PM
    6 responses
    18 views
    0 likes
    Last Post Barry Milan  
    Started by DanielSanMartin, Yesterday, 02:37 PM
    2 responses
    13 views
    0 likes
    Last Post DanielSanMartin  
    Started by DJ888, 04-16-2024, 06:09 PM
    4 responses
    13 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by terofs, Today, 04:18 PM
    0 responses
    12 views
    0 likes
    Last Post terofs
    by terofs
     
    Working...
    X