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

Public class to insert orders

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

    Public class to insert orders

    Hi,

    I'm trying to use a public class to insert/cancel orders (without using ATM).
    I created a public class in an indicator and use it to pass strings or entry prices to a strategy, generating orders.

    I've no problem to insert orders but I cannot find a way to cancel them.

    Here is my class:

    Code:
    public class Global {
    	public static string command1 = string.Empty;	
    	public static double stopPriceLong1=0;
    	}
    and following is how I'm managing orders:

    Code:
     protected override void OnBarUpdate()
    {
    		// insert Long Order
    		if (longOrder1 == null) 
    			{
    			if (Global.command1.Contains("BuyStop"+ Convert.ToString (instrument)))
    				{			
    				enterLong1 = Global.stopPriceLong1;				
    				longOrder1 = EnterLongStop(1,enterLong1,"LONG "+Convert.ToString (instrument));					
    				}	
    			}
    
    
    if (longOrder1.OrderState == OrderState.PendingSubmit) 
    			{
    			if (Global.command1.Contains("Cancel"+ Convert.ToString (instrument)))					
    						{
    						CancelOrder(longOrder1);
    						
    						}
    			}
    
    }
    Both entry and delete are included under OnBarUpdate.

    If I leave only the entry stop order code, it insert the order regularly, but I need to pass a value also to delete the order but the above code does not work when the delete code strings are included.

    Does someone have any suggestion?

    Thanks

    #2
    Hello MAX,
    Unfortunately its more of a C# query and beyond what we could support.

    I will however leave the thread open for our forum members who can give their valuable inputs.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Originally posted by MAX View Post
      ...
      Code:
      if (longOrder1.OrderState == OrderState.PendingSubmit) ...
      What about if the order has already been submitted (i.e., working), or even just accepted, for that matter?

      Some judicious Print() statements might help you find the correct OrderState's to handle in your code?
      Last edited by koganam; 01-02-2013, 01:47 PM.

      Comment


        #4
        I omitted to include them, but I've printed the status.

        I checked it's correct. I rather think could be a problem of including the order handling under OnBarUpdate.

        Infact the output printed this message: **NT** Error on calling 'OnBarUpdate' method for strategy MyStrategy03/a0b120a230c74b7a98520f768709353f': Object reference not set to an instance of an object.

        Probably could be necessary to use OnOrderUpdate, but I don't know how to cope with it.

        Thanks.

        Comment


          #5
          Uh, not much code here to work with... but it looks like what you're trying to do is pretty dangerous... at least from the perspective of coding defensively.

          There should not be a problem dealing with orders inside of OnBarUpdate...

          But don't think that you *must* do your order processing inside of OnBarUpdate either...

          You could just cancel your order from where ever you are setting the cancel text in your 'Global' class... instead of waiting for OnBarUpdate to be called.

          Just a thought....

          Sprinkle some more Prints around to figure out where you are referencing the bogus object...

          Comment


            #6
            Thanks for your thoughts BigWaveDave, but what do you mean exactly with "dangerous for coding defensively"?

            Comment


              #7
              Your use of 'statics' here exposes your code to potential bugs.

              I don't know exactly how your code is structured... but...

              What happens if you run more than one instance of your strategy?

              Comment


                #8
                You are right BigWaveDave. I'm working to allow the strategy run more than once.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by OllieFeraher, 05-09-2024, 11:14 AM
                5 responses
                16 views
                0 likes
                Last Post MisterTee  
                Started by jackiegils, Yesterday, 11:05 PM
                1 response
                10 views
                0 likes
                Last Post marcus2300  
                Started by Skifree, Today, 02:50 PM
                0 responses
                8 views
                0 likes
                Last Post Skifree
                by Skifree
                 
                Started by owen5819, Today, 02:24 PM
                1 response
                12 views
                0 likes
                Last Post owen5819  
                Started by Skifree, 05-07-2024, 11:38 PM
                2 responses
                28 views
                1 like
                Last Post Skifree
                by Skifree
                 
                Working...
                X