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 Sparkyboy, Today, 10:57 AM
          0 responses
          1 view
          0 likes
          Last Post Sparkyboy  
          Started by TheMarlin801, 10-13-2020, 01:40 AM
          21 responses
          3,916 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by timmbbo, 07-05-2023, 10:21 PM
          3 responses
          152 views
          0 likes
          Last Post grayfrog  
          Started by Lumbeezl, 01-11-2022, 06:50 PM
          30 responses
          809 views
          1 like
          Last Post grayfrog  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          3 responses
          11 views
          0 likes
          Last Post NinjaTrader_Erick  
          Working...
          X