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 Mindset, 04-21-2026, 06:46 AM
          0 responses
          90 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          135 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          68 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          120 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          69 views
          0 likes
          Last Post PaulMohn  
          Working...
          X