Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Translating a v6.0 strategy to 7

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

    #31
    Could it be you were using the StopLimit order option and entered the stop price in the limit price parameter, thus leaving the stop price at 0?

    Comment


      #32
      Most probably, but I cant find any examples of the correct format. Any links?

      Comment


        #33
        maninjapan, there's unfortunately no full sample, but a sample SubmitOrder call for a StopLimit exit could look like this, please note that this would use a StopLimit order with no offset a stop and limit price are the same -

        Code:
         
        SubmitOrder(0, OrderAction.Sell, OrderType.StopLimit, 2, Position.AvgPrice - 10 * TickSize, Position.AvgPrice - 10 * TickSize, "", "ExStopLimit");

        Comment


          #34
          Thanks, Figured that bit out. When I first started the strategy I was using the following condition to start the strategy

          Code:
          if (entryBuyOrder == null)
          however, now that I have worked my way down to the exits and have Buy and Sell orders working simultaneously, it obviously isnt working, as soon as I get filled on a Buy order it keeps entering new entry Buy orders.
          How can I write the statement so that it enters the initial orders on starting the strategy and then doesnt renew the entry order until an exit order has been filled?

          Do I need to move the entry orders to OnExecution as well? They are currently under OnBarUpdate?

          Comment


            #35
            Great progress - you could just add a check in OnBarUpdate() to your order submission conditions to enter only if you're flat (Position.MarketPosition == MarketPosition.Flat) - or you could go more advanced by including a check to the order fillstate of your exitOrder to again submit entries.

            Comment


              #36
              Thanks, slow progress but one step at a time in the right direction. Will just checking if the position status is flat work? Considering unmanaged = true?

              Comment


                #37
                I believe so yes, if you're not flat (exits still working getting executed and you therefore flat) no other entry would be submitting then. You would access the current strategy position with this call.

                Comment


                  #38
                  Before that, looks like I need to add a Cancel order command somewhere to cancel the remaining exit order. (if it hits the stop loss, then the lprofit target order is remaining.) Do I have to add this under On Execution? (I tried to add it in under OnBarUpdate, but recieved an error in the log.

                  Comment


                    #39
                    Correct, you either want to add this in OnExecution(), as your stop reports filled, you can cancelOrder the working target...or you link stop and targets via the OCOString together.

                    Comment


                      #40
                      well one more problem down, one more in its place.....

                      After the entry order is executed it successfully submits the OCO order and this also works as expected. However while waiting for the OCO orders to be executed, I Get an error in the log
                      Error on calling 'OnBarUpdate' method for strategy....
                      Im using a foreign language version of windows but I believe the error translates to NullReferenceException or similar???? Is this caused by a major error in the code and easy to fix or by something more subtle and more difficult to troubleshoot?
                      I dont have any problems with this section before it executes it's first trade.
                      Below is the intro to the OnBarUpdate Section.

                      Code:
                      protected override void OnBarUpdate()
                              {
                         // Submit an entry limit order if we currently don't have an entry order open
                         if (entryBuyOrder == null && Position.MarketPosition == MarketPosition.Flat) 
                         {
                       
                          int now = ToTime(DateTime.Now);
                       
                       
                               int diff = now - this.lastTime;
                       
                               if (diff >= this.waitSecond || diff < 0)
                              {    
                       
                               this.bid = GetCurrentBid();
                                this.ask = GetCurrentAsk();
                       
                       
                                if (this.bid == this.ask) return;
                       
                       
                                this.lastTime = now;
                                  this.Print("bid = " + this.bid + ", ask = " + this.ask);
                              }
                       
                       
                          // Buy
                       
                              entryBuyOrder = SubmitOrder(0,OrderAction.Buy,OrderType.Limit,1,this.bid - this.offsetTicks * TickSize,0,"","Long Limit");
                       
                              // Sell
                       
                             entrySellOrder = SubmitOrder(0,OrderAction.SellShort,OrderType.Limit,1,this.ask + this.offsetTicks * TickSize,0,"","Short Limit"); 
                         }
                       
                            else

                      Comment


                        #41
                        This is likely related to accessing one of the IOrder objects in your code without first checking for it to be not null (empty).

                        Comment


                          #42
                          Trying to work through this one, not getting very far though.
                          The error occurs after an entry order is filled, but not immediately.
                          The fact that the error occurs on calling 'OnBarUpdate', does this mean that I need to be looking for the problem within this section? Or may it also be within the OnExecution section where the exit orders are being handled?

                          Comment


                            #43
                            Likely yes manijapan, please step through your code and check for all objects you try accessing without a check for null before - if you like attach the strategy here or sent it to support and I look it over here.

                            Comment


                              #44
                              Thanks Bertrand, here is the code.
                              Attached Files

                              Comment


                                #45
                                Thanks - I tried on my end and don't see an issue - on which charts / timeframes are you running it?

                                Is this on latest NT7 B19?

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                649 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                370 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                109 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                574 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                576 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X