Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Automated strategies not working right?

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

    Automated strategies not working right?

    I have been experiencing problems with getting most of my strategies to correctly enter and exit. I am sure this may be my fault as I still trying to regain my programming skills. But for the purpose of this simple example I even tried too more or less hard code it without parameters and still can't get it to work right.
    It won't exit if the 5 SMA is below the close? I have attached a picture below


    // Condition set 1
    if (Close[0] > SMA(200)[0]
    && Close[
    0] < SMA(5)[0]
    && High[
    2] < High[3]
    && Low[
    2] < Low[3]
    && Low[
    1] < Low[2]
    && High[
    1] < High[2]
    && High[
    0] < High[1]
    && Low[
    0] < Low[1])
    {
    EnterLongLimit(DefaultQuantity, Close[
    0], "");
    }
    // Condition set 2
    if (Close[0] > SMA(5)[0])
    {
    ExitLongLimit(Close[
    0], "", "");
    }
    }

    If you look at the attached picture the buy at 50.21 should have exited 7 or 9 bars later when it closed higher then the 5 day SMA but it didn't it waited much longer
    Attached Files

    #2
    Hello,

    Thank you for your post.

    Is this from a real-time trade or is this in backtesting?

    If you are backtesting, I would suggest enabling the TraceOrders property and backtesting again to see if this provides any additional information as to why the ExitLongLimit was ignored until several bars later.

    Please see our Forum Post on TraceOrders for more information:

    http://www.ninjatrader.com/support/forum/showthread.php?t=3627
    MatthewNinjaTrader Product Management

    Comment


      #3
      Matthew,

      Thank you for your response, I appreciate you showing me the TraceOrders functionality. I received the following output:

      6/15/2011 12:00:00 AM Entered internal PlaceOrder() method at 6/15/2011 12:00:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=0 LimitPrice=55.11 StopPrice=0 SignalName='' FromEntrySignal=''
      6/16/2011 12:00:00 AM Cancelled expired order: BarsInProgress=0: Order='NT-00110/Backtest' Name='Sell' State=Working Instrument='QQQ' Action=Sell Limit price=55.11 Stop price=0 Quantity=0 Strategy='ThreeDayHighLowLS' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='18f962c2f0f1433aab00225f3cb8c83f' Gtd='12/1/2099 12:00:00 AM'

      It appears my sell at the close order did not get executed? This seems to happen on a rare occasion during the backtest. Is there anyway to fix this? Can I change my sell at the close to market and not limit? Can I force it to accept the closing price? I don't understand why it would not fill at the close sometimes?

      Comment


        #4
        Hello,

        When using a managed ExitLongLimit, the default behavior is to cancel the order once the condition is no longer true. However, you can change this behavior by following the following sample on this subject:




        Please let me know if you have additional questions.
        MatthewNinjaTrader Product Management

        Comment


          #5
          Sometimes won't get close?

          Matthew,

          I guess what I don't understand is why am I not getting the close that day? It seems strange that 95% of the time my close order is being filled and 5% it is not? For the sake of backtesting why would it not get filled at the close? What logic prevents this fill?

          I guess I am wondering why is the condition not true, its a close order it should always be true and fill on that days close.

          Comment


            #6
            Your logic is saying to place a Limit order to exit once the Close is greater than the 5 period SMA. From your screen shot you included, this condition is true, however the order is not going to be placed until the bar closes. The next bar never reaches that limit so it will not fill, the close then goes below the 5 period SMA, which cancels the limit order.

            Keep in mind that backtesting will always be Calculated on bar close = true.

            If you would like further clarification on this, I would suggest including some Print() statements, or using draw objects to visual where the limit order is actually being placed to gauge if your logic is meeting your expectations or if something needs to be modified.

            Click here for more information on Debugging NinjaScript Code
            MatthewNinjaTrader Product Management

            Comment


              #7
              So to clarify,

              So because orders aren't execute until the bar closes, you can never backtest a strategy that uses only OHLC data and have it execute at the close because the bar has yet to close? I understand you can do this for intraday data, but most vendors, Kinetick included only go back a few years on intraday data.

              Also, you cannot fill an order at a closed bar price (prior bar) even for the sake of backtesting, because this would be considered backward looking?

              So to summarize, you don't allow interbar order generation (IOG), and you don't allow trades to be filled at past bar prices? (Bar -1) This makes it impossible to test any crossover indicator systems that execute on that days close. (that bar)

              Comment


                #8
                That is correct on a single series - however you can use multi-series scripts for backtesting with intrabar granularity. Please see our Reference Sample on this topic for more information:

                You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by
                MatthewNinjaTrader Product Management

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by GussJ, 03-04-2020, 03:11 PM
                11 responses
                3,227 views
                0 likes
                Last Post xiinteractive  
                Started by andrewtrades, Today, 04:57 PM
                1 response
                13 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by chbruno, Today, 04:10 PM
                0 responses
                7 views
                0 likes
                Last Post chbruno
                by chbruno
                 
                Started by josh18955, 03-25-2023, 11:16 AM
                6 responses
                440 views
                0 likes
                Last Post Delerium  
                Started by FAQtrader, Today, 03:35 PM
                0 responses
                12 views
                0 likes
                Last Post FAQtrader  
                Working...
                X