Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

System won't do another trade when target/stop in place

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

    System won't do another trade when target/stop in place

    My strategy enters via EnterLongLimit or EnterShortLimit. The exit strategy is put in place on MarketPosition.Long with ExitLongLimit/ExitLongStop or MarketPosition.Short with ExitShortLimit/ExitShortStop.

    Here is the problem. For example, if the system is short and a target or stop has not been hit, and the system becomes buy ready, the buy limit order to reverse does not work! However, it does reverse, if in the code I remove all targets and stops totally. So, it seems like, when targets or stops are in, it won't make another trade until they are met. Any ideas of why that would be? Also, I am using fromEntrySignal and fromSignalName to tie the longs and short together.

    Thanks!
    lawyse
    NinjaTrader Ecosystem Vendor - Affordable Indicators

    #2
    From Page 440 in the manual:

    Methods that generate orders (excluding market orders) to
    enter a position will be ignored if:

    A position is open and an order submitted by an exit method (ExitLongLimit() for example)
    is active and the order is used to open a position in the opposite direction

    A position is open and an order submitted by a set method (SetStopLoss() for example) is
    active and the order is used to open a position in the opposite direction

    The strategy position is flat and an order submitted by an enter method (EnterLongLimit()

    for example) is active and the order is used to open a position in the opposite direction

    So, how CAN I do this? There has to be a way!


    Originally posted by lawyse View Post
    My strategy enters via EnterLongLimit or EnterShortLimit. The exit strategy is put in place on MarketPosition.Long with ExitLongLimit/ExitLongStop or MarketPosition.Short with ExitShortLimit/ExitShortStop.

    Here is the problem. For example, if the system is short and a target or stop has not been hit, and the system becomes buy ready, the buy limit order to reverse does not work! However, it does reverse, if in the code I remove all targets and stops totally. So, it seems like, when targets or stops are in, it won't make another trade until they are met. Any ideas of why that would be? Also, I am using fromEntrySignal and fromSignalName to tie the longs and short together.

    Thanks!
    lawyse
    NinjaTrader Ecosystem Vendor - Affordable Indicators

    Comment


      #3
      Hi lawyse,

      Have you tried incorporating CancelOrder() into your strategy?

      Comment


        #4
        // IF WE ARE FLAT, GET READY TO BUY OR SELL //

        if (Position.MarketPosition == MarketPosition.Flat)
        {
        if (buyready == true)
        {
        EnterLongLimit(quantity,(EMA(TriggerEMA)[0] + entryAdjust));
        }

        if (sellready == true)
        {
        EnterShortLimit(quantity,(EMA(TriggerEMA)[0] - entryAdjust));
        }
        }

        // IF WE ARE LONG, SET STOP AND TARGET OR ENTRY TO REVERSE SHORT //

        if (Position.MarketPosition == MarketPosition.Long)
        {
        ExitLongStop(quantity, Position.AvgPrice - stop); //always have a stop in
        if (sellready == true) //get ready to reverse
        {
        // EnterShortLimit(quantity,(EMA(TriggerEMA)[0] - entryAdjust), "EDGE Short");
        // ExitLongLimit(quantity, (EMA(TriggerEMA)[0] - entryAdjust));
        // ExitLongLimit(quantity, (EMA(TriggerEMA)[0] - entryAdjust));
        ExitLongLimit(quantity*2, (EMA(TriggerEMA)[0] - entryAdjust));

        }
        if (sellready == false) //use target
        {
        ExitLongLimit(quantity, Position.AvgPrice + target);
        }
        }

        // IF WE ARE SHORT, SET STOP AND TARGET OR ENTRY TO REVERSE LONG //

        if (Position.MarketPosition == MarketPosition.Short)
        {

        ExitShortStop(quantity, Position.AvgPrice + stop); //always have a stop in
        if(buyready == true) //get ready to reverse
        {
        // EnterLongLimit(quantity,(EMA(TriggerEMA)[0] + entryAdjust), "EDGE Long");
        // ExitShortLimit(quantity, (EMA(TriggerEMA)[0] + entryAdjust));
        // ExitShortLimit(quantity, (EMA(TriggerEMA)[0] + entryAdjust));
        ExitShortLimit(quantity*2, (EMA(TriggerEMA)[0] + entryAdjust));
        }
        if(buyready == false) //use target
        {
        ExitShortLimit(quantity, Position.AvgPrice - target);
        }
        }
        lawyse
        NinjaTrader Ecosystem Vendor - Affordable Indicators

        Comment


          #5
          This code works in Market Replay... for example, when it reverses from short to long, it will buy double the contracts (to exit the contracts from the short and get long)

          BUT

          When backtesting, it does not reverse totally, it only buys the contacts to close out the short.

          WHY? Thanks!
          lawyse
          NinjaTrader Ecosystem Vendor - Affordable Indicators

          Comment


            #6
            Hi lawyse, we would appreciate if you could use the

            Code:
            i am code
            markers to post NinjaScript code in the future, much easier to follow!

            Please Print() statements in your code to debug the trading logic leading to your signals, you can also attach a strategy export here and I will take a look later.

            See also this Tip on debugging - http://www.ninjatrader-support2.com/...ead.php?t=3418

            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