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 rdtdale, Yesterday, 01:02 PM
          2 responses
          15 views
          0 likes
          Last Post rdtdale
          by rdtdale
           
          Started by TradeSaber, Today, 07:18 AM
          0 responses
          7 views
          0 likes
          Last Post TradeSaber  
          Started by PaulMohn, Today, 05:00 AM
          0 responses
          9 views
          0 likes
          Last Post PaulMohn  
          Started by ZenCortexAuCost, Today, 04:24 AM
          0 responses
          6 views
          0 likes
          Last Post ZenCortexAuCost  
          Started by ZenCortexAuCost, Today, 04:22 AM
          0 responses
          3 views
          0 likes
          Last Post ZenCortexAuCost  
          Working...
          X