Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Stops Trading

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

    Strategy Stops Trading

    I am using the following code to execute orders. The strategy enters a position, then stops trading.

    Code:
    [FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (cvalue>avg+increment[/SIZE][/FONT][FONT=Courier New][SIZE=2])
    { 
    Print([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"Short"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (mp1 > -[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])
    { 
    Entry=EnterShortLimit([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],Contracts,Close[/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"Entry"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
    }
    }
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (cvalue<avg-increment[/SIZE][/FONT][FONT=Courier New][SIZE=2])
    {
    Print([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"Long"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (mp1<[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])
    { 
    Entry=EnterLongLimit([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],Contracts,Close[/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"Entry"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
    }
    }
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]else
    [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]{
    Print([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"Cancel"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (Entry!= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])
    CancelOrder(Entry);
    }
    [/SIZE][/FONT]

    #2
    When do you need to cancel the order? On the next bar?
    RayNinjaTrader Customer Service

    Comment


      #3
      Actually disregard, I do not see an exit condition thus your strategy never exits?
      RayNinjaTrader Customer Service

      Comment


        #4
        I need to cancel the order as soon as the conditions are not met. This works properly up until the time when I enter a position. After that, no more orders are sent.

        Comment


          #5
          Originally posted by NinjaTrader_Ray View Post
          Actually disregard, I do not see an exit condition thus your strategy never exits?
          I want the strategy to reverse, not exit.

          Comment


            #6
            Please add "TraceOrders = true" in your Initialize() method. Then run strategy with Output window open.

            Do you see anything like "Ignored to to matching terminal exit order" or something like that?
            RayNinjaTrader Customer Service

            Comment


              #7
              This is the message it gives me when trying to reverse.

              8/21/2008 11:22:22 AM Entered internal PlaceOrder() method at 8/21/2008 11:22:22 AM: Action=SellShort OrderType=Limit Quantity=1 LimitPrice=1.8757 StopPrice=0 SignalName='Entry'FromEntrySignal=''
              8/21/2008 11:22:22 AM Ignored PlaceOrder() method at 8/21/2008 11:22:22 AM: Action=SellShort OrderType=Limit Quantity=1 LimitPrice=1.8757 StopPrice=0 SignalName='Entry'FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'

              Comment


                #8
                That is fine.

                I am looking for entry signal ignore because of terminal matching exit order. This would occur if you have an open entry working but then you have cancelled it.
                RayNinjaTrader Customer Service

                Comment


                  #9
                  I'm not sure I understand.

                  Comment


                    #10
                    Try using different signal names.

                    "EntryLong"
                    "EntryShort"

                    right now you use the same one for both.
                    RayNinjaTrader Customer Service

                    Comment


                      #11
                      I still get the same message ignoring the order. Below is the new code.

                      Code:
                      [COLOR=#0000ff]if[/COLOR][FONT=Courier New][SIZE=2] (cvalue>avg+increment[/SIZE][/FONT][FONT=Courier New][SIZE=2])
                      { 
                      Print([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"Short"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
                      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (mp1 > -[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])
                      { 
                      ShortEntry=EnterShortLimit([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],Contracts,Close[/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"SEntry"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
                      }
                      }
                      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (cvalue<avg-increment[/SIZE][/FONT][FONT=Courier New][SIZE=2])
                      {
                      Print([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"Long"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
                      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (mp1<[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])
                      { 
                      LongEntry=EnterLongLimit([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],Contracts,Close[/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"LEntry"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
                      }
                      }
                      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]else
                      [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]{
                      Print([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"Cancel"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
                      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (LongEntry!= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])
                      CancelOrder(LongEntry);[/SIZE][/FONT]
                      [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][FONT=Courier New][SIZE=2] (ShortEntry!= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])
                      CancelOrder(ShortEntry);[/SIZE][/FONT]
                      }
                      [/SIZE][/FONT]

                      Comment


                        #12
                        SystemTrading,

                        Please provide the full output logs. What we want to look for are the log entries corresponding with the order ignoral for your reversal position.
                        Josh P.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        559 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        324 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        101 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        546 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        547 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X