Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IORDERS NOT Working

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

    #16
    Hello ginx10k,

    We need to add the liveUntilCancelled bool as true to these orders as they are being cancelled on the next bar after they are submitted.

    For example:
    Code:
    sellStopOrder1 = ExitShortStop(0, true, DefaultQuantity, High[1] - (stopLoss * TickSize), "exitShortLimit", "sellTrade1");
    Using the syntax:
    Code:
    ExitShortStop(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double stopPrice, string signalName, string fromEntrySignal)

    Comment


      #17
      That's one thing that confuses me. If the order is love until cancelled. When is it cancelled? I mean. This is exactly what I'm looking for. 1. Down bar closes sell trade is fired. 2. Next bar closes down. I want stop to move down. 3. I want a take profit to be hit if price continues down another bar.

      I don't want orders to be confused w each other. Just want to know when is it live till cancelled?

      Will a reversal bar cancel them. Will the stop being hit cancelled them?

      Comment


        #18
        Hello ginx10k,

        Thank you for your response.

        You can use CancelOrder() to cancel any orders that you need to: http://www.ninjatrader.com/support/h...ancelorder.htm

        Using the IOrder objects you can re-submit the orders to new levels by using the same IOrder object name. So you can move the stop down in your example and make sure the take profit is running when it needs to.

        When you reverse you would want to cancel any orders that would not be valid for the new position.

        Any order filling will need to be set to null for the IOrder object and then you would need logic to cancel the remaining orders as your own OCO system.

        Comment


          #19
          Figured Out Most of It

          Okay so I pretty much got the strategy to work. just one thing for Now that's bugging me

          Code:
            protected override void OnExecution(IExecution execution)
                  {
          if (shortEntryOrder1 != null && shortEntryOrder1 == execution.Order)
          			{
          				if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
          				{
          					
          					//STEP 1: Take Profit
          				//	sellTargetOne = ExitShortLimit( Close[0] - (  profitTarget * TickSize), "sellTrade1");
          					sellTargetOne = ExitShortLimit(0, true, execution.Order.Filled,  Close[0] - (  profitTarget * TickSize), "Short1ProfitTarget", "sellTrade1");
          				
          					//STEP 2: STOP LOSS
          					//If Previous DownBar had No Wick use the High of that Bar
          					if((High[0] - 10 * TickSize) < Open[0])
          								{ 	//Set Stop Live Until Cancelled at Previous Bar's Low 
          									sellStopOrder1 = ExitShortStop(0, true, execution.Order.Filled, High[0] + (stopLoss * TickSize), "Short1Stop", "sellTrade1");
          								}
          					//If Previous Down-Bar Had Wick use Reversal Close
          					else if((High[0] - 10 * TickSize) >= Open[0])
          								{	//Set Stop Live Until Cancelled at Bar's Reversal Close
          									sellStopOrder1 = ExitShortStop(0, true, execution.Order.Filled,  Close[0] + ( (rangeToReverse + 2) * TickSize), "Short1Stop", "sellTrade1");	
          								}
          					
          								
          					// Resets the shortEntryOrder1 object to null after the order has been filled
          					if (execution.Order.OrderState != OrderState.PartFilled)
          					{
          						shortEntryOrder1 	= null;
          					}
          				}
          			}
          			
          			// Reset our stop order and target orders' IOrder objects after our position is closed.
          			if ((sellStopOrder1 != null && sellStopOrder1 == execution.Order) || (sellTargetOne != null && sellTargetOne == execution.Order))
          			{
          				if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
          				{
          					sellStopOrder1 = null;
          					sellTargetOne = null;
          					
          				}
          			} 
          }
          It takes Orders and sets Stops and T.P properly. However, because of this line
          Code:
          if (execution.Order.OrderState != OrderState.PartFilled)
          					{
          						shortEntryOrder1 	= null;
          					}
          It resets the ShortEntryOrder and allows strategy to Take a 2nd Entry Order when the next bar Closes down even before reaching my Profit Target.

          I tried to change that reset to this area and deleted it from previous area
          Code:
          if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
          				{
          					sellStopOrder1 = null;
          					sellTargetOne = null;
          					shortEntryOrder1 	= null;
          				}
          			}
          But all it does is give me a Blank Chart with No Orders on it at all.

          This 2nd entry is a problem, because it will take First entry at 1000 Contracts, and Set Stop and Take Profit at 1000 contracts, but when bar closes Down, and it Enters another 1000 contracts the TP and S.L are still at 1000 Contracts each. so it'll close those out but leave 1000 contracts Open.

          Now before you suggest using a if(Position.MarketPosition != MarketPosition.Short), I want you to note that I do intend on adding another ShortEntryOrder2 that will take another trade at bar close (Even if in Current Open Short Position).

          So all I am asking is How do I Stop ShortEntry1 from taking orders until a Stop or T.P is filled.

          This is something else I attempted but didn't work:
          1. I created a bool shortTrade1Open;

          and Tried to set it to True only during the part of Execution after order is filled
          Code:
          	// Resets the shortEntryOrder1 object to null after the order has been filled
          					if (execution.Order.OrderState != OrderState.PartFilled)
          					{
          						shortEntryOrder1 	= null;
          						shortTrade1Open = true; 
          					}
          //Only sets it to False after a Stop or T.P was hit and trade is Closed
          // Reset our stop order and target orders' IOrder objects after our position is closed.
          			if ((sellStopOrder1 != null && sellStopOrder1 == execution.Order) || (sellTargetOne != null && sellTargetOne == execution.Order))
          			{
          				if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
          				{
          					sellStopOrder1 = null;
          					sellTargetOne = null;
          					shortTrade1Open = false; 
          				}
          			}
          This also Gives me a Blank Orders on chart.

          I'm Now Stuck.

          Comment


            #20
            Hello ginx10k,

            Thank you for your response.

            Have you added the bool to the entry condition?
            Code:
            		if (shortEntryOrder1 == null && Close[0] < Open[0] && !shortTrade1Open)
            			{	
            				shortEntryOrder1 = EnterShortStop(scalpLotSize, Close[0] - (entryTrigDist * TickSize), "sellTrade1");  
            				
            			}

            Comment


              #21
              YES. No effect. it just made no trades

              Comment


                #22
                Hello ginx10k,

                Thanks ginx10k for the response. Can you supply the newly edited strategy for testing?

                Comment


                  #23
                  It has been ReUploaded now.

                  Notice the longTrade1Open and shortTrade1Open Bool Variables. Notice when I set them to False and True. and Notice how it will show trades Long Trades working but No Selling.

                  I just have NO idea what's going on. Please help
                  Attached Files

                  Comment


                    #24
                    Hello ginx10k,

                    I was able to produce trades with this strategy in the Strategy Analyzer. Have you ran a backtest for the strategy or are you running your tests on real-time?

                    Comment


                      #25
                      Patrick I understand what you mean. However I'm not having problems with back testing. I'm only having problems with forward testing. If u don't do the same as I then u can't see the error. Back testing forex does not work the same. I already learned this the hard way. Place the strategy on a chart. Gbp/jpy or something fast. And wait till market moves fast. You'll see how it'll fill the first entry. Then if it retraced before reaching take profit it'll fill another same entry. I showed u my settings on previous post so u see I have one entry direction.

                      And I even pointed out that it's possibly the part of code that Resets LongEntryorder1 after it's been filled.

                      However. When I tried to change that part of code I get blank chart no results.

                      Please look a bit deeper. I'm so close to perfection but can't fix this problem.

                      Comment


                        #26
                        RESETTING to Null

                        Okay. I have a question that I hope will get answered without further confusion. If this part of the code
                        Code:
                        					// Resets the longEntryOrder1 object to null after the order has been filled
                        					if (execution.Order.OrderState != OrderState.PartFilled)
                        					{
                        						longEntryOrder1 	= null;
                        					}
                        Sets the LongEntryOrder = null; after the order has been filled. Does anyone Think that this is why I'm having a problem.

                        Let me try to break this down to hopefully get more clarification.

                        Step 1: If longEntryOrder1 == null && UpBar Closes --> EntryLongStop is set 5 pipettes above Close of Range UpBar.
                        Step 2: Price fills Order
                        Step 3: The part of code shown above Resets longEntryOrder1 = null;
                        Step 4: Price doesn't close Up next bar, it retraces back down
                        Step 5: After retracement down there is another BuyStop set 5 pipettes above Close (this is NOT seen on backTest, because after bar closes and Chart is Refreshed it looks as if this never happened. I see it during Live Forward Trading anytime price moves really fast.

                        Those 5 steps are what has been killing me.

                        I tried removing that part of the code, but it leaves Chart with NO trades at all. I've also tried to place a Bool Variable that will NOT take trades if Bool is True. and the only way to Reset it to false is after a Trade closed. that should be in last upload of strategy that I sent.

                        My Question is simple: HOW DO I STOP ALLOWING THE longEntryORder to be reset to null until after the Trade is actually Closed?

                        Please help, someone has to know the answer to this one.

                        Comment


                          #27
                          Hello ginx10k,

                          Originally posted by NinjaTrader_PatrickH View Post
                          Have you ran a backtest for the strategy or are you running your tests on real-time?
                          Thank you for confirming your are "forward testing"/testing on real-time.

                          Originally posted by ginx10k
                          Sets the LongEntryOrder = null; after the order has been filled. Does anyone Think that this is why I'm having a problem.
                          No.

                          Originally posted by ginx10k
                          My Question is simple: HOW DO I STOP ALLOWING THE longEntryORder to be reset to null until after the Trade is actually Closed?
                          Check that the order is filled or cancelled of course.

                          I will continue to test in real-time on this strategy and let you know what I find.

                          You may wish to simplify the code further to try to isolate the issue as well.

                          Comment


                            #28
                            Thanks for taking your time to help me with this.

                            I have a question:
                            when the EnterLongStop code (any code) fires off
                            Code:
                            longEntryOrder1	= EnterLongStop(0, true, scalpLotSize, Close[0] + ( 20  * TickSize), "buyTrade1");
                            Is the Spread added or subtracted from entry.

                            For Instance, I only use Bars based on "Last". But I set this code in, to set Entry One bar in advance, and I noticed that trades are being executed before the bar actually closes. The spread on G/U at the time was .5

                            So I'm wondering If Close[0] = 1.10000 will this EnterLong be set at (1.10000 + ( 20 * TickSize) +- Spread???

                            Comment


                              #29
                              Hello ginx10k,

                              Thank you for your response.

                              The spread would be against you as you need to gain a profit by exiting at the opposite side of the spread.


                              For the strategy, I am seeing long and short trades and exits on stops and profits. Are you testing your strategy in real-time in the Sim101 account and what data provider are you using for the Forex data?

                              Comment


                                #30
                                Stops Problem

                                Okay. I've uploaded latest Version.

                                I am testing it live and Sim and Now Market replay. I have FXCM. I'm Only testing FOREX GBP/USD or GBP/JPY

                                It does Take Trades Now. Problem I'm having is when it takes the "addInSell" or "addInBuy" (you'll see these in the code), it won't set a Proper Stop Loss for these extra trades.

                                The Original entry ("buyTrade1" and "sellTrade1" ) work just fine.

                                Step 1: FIrst UpBar Closes --> buyTrade1 fires and Stops and T.P are set
                                Step 2: a Future entry ("addInBuy") is Set in case price reaches that level
                                Step 3: when that ("addInBuy") is triggered, the Take profit is Set right away and by then the Stop Loss on ("buyTrade1") is already moved.

                                So at this point I'll have 2 positions Open and 2 separate Take Profits but Only 1 Stop for 1 position.

                                Any suggestions??? (Please review my code) I've simplified it as much as possible and its labeled Step by Step.

                                P.S. In Ninja Options --> Quote currencies (FX) in: "TenthPip".
                                Use a 40 tick Renko chart or 40 tick Range Chart on GBP/USD. and market replay or Forward Test only please.

                                Thank you! so much for support
                                Last edited by ginx10k; 04-08-2015, 02:54 AM. Reason: added a step

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                647 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                368 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                108 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                571 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                573 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X