Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SerializeObjectExample

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

    SerializeObjectExample

    Hi, I look at the example "SerializeObjectExample" and have 2 questions:
    1. The line is saved as it should. When the strategy is reloaded, there is a red line. How can this line be deleted without deleting the strategy?
    2. I tried to save a horizontal line instead of a normal line then I get an error message: Strategie 'SerializeObjectExample': Error on calling 'OnStateChange' method: Sie greifen mit einem ungültigen Wert auf einen Index zu, der außerhalb des erwarteten Bereichs ist. Z.B. Zugriff auf eine Reihe mit [BarsAgo] mit einem Wert von 5, wenn nur 4 Kerzen im Chart vorhanden sind. I know what the error message means, but not how I can fix the error, does anyone have a tip for me?


    Click image for larger version

Name:	Screenshot_3.jpg
Views:	277
Size:	110.6 KB
ID:	1154937Click image for larger version

Name:	Screenshot_7.jpg
Views:	245
Size:	68.0 KB
ID:	1154938

    Click image for larger version

Name:	Screenshot_4.jpg
Views:	240
Size:	109.9 KB
ID:	1154939Click image for larger version

Name:	Screenshot_8.jpg
Views:	244
Size:	92.6 KB
ID:	1154940
    sidlercom80
    NinjaTrader Ecosystem Vendor - Sidi Trading

    #2
    Hello sidlercom80,

    Thanks for your post.

    Please note that the approach described in the example you describe uses C# code that is not standard NinjaScript. While the example was originally intended to be helpful, serializing objects on your own would be outside of our scope of support. In a supported manner, we would suggest leaving serializable objects public and to handle non-serializable objects by converting them to something that is serializable, like Brushes, or to store serializable properties that can then be used to recreate the non-serializable object.

    How brushes are serialized in NinjaTrader 8 - https://ninjatrader.com/support/help...lor_inputs.htm

    When a line is drawn from NinjaScript, it will be owned by that NinjaScript. When this example redraws the line, it becomes NinjaScript owned and if the line gets deleted the strategy would then become disabled. There is not a supported means to remove a drawing object that was drawn from NinjaScript.

    The example is a bit old, but you may have more luck trying what is done in State.Realtime, after making it accept HorizontalLines. (Drawing methods may use BarsAgo logic internally, and if you try to do something in State.Historical before bars are processed, that internal BarsAgo logic may fail. I tested the script in State.Realtime after changing it to use Horizontal lines and it worked for me.

    If you have any other inquiries, please don't hesitate to open a new ticket.

    Comment


      #3
      Hello _Jim, thank you for your detailed answer! That with the state.realtime was a good tip ;-)
      sidlercom80
      NinjaTrader Ecosystem Vendor - Sidi Trading

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      52 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X