Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Managing multiple similar entries/SL/BE/trails with IOrder

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

    Managing multiple similar entries/SL/BE/trails with IOrder

    Hi there fellow coders

    I am in the final stage of testing my automated strategy. In total I have 10 different sets of parameters and they all open (scalping) positions from time to time. For now, I allow each set two make two entries, but this number will go up in the future. Depending on the market it is thus possible that a set of entry parameters opens 2 short positions on 2 consecutive (renko) bars. (Or later 5, or 10 even)
    Since both these positions are opened with the same parameters, they have the same amount of ticks for SL/BE and trailing stops.

    And then the problems started :
    The first and second 'SRA'-position did not only take the same amount of ticks as stoploss, but also the same Price level (they both had the name 'SRA', hence why) .
    That is not behaviour that I am looking for. The wise and friendly forum user koganam put me on the right track and I started using IOrder to give every order 'born' from the same set of parameters a different name, like so:

    Code:
    // Condition set 1: Short Red Arrow
                if ([I]//my entry conditions are here[/I]
                    )
                {    if (entryOrder1 == null) {entryOrder1 = EnterShort(1,DefaultQuantity, [COLOR=Red]"SRA1"[/COLOR]);
                        OpSRA = Open[0];
                    Print(Time[0].ToString("dd/MM/yyyy") + ",  " + Time[0].ToString("HH:mm:ss")+ " Short Red Arrow 1 @ " + Close[0]);
                    DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[0] + 65 * TickSize, Color.Red);
                    trailSRA = true;}
                    else if (entryOrder2 == null) {entryOrder2 = EnterShort(1,DefaultQuantity, [COLOR=Red]"SRA2"[/COLOR]);
                    OpSRA = Open[0];
                    Print(Time[0].ToString("dd/MM/yyyy") + ",  " + Time[0].ToString("HH:mm:ss")+ " Short Red Arrow 2 @ " + Close[0]);
                    DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[0] + 65 * TickSize, Color.Red);
                    trailSRA = true;}
                    
                    }
    Recently I got stuck handling the StopLoss for these different positions: I have these lines for initial SL/BE/Trail: (best I could come up with; I wish there was an easier way to handle SL/BE/Trail in NT)
    Code:
    //********* 1. SRA
                //Initial Stop on Open for SRA
                if (trailSRA == true && Position.MarketPosition == MarketPosition.Short  && !initialSetSRA)    
                    {
                    SetStopLoss("[COLOR=Red]SRA[/COLOR]",CalculationMode.Ticks,195,false);
                    initialSetSRA = true;         // set initial stop only once
                    Print(Time[0].ToString("dd/MM/yyyy") + ",  " + Time[0].ToString("HH:mm:ss") +  " Open SL SRA set @ " + (Open[0] + (195 * TickSize)));
                }    
                // Breakeven for SRA
                if (initialSetSRA && !BESetSRA && trailSRA == true && Position.MarketPosition == MarketPosition.Short && Close[0] <= Position.AvgPrice - 195 * TickSize)
                    {
                      SetStopLoss("[COLOR=Red]SRA[/COLOR]",CalculationMode.Price, Close[0] + 195 * TickSize, false); 
                      BESetSRA = true;      // set BE stop once
                    SRATrail = Close[0];
                    Print(Time[0].ToString("dd/MM/yyyy") + ",  " + Time[0].ToString("HH:mm:ss") +  " BE SRA set @ " + (Close[0] + 195 * TickSize));
                    }
                //Trailing Stop during for SRA
                if (BESetSRA && trailSRA == true && Position.MarketPosition == MarketPosition.Short && Close [0] < Close [1])    
                    {
                      SetStopLoss("[COLOR=Red]SRA[/COLOR]",CalculationMode.Price ,Close[0]+(65*TickSize),false);
                       Print(Time[0].ToString("dd/MM/yyyy") + ",  " + Time[0].ToString("HH:mm:ss") +  " Trail SRA adjusted to " + (Close[0]+(65*TickSize)));
                    }
    but this does not work. (the generic 'SRA' does no longer exist since I started using IOrder)

    Here's my question:
    Do I really have to copy this set of SL/BE/Trail-parameters 10 times and rename them to SRA1, SRA2, SRA3,... SRA10 to allow 10 different entries to be handled correctly when it comes to SL/BE/Trail or can this be accomplished in a different way (perhaps with a for... loop ?? Or an array ??)

    Having 10 sets of entry parameters and 10 different blocks of code per set for SL/BE/Trail seems overkill I did browse this forum (and others) for quite some time already, but no luck so far.

    Bonus question: Can I further limit the amount of code so that the names of the different IOrders are given 'automatically' instead of having this line 10 times per entry set ??
    Code:
    else if (entryOrder2 == null) {entryOrder2 = EnterShort(1,DefaultQuantity, [COLOR=Red]"SRA2"[/COLOR]);
    Kudos to all who help / point me in the right direction !!
    Thanks in advance !

    #2
    Hello Spinn,

    Using SetStopLoss() with a fromEntrySignal will still work when using IOrders. The fromEntrySignal has to match the entry order's signalName.

    If you have changed the entry orders entry signalName to SRA1, then the fromEntrySignal for that order also needs to be changed to SRA1.
    SetStopLoss("SRA1",CalculationMode.Ticks,195,false );

    Yes, using these signal names is required when using SetStopLoss so that the exit is only applied to that order.

    Writing each of these calls out is up to you. Just as a suggestion, you could instead use a variable with the signal name. Then you could have a condition select the fromEntrySignal according to which order is processing. After selecting the fromEntrySignal name, as long as you want the same behavior for each order then you could use the same logic for all orders replacing the fromEntrySignal as needed.
    Last edited by NinjaTrader_ChelseaB; 06-20-2016, 08:46 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you very much, NinjaTrader_ChelseaB !!

      I got it working now (the number of lines in my Strategyscript has gone up drastically, but my PC seems to manage, so all is good)

      Another quick question then, since this 'IOrder-business' is new to me:

      How do I check if a position with a specific name exists (as in: I want to know if it is still open or has been stopped out, so I can reset it to be opened again by the script)

      In the past I did this with these lines in the "protected override void OnPositionUpdate(IPosition position)"-block

      Code:
      if (position.MarketPosition == MarketPosition.Flat)
      but this only partially does what I want. The strategy then waits until ALL positions are closed before resetting all of them at once. This way I miss entries, so I want to check for specific entries or names of entries. The goal is to have shorter scalps to open/close while a longer long or short position is open (and stays open) at the same time.

      I did try

      Code:
      if (entryOrder1 == null)
      but that does not work.

      I also tried checking if the name I give a position when I open it ("SRA1") still exists in several ways, but i keep getting errored out.

      I looked at http://ninjatrader.com/support/helpG...t7/?iorder.htm but couldn't figure out how to work it. I have probably been staring at code for too long
      Last edited by Spinn; 06-19-2016, 01:52 PM.

      Comment


        #4
        Hello Spinn,

        There is only one position for the Strategy and this will not have a name.

        However, I think you are asking how to check the order state of an order.

        Code:
        In #region Variables:
        IOrder myOrder = null;
        
        In OnBarUpdate():
        if (myOrder == null)
        myOrder == EnterLong();
        
        in OnOrderUpdate() or where ever you want to know the state of the order:
        if (myOrder != null)
        Print(myOrder.OrderState.ToString());
        
        if (myOrder != null && myOrder.OrderState == OrderState.Filled)
        {
        // execute code
        }
        Below is a link to the help guide on IOrder. Please look for OrderState.
        http://ninjatrader.com/support/helpG...nt7/iorder.htm
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          NinjaTrader_ChelseaB, thank you for your time. Truly appreciated

          Checking the orderState is NOT what I am looking for imo.

          Let me try to clarify:

          I have multiple sets of parameters (8 in total) in one strategy. When I fire up NT and launch my strategy I get for example an opening signal on LONG1. Since no positions are open, the strategy allows LONG1 to be opened. A little while later, the market moves in a similar way and I get another signal (from the same parameter set) and since only one position LONG1 is open at this moment and since I allow "2 unique" a second position is opened. We'll call this one LONG2. 2 similar positions are now open, both 'born' from the same set of parameters.
          Time moves on and the market gives me another signal to go long, this time from a different set op opening parameters. LONG1 and LONG2 are still open, but because I allow 2 Unique positions, a third long is opened, named LONGER1.

          Now, suppose the market moves against me and this youngest position, LONGER1, is stopped out rather quickly, but the other 2, LONG1 and LONG2 stay open.

          I now want to 'nullify' this LONGER1, meaning that I want to reset all the values to their initial setting: BE/SL/Trail but also the fact that my strategy checks for a possible exit (I use "trailSRA" for this in the code I posted before) Right now this process to 'nullify' or re-initialise that specific possible entry is only done when ALL positions are flat (remember: i use "if (position.MarketPosition == MarketPosition.Flat)"), so only after LONG1 and LONG2 are also closed.

          By having to wait until EVERY position is closed and I am effectively flat, I miss entries and I am looking for a way to avoid that. I don't see how this can be done by using OrderState, unless there is a way to check if the close order for a specific position has been filled or not.

          Comment


            #6
            Hello Spinn,

            There will only be one position for the strategy (per instrument). Lets say you place 2 buy entry orders with a quantity of 1 each on the same instrument. This means there is no secondary series of a different symbol added to the script with the Add() call. When the first order fills the position will be long 1. When the second order fills the position will be long 2. As orders fill this will adjust the strategy position.

            When you mention "A little while later, the market moves in a similar way and I get another signal (from the same parameter set) and since only one position LONG1 is open at this moment and since I allow "2 unique" a second position is opened", this is incorrect.

            While a second order will have filled, this will have updated the strategy position and will not have created a second unique position which cannot exist with a strategy or manual orders when the same instrument and same account is selected.

            I still feel that you are wanting to know when the first order or trade is entered and exited as a strategy cannot have multiple positions for the same instrument.

            Are you asking about using a different symbol for the secondary series specifically?

            Below is a link to the help guide on Position.
            http://ninjatrader.com/support/helpG...7/position.htm

            Positions (plural) is used when a secondary series is added to the script that uses a different instrument.Below is a link to Positions.
            http://ninjatrader.com/support/helpG.../positions.htm
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              NinjaTrader_ChelseaB,

              Hmmm, still haven't figured this out. I look at my BreakEven-code:


              Code:
                          // Breakeven for SRA
                          if (initialSetSRA && !BESetSRA && trailSRA == true && Position.MarketPosition == MarketPosition.Short && Close[0] <= Position.AvgPrice - 195 * TickSize)
                              {
                                SetStopLoss("SRA2",CalculationMode.Price, Close[0] + 195 * TickSize, false); 
                                BESetSRA = true;      // set BE stop once
                              SRATrail = Close[0];
                              Print(Time[0].ToString("dd/MM/yyyy") + ",  " + Time[0].ToString("HH:mm:ss") +  " BE SRA2 set @ " + (Close[0] + 195 * TickSize));
                              }
              and I notice that I can check if SRA is a certain amount of ticks above or (in this case) below my initial entry. So even though this "SRA"-position has been opened a while ago and has been added to the 'strategy'-stack of all open positions (where according to you all the open positions are grouped), it is still possible to check for this order specifically if certain conditions are met.

              Is it then really impossible to simply verify if the 'SRA' position is still open / still exists ?? That does not seem logical: if it is possible to check whether or not it is x Ticks below my entry, it must also be possible to check if it is still 'alive' or 'open' or 'in existence'.

              I looked at the 'position'-Object, but that holds the info for all the positions (the complete stack), no ? So I cannot use that to check on the status of a specific position.

              The 'positions'-array (plural) holds info for multiple instruments, but I only use one.

              I am sorry, but I still cannot grasp why what I want to do cannot be done using code

              Comment


                #8
                Hello Spinn,

                Thank you for confirm that you are looking to check the state of an order instead of the strategy position.

                To check the state of an order, use an Order variable type when submitting the order as the order submission method will return an Order object.

                Then use Order.OrderState to check the state of the order.

                Code:
                private IOrder myEntryOrder = null;
                
                if (/* conditions to enter && */ myEntryOrder == null)
                {
                myEntryOrder = EnterLongLimit(Low[0] - 5 * TickSize);
                }
                
                if (myEntryOrder != null && myEntryOrder.OrderState == OrderState.Working)
                {
                Print("myEntryOrder is working at " + myEntryOrder.LimitPrice);
                }
                
                if (myEntryOrder != null && myEntryOrder.OrderState == OrderState.Filled)
                {
                Print("myEntryOrder filled at " + myEntryOrder.AvgFillPrice);
                }
                Below is a link to the help guide on IOrder.
                http://ninjatrader.com/support/helpG...nt7/iorder.htm

                Also, below is a link to a reference sample that demonstrates using IOrder.
                http://ninjatrader.com/support/forum...ead.php?t=7499
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks (again) NinjaTrader_ChelseaB for this information. Very kind of you

                  I am however still facing issues in getting this to work.
                  This afternoon and night I fiddled with code to check the state of an order and I understand the 'OrderState.Filled'-part. By this I mean that I can code my strategy in such a way that it checks whether an order has been filled or not.

                  But -as you no doubt know- an order gets filled on 2 different occasions: when it's opened and again when it's closed.

                  I can't for the life of me figure out what I need to code to 'nullify' an order when the stopLoss has been triggered and the position is exited. (I do not use ExitOrders, all exits are handled by StopLosses) Until now I only succeeded in getting the 'nullify' to work after every OrderState == filled, so also right after an entry.

                  I found this code in another topic http://ninjatrader.com/support/forum...ad.php?t=49433
                  Code:
                  protected override void OnExecution(IExecution execution) 
                  {      if (execution.Order != null && execution.Order.Name == "exitlong3" && execution.order.OrderState == OrderState.Filled)  
                    {        long3 = null;  
                   } }
                  but I keep getting errored out.

                  This is about as far as I got:
                  Code:
                  if (execution.Order != null && execution.Order.Name == "LLA1" && execution.Order.OrderState == OrderState.Filled)
                              {
                                  SetStopLoss("LLA1",CalculationMode.Ticks,225,false);
                                  Print(Time[0].ToString("dd/MM/yyyy") + ",  " + Time[0].ToString("HH:mm:ss")+  " Long Lime Arrow 1 Flat, so SL reset " );
                                  initialSetLLA1 = false;
                                  BESetLLA1 = false;
                                  entryOrder50 = null;            
                              }
                  How can I check if my IOrder with name "entryOrder50" and signal name "LLA1" has been closed, so I can reset it to initial settings ??

                  Comment


                    #10
                    Hello Spinn,

                    An order cannot be filled twice. It is possible for a fill to happen in parts. A part fill is when some of the order has filled but there was not enough volume to completely fill the order. In this situation there would be a remaining quantity.

                    I think you are confusing an individual order with a complete trade.

                    The exchange sees individual orders.
                    For example if you place a buy market order when in a flat position, this will enter into a long position. The exchange fills the buy market order and you are now in a position.
                    Then a second order is placed as a sell market order. This would exit the long position and would bring the position back to flat.
                    The pair of orders the buy market entry order and the sell market exit order would be one trade (in ninjatraders performance).

                    However, a buy market order would not be able to be filled twice.

                    When an order fills, this triggers OnExecution() with the execution and order information. If you find that your order is the order that was executed, this would be a good time to immediately set the IOrder to null (if you strategy depends on them being null to place new entries or if you need them to be set to null for some reason).

                    Below is a link to the help guide on OnExecution().
                    http://ninjatrader.com/support/helpG...nexecution.htm

                    Code:
                    In #region Variables
                    private myOrder;
                    
                    In OnBarUpdate() (or whichever method is placing the orders)
                    if (/* conditions to enter */)
                    {
                    myOrder = EnterLong();
                    }
                    
                    In OnExecution():
                    if (myOrder != null && execution.Order == myOrder)
                    {
                    if (execution.Order.OrderState == OrderState.Filled)
                    {
                    // entry has filled
                    // set the IOrder handle back to null
                    myOrder = null;
                    }
                    else if (execution.Order.OrderState == OrderState.PartFilled)
                    {
                    // entry has part filled.
                    }
                    }
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks you for your input NinjaTrader_ChelseaB. Part of it is more clear now. I looked into using the code you suggested, but it does not seem to do what I am aiming for. I can -obviously- reset myOrder (or 'entryOrder50' as it is called in my strategy) to null right after it has been filled, but then my SL/BE/Trail code would also become obsolete, and no BE/trailing would be performed by my strategy.

                      This is what happens in chronological order imo:

                      1. a bunch of parameters gets triggered
                      2. an enterLong is being launched
                      3. this enterLong gets filled
                      4. my initial SL is being set
                      5. if market moves my way, my BE is being set (slightly above the entry price)
                      6. if market moves far in the direction I want it to, a trail is being initialised and maintained
                      7. eventually price moves against me
                      8. I am stopped out (by price hitting my StopLoss; I don't use exitOrders)

                      Now, if I wanted to nullify this position I would do so after step 8, and NOT -and this is what happens if I nullify right after the entryOrder50 is filled- after step 3


                      I am thus still looking for a way to either see if this entryOrder50, or the position named LLA1 is still alive/open/working/active.


                      So far I've tried

                      • if (entryOrder50 != null && entryOrder50.OrderState == Orderstate.Working) (in OnBarUpdate)
                      • if (entryOrder50 != null && execution.Order == entryOrder50)
                        {
                        if (execution.Order.OrderState != OrderState.Working)
                        } (in OnExecution and in OnPositionUpdate)
                      • checking -by use of TraceOrders = Trueto see if these StopLoss-orders can be called by their names
                      • ...

                      But it seems nothing works. I am starting to think that checking whether a single position (from a strategy that allows several) is still open or not (in order to be ablw to nullify it as soon as it's been closed/stopped out) is not possible

                      This is the output of a 'full circle' of a single order (with Trace Orders on and a few print statements to debug) Perhaps it can be of any use.

                      2-2-2016 5:46:39 Entered internal PlaceOrder() method at 2-2-2016 5:46:39: BarsInProgress=1 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='LLA1' FromEntrySignal=''
                      02-02-2016, 05:46:39 Long Lime Arrow 1 @ 173,315
                      02-02-2016, 05:47:20 $ $ $ Open PnL: 49,9999999999829
                      2-2-2016 5:47:20 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='LLA1' Mode=Price Value=173,105 Currency=0 Simulated=False
                      02-02-2016, 05:47:20 Open SL LLA1 @ AvgFill - 225 = 173,105
                      02-02-2016, 05:50:50 $ $ $ Open PnL: -80,0000000000125
                      02-02-2016, 05:52:11 $ $ $ Open PnL: -145,00000000001
                      02-02-2016, 05:57:16 $ $ $ Open PnL: -15,0000000000148
                      02-02-2016, 05:58:34 $ $ $ Open PnL: 49,9999999999829
                      02-02-2016, 06:13:25 $ $ $ Open PnL: 114,999999999981
                      02-02-2016, 06:14:45 $ $ $ Open PnL: 179,999999999978
                      02-02-2016, 06:16:57 $ $ $ Open PnL: 244,999999999976
                      2-2-2016 6:16:57 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='LLA1' Mode=Price Value=173,53 Currency=0 Simulated=False
                      2-2-2016 6:16:57 Amended stop order: Order='NT-00007/Sim101' Name='Stop loss' State=Working Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=173,53 Quantity=1 Strategy='LiSL210NewStops' Type=Stop Tif=Gtc Oco='NT-00006-1718' Filled=0 Fill price=0 Token='e39f5a81ad6245f483ff36de48e6d818' Gtd='1-12-2099 0:00:00'
                      02-02-2016, 06:16:57 BE LLA 1 set @ 173,53
                      02-02-2016, 06:17:55 $ $ $ Open PnL: 309,999999999974
                      2-2-2016 6:17:55 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='LLA1' Mode=Price Value=173,575 Currency=0 Simulated=False
                      2-2-2016 6:17:55 Amended stop order: Order='NT-00007/Sim101' Name='Stop loss' State=Working Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=173,575 Quantity=1 Strategy='LiSL210NewStops' Type=Stop Tif=Gtc Oco='NT-00006-1718' Filled=0 Fill price=0 Token='e39f5a81ad6245f483ff36de48e6d818' Gtd='1-12-2099 0:00:00'
                      02-02-2016, 06:17:55 Trail LLA 1 adjusted to 173,575
                      02-02-2016, 06:18:13 $ $ $ Open PnL: 375
                      2-2-2016 6:18:13 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='LLA1' Mode=Price Value=173,64 Currency=0 Simulated=False
                      2-2-2016 6:18:13 Amended stop order: Order='NT-00007/Sim101' Name='Stop loss' State=Working Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=173,64 Quantity=1 Strategy='LiSL210NewStops' Type=Stop Tif=Gtc Oco='NT-00006-1718' Filled=0 Fill price=0 Token='e39f5a81ad6245f483ff36de48e6d818' Gtd='1-12-2099 0:00:00'
                      02-02-2016, 06:18:13 Trail LLA 1 adjusted to 173,64
                      02-02-2016, 06:18:19 $ $ $ Open PnL: 439,999999999998
                      2-2-2016 6:18:19 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='LLA1' Mode=Price Value=173,705 Currency=0 Simulated=False
                      2-2-2016 6:18:19 Amended stop order: Order='NT-00007/Sim101' Name='Stop loss' State=Working Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=173,705 Quantity=1 Strategy='LiSL210NewStops' Type=Stop Tif=Gtc Oco='NT-00006-1718' Filled=0 Fill price=0 Token='e39f5a81ad6245f483ff36de48e6d818' Gtd='1-12-2099 0:00:00'
                      02-02-2016, 06:18:19 Trail LLA 1 adjusted to 173,705
                      02-02-2016, 06:30:30 $ $ $ Open PnL: 504,999999999995
                      2-2-2016 6:30:30 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='LLA1' Mode=Price Value=173,77 Currency=0 Simulated=False
                      2-2-2016 6:30:30 Amended stop order: Order='NT-00007/Sim101' Name='Stop loss' State=Working Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=173,77 Quantity=1 Strategy='LiSL210NewStops' Type=Stop Tif=Gtc Oco='NT-00006-1718' Filled=0 Fill price=0 Token='e39f5a81ad6245f483ff36de48e6d818' Gtd='1-12-2099 0:00:00'
                      02-02-2016, 06:30:30 Trail LLA 1 adjusted to 173,77
                      02-02-2016, 06:33:41 $ $ $ Open PnL: 569,999999999993
                      2-2-2016 6:33:41 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='LLA1' Mode=Price Value=173,835 Currency=0 Simulated=False
                      2-2-2016 6:33:41 Amended stop order: Order='NT-00007/Sim101' Name='Stop loss' State=Working Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=173,835 Quantity=1 Strategy='LiSL210NewStops' Type=Stop Tif=Gtc Oco='NT-00006-1718' Filled=0 Fill price=0 Token='e39f5a81ad6245f483ff36de48e6d818' Gtd='1-12-2099 0:00:00'
                      02-02-2016, 06:33:41 Trail LLA 1 adjusted to 173,835
                      02-02-2016, 06:33:46 $ $ $ Open PnL: 634,999999999991
                      2-2-2016 6:33:46 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='LLA1' Mode=Price Value=173,9 Currency=0 Simulated=False
                      2-2-2016 6:33:46 Amended stop order: Order='NT-00007/Sim101' Name='Stop loss' State=Working Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=173,9 Quantity=1 Strategy='LiSL210NewStops' Type=Stop Tif=Gtc Oco='NT-00006-1718' Filled=0 Fill price=0 Token='e39f5a81ad6245f483ff36de48e6d818' Gtd='1-12-2099 0:00:00'
                      02-02-2016, 06:33:46 Trail LLA 1 adjusted to 173,9
                      2-2-2016 6:33:46 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='LLA1' Mode=Ticks Value=225 Currency=0 Simulated=False
                      02-02-2016, 06:33:46 Long Lime Arrow 1 Flat, so SL reset @

                      Comment


                        #12
                        Hi Spinn,

                        This was an example of how to set something to null, this was not meant to be code that you can use in your script that knows when to set something to null.

                        When you want the order set to null, set the IOrder variable to null.

                        If you want this to happen after the exit fills, then detect the exit has filled in OnExecution and then set the entry to null.
                        (This is actually how I make a lot of my scripts)

                        When you place the order are you assigning the IOrder that is returned from the entry method to a variable?
                        Is the variable called entryOrder50 or is the signalName "entryOrder50"?

                        Is the variable null when you print?

                        If it is not null, what is the OrderState of the IOrder when you check it?


                        Where are you checking the order state of the object? Is this in OnExecution?

                        Code:
                        if (entryOrder50 != null && entryOrder50 = execution.Order && execution.Order.OrderState == Orderstate.Working)
                        This should work.

                        Also, how do you know the order isn't being filled. The prints in your output appear to be printing a PnL.. This would indicate that an order has filled.


                        Below is a link to an example where I've used IOrders that are reset to null only when the exit order is filled.
                        http://ninjatrader.com/support/forum...t.php?p=465103
                        Last edited by NinjaTrader_ChelseaB; 07-06-2016, 02:50 PM.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Thank you sooooo much for all your help NinjaTrader_ChelseaB !!! I got it working now.

                          The relentless effort of the NinjaTrader staff is what truly makes this platform the best

                          I would click the 'thanksbutton' twice, but the forum won't allow me

                          Please keep up the good work

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by love2code2trade, Yesterday, 01:45 PM
                          4 responses
                          28 views
                          0 likes
                          Last Post love2code2trade  
                          Started by funk10101, Today, 09:43 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post funk10101  
                          Started by pkefal, 04-11-2024, 07:39 AM
                          11 responses
                          37 views
                          0 likes
                          Last Post jeronymite  
                          Started by bill2023, Yesterday, 08:51 AM
                          8 responses
                          44 views
                          0 likes
                          Last Post bill2023  
                          Started by yertle, Today, 08:38 AM
                          6 responses
                          26 views
                          0 likes
                          Last Post ryjoga
                          by ryjoga
                           
                          Working...
                          X