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

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:	209
Size:	110.6 KB
ID:	1154937Click image for larger version

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

    Click image for larger version

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

Name:	Screenshot_8.jpg
Views:	177
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.
    JimNinjaTrader Customer Service

    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 PhillT, Today, 02:16 PM
      2 responses
      3 views
      0 likes
      Last Post PhillT
      by PhillT
       
      Started by Kaledus, Today, 01:29 PM
      3 responses
      10 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by frankthearm, Yesterday, 09:08 AM
      14 responses
      47 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by gentlebenthebear, Today, 01:30 AM
      2 responses
      14 views
      0 likes
      Last Post gentlebenthebear  
      Started by PaulMohn, Today, 12:36 PM
      2 responses
      17 views
      0 likes
      Last Post PaulMohn  
      Working...
      X