Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Questions on execution of strategy code

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

    Questions on execution of strategy code

    I am in the middle of creating a strategy based on a custom complex indicator. This strategy has two data series. This custom indicator executes on the data from the second data series.

    I am having an issue that doesn't make sense to me. I already wrote this strategy as an indicator and it works perfectly.

    I now have the code moved into a strategy, however, some peculiar results are showing up.

    I have two variables that I use to prevent "double" entries from being taken (entries taken *right* after a profit/stop gets filled). In essence, I only take one trade in one direction and then wait for a trade in the opposite direction to "reset" possible entries in the first direction.

    Here is what it looks like in the strategy:

    Code:
    if (criteria1 and criteria2 and OKForLong)
    
    { 
    
    EnterLong(1);
    
    OKForLong = false;
    
    OKForShort = true;
    
    }
    
    if (criteria3 and criteria4 and OKForShort)
    
    {
    
    EnterShort(1);
    
    OKForShort = false;
    
    OKForLong = true;
    
    }


    This code works perfectly in the indicator but generates NO orders in the strategy. (the indicator places arrows/text on the bars on the chart instead of enter() orders)

    NOW ... when I take out the OKForLong/Short out of the if() statements, all of the correct trade entries get generated (including the double entries of course). BUT ... with them in, no trades at all.

    This tells me that these two variables are not getting reset.

    Couple of things:

    1) These variables are global scope to the strategy

    2) They are reset to true when ToDay(Times[1][0]) != ToDay(Times[1][1]) (A new day starts in the second data series on which my indicator/strategy is driven).

    Any ideas?

    Thanks!

    #2
    imported post

    Not sure how your strategy should work in all details and analyzing complete strategies is beyond the scope of what we can support, but here are some hints:

    - OKForLong and OKForShort need to be initialized to true. If not then your logic never will make it into the if branches
    - printing out values of OKForLong and OKForShort could help
    - is there funny stuff in the logs which would indicate coding bugs
    - Times[1][0] indicates a multi series strategy (Times[1] is the second ! series). Is that your intention? I suggest starting simply as possible with a single series strategy

    Comment


      #3
      imported post

      Thanks Dierk,

      I found out that the Strategy is, in fact, working correctly. HOWEVER, the Strategy Analyzer is what is failing.

      Here is debug code from my Strategy as reported by the output window. I am printing when the OKForLong/Short is reset as well as when the strategy actually goes long/short.

      20070105: Resetting. Longs=True / Shorts=True

      95000 Short

      104500 Long

      143000 Long

      20070108: Resetting. Longs=True / Shorts=True

      91500 Short

      94500 Long

      105000 Long

      111500 Long

      123500 Long

      135000 Short

      145000 Short

      20070109: Resetting. Longs=True / Shorts=True

      94000 Long
      However, I get NO trades listed in the Trades tab, Charts tab or Summary tab in the Strategy Analyzer. Removing the OKForLong/Short from the criteria list, produces the same output but I actually get results in the Analyzer.

      Clues?

      Comment


        #4
        imported post

        Try TraceOrders=true in Initialize() to see what happens to your signals.

        Comment


          #5
          imported post

          Did you check the logs?

          Comment


            #6
            imported post

            Sorry for the delay ... had to step out.

            Thanks for the help so far. Here is what trace reports:

            90500 Short

            Entered internal PlaceOrder() method at 1/4/2007 9:05:00 AM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=se2' FromEntrySignal=''

            Entered internal SetStopTarget() method at 1/4/2007 9:05:00 AM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False

            Entered internal SetStopTarget() method at 1/4/2007 9:05:00 AM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False

            95000 Long

            Entered internal PlaceOrder() method at 1/4/2007 9:50:00 AM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=le2' FromEntrySignal=''

            Entered internal SetStopTarget() method at 1/4/2007 9:50:00 AM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False

            Entered internal SetStopTarget() method at 1/4/2007 9:50:00 AM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False

            110500 Long

            Entered internal PlaceOrder() method at 1/4/2007 11:05:00 AM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=le2' FromEntrySignal=''

            Entered internal SetStopTarget() method at 1/4/2007 11:05:00 AM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False

            Entered internal SetStopTarget() method at 1/4/2007 11:05:00 AM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False

            112000 Short

            Entered internal PlaceOrder() method at 1/4/2007 11:20:00 AM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=se2' FromEntrySignal=''

            Entered internal SetStopTarget() method at 1/4/2007 11:20:00 AM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False

            Entered internal SetStopTarget() method at 1/4/2007 11:20:00 AM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False

            122000 Long

            Entered internal PlaceOrder() method at 1/4/2007 12:20:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=le2' FromEntrySignal=''

            Entered internal SetStopTarget() method at 1/4/2007 12:20:00 PM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False

            Entered internal SetStopTarget() method at 1/4/2007 12:20:00 PM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False

            125000 Short

            Entered internal PlaceOrder() method at 1/4/2007 12:50:00 PM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=se2' FromEntrySignal=''

            Entered internal SetStopTarget() method at 1/4/2007 12:50:00 PM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False

            Entered internal SetStopTarget() method at 1/4/2007 12:50:00 PM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False

            131500 Long

            Entered internal PlaceOrder() method at 1/4/2007 1:15:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=le2' FromEntrySignal=''

            Entered internal SetStopTarget() method at 1/4/2007 1:15:00 PM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False

            Entered internal SetStopTarget() method at 1/4/2007 1:15:00 PM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False

            145000 Short

            Entered internal PlaceOrder() method at 1/4/2007 2:50:00 PM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=se2' FromEntrySignal=''

            Entered internal SetStopTarget() method at 1/4/2007 2:50:00 PM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False

            Entered internal SetStopTarget() method at 1/4/2007 2:50:00 PM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False

            20070105: Resetting. Longs=True / Shorts=True

            95000 Short

            Entered internal PlaceOrder() method at 1/5/2007 9:50:00 AM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=se2' FromEntrySignal=''

            Entered internal SetStopTarget() method at 1/5/2007 9:50:00 AM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False

            Entered internal SetStopTarget() method at 1/5/2007 9:50:00 AM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False
            Still doesn't report any trades in the Analyzer even though they are being entered according to the logs.

            Comment


              #7
              imported post

              I have a hunch:

              My two bar series are two different markets. I get my signals from the second bar series (1) and want to place trades on the first bar series (0).

              When I *don't* check for BarsInProgress == 1, I get trades in the Analyzer when I place EnterXX() orders. When I *do* check and place EnterXX() orders, I don't get trades in the Analyzer.

              My broker does not support trades against the second bar series but *does* for the first bar series. Therefore, I am probably not getting trades listed because the order is being rejected ... even though the logs and trace logs do not report this.

              Question: when I place EnterXX() orders, do these orders automatically get placed against bar series (0) or the bar series generating the call to OnBarUpdate()?

              Can I force the order to a particular symbol or bar series?

              Thanks

              Comment


                #8
                imported post

                BINGO!

                This is the issue I am having.

                I'll figure something out.

                Thanks for the help Dierk!!

                You guys are doing a super job with this platform ... keep it up!!!!

                Comment


                  #9
                  imported post

                  Great. You always you should check the logs first, since they hold messages in case there is something wrong with order placement on "wrong" series.

                  Comment


                    #10
                    imported post

                    Thanks Dierk.

                    Now another question.

                    My strategy is set to execute on the close of the bar and it needs to be that way. However, the strategy trade execution and management is driven from the second data series (BarsArray[1]) BUT it needs to trade the market loaded into the primary data series (BarsArray[0]). Is there ANYWAY this can be done in a NinjaTrader strategy?

                    Before any trade can be entered into, I *must* have a closed bar on BarsArray[1] that my strategy code is executing against.

                    Thanks

                    Comment


                      #11
                      imported post

                      Not that I could think of. However, we will consider that and let you know.

                      Comment


                        #12
                        imported post

                        Thanks Dierk.

                        Anything on this would help. My Strategy is pretty much complete and operational EXCEPT this.

                        Thanks again for the help.

                        Comment


                          #13
                          imported post

                          We discussed this issue but found that changing the implementation now would have serious impact on the stability of the product. However we put this on our list of high priority issues and will provide a soltuion later on this year.

                          Sorry for the inconvenience and thanks for your understanding.

                          Comment


                            #14
                            imported post

                            I understand and agree with your statements.

                            Thank you for all of your help. You guys are doing a terrific job and have done *much* in such a short amount of time.

                            Comment


                              #15
                              Originally posted by NinjaTrader_Dierk View Post
                              We discussed this issue but found that changing the implementation now would have serious impact on the stability of the product. However we put this on our list of high priority issues and will provide a soltuion later on this year.
                              Do you have any ETA on when this may be implemented? If you need assistance in testing this feature during a beta, I would be interested in assisting.

                              Thanks again.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              11 responses
                              42 views
                              0 likes
                              Last Post cmtjoancolmenero  
                              Started by FrazMann, Today, 11:21 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post FrazMann  
                              Started by geddyisodin, Yesterday, 05:20 AM
                              8 responses
                              52 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by DayTradingDEMON, Today, 09:28 AM
                              4 responses
                              27 views
                              0 likes
                              Last Post DayTradingDEMON  
                              Started by George21, Today, 10:07 AM
                              1 response
                              22 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Working...
                              X