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

System.Threading.Thread cannot be serialized because it does not have a parameterless

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

    System.Threading.Thread cannot be serialized because it does not have a parameterless

    Hello!

    When I start strategy I getting this error. Just in the process of strategy get this error.

    Default,Failed to execute DB job 'StrategyUpdateJob': There was an error reflecting type 'NinjaTrader.Strategy.Bot'.: Cannot serialize member 'NinjaTrader.Strategy.Bot.t1' of type 'System.Threading.Thread', see inner exception for more details.: System.Threading.Thread cannot be serialized because it does not have a parameterless constructor.,

    #2
    Evggne,

    Thank you for your post.

    Are you adding any thread properties through the strategy?

    If so you may need to add [XmlIgnore()] attribute before it so it does not go into serialization.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      That's part of the code. XML do not use.


      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
      /// <summary>
      /// Enter the description of your strategy here
      /// </summary>
      [Description("Enter the description of your strategy here")]

      public class Bot : Strategy
      {
      ......
      public Thread t1;
      ......
      protected override void Initialize()
      {
      CalculateOnBarClose = true;

      }

      private void LoginCallback(ISession session)
      {
      ....

      t1.Start();
      }

      private OnFailure FailureCallback(string failedFunction)
      {
      .....
      }

      private void SubscribePrice()
      {
      session.MarketDataChanged += MarketDataUpdate;
      session.Subscribe(.......);

      session.Start();
      ......
      }

      public void MarketDataUpdate(OrderBookEvent onOrderBookEvent)
      {
      .......

      DrawHorizontalLine(.....);
      DrawHorizontalLine(.....);


      swAllTextLine = ......

      File.AppendAllText(_filePathAll, swAllTextLine);

      if (.......)
      {
      if (....) { entryOrder = EnterLongStopLimit(.....); } else { entryOrder = EnterLong(.....); }
      }
      if (.....)
      {


      protected override void OnExecution(IExecution execution)
      {
      .............
      }

      public void NotifyStreamFailure(Exception exception)
      {
      ......
      }

      public void NotifySessionDisconnect()
      {
      ....
      }

      protected override void OnBarUpdate()
      {
      try
      {
      if (connect)
      {
      ......
      t1 = new Thread(SubscribePrice);
      t1.Name = t1.ManagedThreadId;
      t1.IsBackground = true;
      Api.Login(loginRequest, LoginCallback, FailureCallback("log in"));
      .....
      }
      if (dissconnect)
      {

      t1.Abort();

      }
      }
      catch (NullReferenceException e)
      {
      ......
      }

      Comment


        #4
        Evggne,

        Try using a private variable instead of a public -
        private Thread t1;

        Does this solve the error?
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Yes, the problem is solved. Thank you very much!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Segwin, 05-07-2018, 02:15 PM
          14 responses
          1,789 views
          0 likes
          Last Post aligator  
          Started by Jimmyk, 01-26-2018, 05:19 AM
          6 responses
          837 views
          0 likes
          Last Post emuns
          by emuns
           
          Started by jxs_xrj, 01-12-2020, 09:49 AM
          6 responses
          3,293 views
          1 like
          Last Post jgualdronc  
          Started by Touch-Ups, Today, 10:36 AM
          0 responses
          13 views
          0 likes
          Last Post Touch-Ups  
          Started by geddyisodin, 04-25-2024, 05:20 AM
          11 responses
          63 views
          0 likes
          Last Post halgo_boulder  
          Working...
          X