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

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 maybeimnotrader, Yesterday, 05:46 PM
          1 response
          18 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Perr0Grande, Yesterday, 08:16 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by f.saeidi, Yesterday, 08:12 AM
          3 responses
          25 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by algospoke, Yesterday, 06:40 PM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by quantismo, Yesterday, 05:13 PM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X