Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding string values to series<T>

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

    Adding string values to series<T>

    I am trying to create a custom series that holds strings indicating the direction of the Trend as calculated by a CheckMarketTrend().
    Without using the Trend series, the algorithm works well on historical data. With it, it does nothing. No compilation errors or log errors were given. I am assuming therefor that I am not adding the string values correctly to the Trend series.
    I would appreciate it if someone can point me in the right direction to fix this.

    Below is the skeleton code I am using to execute.

    else if (State == State.DataLoaded)
    Trend = new Series<string>(this);

    protected override void OnBarUpdate()
    {
    if (IsFirstTickOfBar)
    {
    CheckMarketTrend();
    }

    if (Trend[0] == "long")
    {
    ///Execute logic to enter long position
    }
    }

    private string CheckMarketTrend()
    {
    if (stochastic5min.D[0] <= 20)
    {
    return Trend[0] = "long";
    }
    ////logic continues setting Trend[0] = "long", "short" or "donothing" using logic structure of above example ending with an Exception to catch anything falling outside the scope given.
    }

    #2
    Hello JulieV,

    Trace it back one step at a time.

    Use prints to understand the behavior.
    http://ninjatrader.com/support/forum...979#post510979

    What have you understood so far?
    Is Trend[0] set to the expected value after that condition is set?
    Keep in mind a bar series value represents that entire bar. If its changed at some point its changed for the entire bar.
    This means if the condition was false on the first tick, then on each subsequent tick that condition will remain false (and vice versa) when the other condition is doing its evaluation on all the other bars..
    If its changed on other ticks, its changed for that bar..
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks, ChelseaB for the link. I found my error.
      I am hoping you can help me with adding commission to my backtesting.
      I have already added the commission under Tools - Commissions tab. I have ticked Include commission under Set up in the Strategy Analyzer. Not sure what else to do to get the commission added.
      I am currently on a demo account.

      Thanks

      Comment


        #4
        Hello JulieV,

        Have you applied a Commissions template to the Sim101 account?

        Below is a public link to the help guide.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks, ChelseaB. I missed that documentation in my search. It's all fixed up.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          50 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          69 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X