Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using IOrder to keep an order active

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

    Using IOrder to keep an order active

    I have a strategy which currently compiles and runs, but I have an issue that is complicating my ability to improve this strategy. This is a simple strategy which monitors a series of variables and sets a boolean flag to go long or go short when those conditions are present. Within an acceptable golong or goshort condition I want to enter an order limit. since the conditions can exist for multiple bars, and the order may not fill on one or more of those bars, I need a way to set the goLong and goShort variables to null after a trade is closed, but not when there is an active order in place. To accomplish this I tried using IOrder as follows.
    I put the following statement just above the on order update line:

    Code:
    			private IOrder entryOrder = null;
    and then I added the following code just below the onBarUpdate() line.

    Code:
    			if(entryOrder = null && Position.MarketPosition == MarketPosition.Flat)
    				{
    				goLong.Set(false);
    				goShort.Set(false);
    				}
    As soon as I added these statements the code no longer compiled and I got a lengthy list of errors including:
    CS1513
    CS1518
    CS1041
    CS0116
    CS1001
    CS1022

    The errors include } expected; Expected class, delegate, enum, interface, or struct;
    Identifier expected, 'this' is a key word; A namepsace does not directly contain members such as fields or methods, Identifier expected; and Type or namespace definition, or end-of-file expected.

    Clearly I am not using IOrder properly but I copied it directly from the sample, and I just don't know what I did wrong. Can you offer any guidance, or perhaps there is a different way to reset my goLong goShort variables when the trade is over, without resetting them when flat but a limit order is in place?

    Thanks

    DaveN

    #2
    Hello daven,
    To assist you further may I know is the variable goLong/goShort are boolean values or DataSeries?

    I look forward to assisting you further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      IOrder continued

      I made it a Boolean Data Series:

      Code:
      		private BoolSeries goLong;
      		private BoolSeries goShort;
      Then in the Initialize section:

      Code:
      			goLong = new BoolSeries(this);
      			goShort = new BoolSeries(this);
      Then in the OnBarUpdate Section

      Code:
      			if(Position.MarketPosition == MarketPosition.Flat)
      				{
      				goLong.Set(false);
      				goShort.Set(false);
      				}
      But here is where the problem is, because with the current code, both goLong and goShort get reset to false if there is no open position, but I want the limit entry to endure past one bar because the good entries often occur after a bit of congestion, and that is when I want to enter the order. I need a variable which is true when the long or short conditions continue, even if there is an active order.

      Comment


        #4
        Hello DaveN,
        You have appended the initial code as
        Code:
        if(entryOrder [COLOR="Red"]=[/COLOR] null && Position.MarketPosition == MarketPosition.Flat)
        {
        	goLong.Set(false);
        	goShort.Set(false);
        }
        The correct code will be
        Code:
        if(entryOrder [B]==[/B] null && Position.MarketPosition == MarketPosition.Flat)
        {
           //do stuffs
        }
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          That fixed it, but I had to move the entryOrder initialization into the variables section where it belongs.
          Thanks so much for your help. I really do appreciate it,
          DaveN

          Comment


            #6
            Hello DaveN,
            Thanks for your note.
            Please let me know if I can assist you any further.
            JoydeepNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by AttiM, 02-14-2024, 05:20 PM
            12 responses
            213 views
            0 likes
            Last Post DrakeiJosh  
            Started by cre8able, 02-11-2023, 05:43 PM
            3 responses
            237 views
            0 likes
            Last Post rhubear
            by rhubear
             
            Started by frslvr, 04-11-2024, 07:26 AM
            8 responses
            116 views
            1 like
            Last Post NinjaTrader_BrandonH  
            Started by stafe, 04-15-2024, 08:34 PM
            10 responses
            47 views
            0 likes
            Last Post stafe
            by stafe
             
            Started by rocketman7, Today, 09:41 AM
            3 responses
            11 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X