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

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

    Click image for larger version

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

Name:	Screenshot_8.jpg
Views:	41
Size:	92.6 KB
ID:	1154940

    #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 ;-)

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NinjaTrader_Kate, Today, 02:40 PM
      0 responses
      2 views
      0 likes
      Last Post NinjaTrader_Kate  
      Started by aligator, Today, 02:09 PM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_Kate  
      Started by patpat, Today, 11:34 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_ChrisL  
      Started by crystalet, Today, 10:41 AM
      3 responses
      14 views
      0 likes
      Last Post crystalet  
      Started by tonynt, Today, 10:47 AM
      3 responses
      15 views
      0 likes
      Last Post NinjaTrader_ChrisL  
      Working...
      X