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

Method call problem within OnBarUpdate()

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

    Method call problem within OnBarUpdate()

    Hi there,

    I'm running into an issue where, within OnBarUpdate, I try to call the following code:

    Code:
    private void Stop_EndStrategy()
    			{
    				Stop_GoFlat();
    				
    				//  If no long/short positions, halt processing.
    				if (Position.MarketPosition == MarketPosition.Flat)
    				{	haltProcessing = true;	}
    			}
    Whenever I do this, the editor throws back both a "} expected" error and a "Type or namespace definition, or end of file expected" error.

    If I take this bit of code out of the "protected override void OnBarUpdate()" section, everything compiles fine.

    I checked the NT8 help files, but I'm wondering if I'm putting this method in the wrong place.

    Can anyone help give some perspective?

    #2
    Hello Spiderbird,

    Thank you for your note.

    Without the full code I would be unable to know exactly what the issue is.

    Below is a sample which demonstrates how to halt a strategy from processing.


    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by Spiderbird View Post
      Hi there,

      I'm running into an issue where, within OnBarUpdate, I try to call the following code:

      Code:
      private void Stop_EndStrategy()
      			{
      				Stop_GoFlat();
      				
      				//  If no long/short positions, halt processing.
      				if (Position.MarketPosition == MarketPosition.Flat)
      				{	haltProcessing = true;	}
      			}
      Whenever I do this, the editor throws back both a "} expected" error and a "Type or namespace definition, or end of file expected" error.

      If I take this bit of code out of the "protected override void OnBarUpdate()" section, everything compiles fine.

      I checked the NT8 help files, but I'm wondering if I'm putting this method in the wrong place.

      Can anyone help give some perspective?
      Whereas C#7 now does allow one to define "local functions' that are private and scoped to another method, I really find it hard to see why you need it here, and in any case, the syntax is not quite what you have shown. Example ref: https://blogs.msdn.microsoft.com/dot...in-csharp-7-0/

      Much better, will be to define your method outside any other method, in class scope. I would suggest that you take the method code out of the OnBarUpdate() handler.

      Comment


        #4
        Hi Koganam,

        That did the trick (moving the code out of OnBarUpdate). Thanks for the C#7 reference as well.
        Appreciate the help!

        - R

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CortexZenUSA, Today, 12:53 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by CortexZenUSA, Today, 12:46 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by usazencortex, Today, 12:43 AM
        0 responses
        5 views
        0 likes
        Last Post usazencortex  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        168 responses
        2,266 views
        0 likes
        Last Post sidlercom80  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        13 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X