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 Davidtowleii, Today, 12:15 AM
    0 responses
    3 views
    0 likes
    Last Post Davidtowleii  
    Started by guillembm, Yesterday, 11:25 AM
    2 responses
    9 views
    0 likes
    Last Post guillembm  
    Started by junkone, 04-21-2024, 07:17 AM
    9 responses
    68 views
    0 likes
    Last Post jeronymite  
    Started by trilliantrader, 04-18-2024, 08:16 AM
    5 responses
    22 views
    0 likes
    Last Post trilliantrader  
    Started by mgco4you, Yesterday, 09:46 PM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Working...
    X