Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Duplicate Trades

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

    Duplicate Trades

    Hi,
    On the 28th and 29th of this month I had a couple of duplicate trades made by my strategy that seemingly should not have been possible.
    In checking around I found the warnings shown in screenshot 1 attached.
    In screenshot 2, you will see the duplicate trades. I don't know if the warnings and the duplicate trades are related, but it sure seems like it.
    I have the following pseudo code that would seem to prevent dupes, but obviously did not.

    Code:
    [FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]// check to see if there is a trade on in the direction that I [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
     [FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]// intend to place a new  trade. If a stored trade's TheOrder is not [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
     [FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]// null, don't [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][COLOR=#008000]trade. Given that I keep a copy of all orders until [/COLOR][/FONT]
     [FONT=Consolas][COLOR=#008000]// the target or [/COLOR][/FONT][FONT=Consolas][COLOR=#008000]stop is reached this test in theory, should make it [/COLOR][/FONT]
     [FONT=Consolas][COLOR=#008000]// impossible [/COLOR][/FONT][FONT=Consolas][COLOR=#008000]to put in a dupe[/COLOR][/FONT]
     [FONT=Consolas][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][/FONT][SIZE=2][SIZE=2][FONT=Consolas] (MyStrat.IsLong)[/FONT]
     [FONT=Consolas]{[/FONT]
     [/SIZE][/SIZE][FONT=Consolas][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]    if[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] (([/SIZE][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]from[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] a [/SIZE][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]in[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] MyStrat.Trades [/SIZE][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]where[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] a.TheOrder != [/SIZE][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] && [/SIZE][/SIZE][/FONT]
     [FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]          a.Direction == TradeTypeLong [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]select[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] a).Count() != 0)
     [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]        return[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2];
     }
     [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]else
    [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] {
     [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]    if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] (([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]from[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] a [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]in[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] MyStrat.Trades [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]where[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] a.TheOrder != [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] &&[/SIZE][/FONT][/SIZE][/FONT]
     [FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]          a.Direction == TradeTypeShort [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]select[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] a).Count() != 0)
     [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]    return[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2];
     }
     [FONT=Consolas][COLOR=#008000]// if we get here place a new trade.[/COLOR][/FONT]
     [COLOR=#008000][/COLOR] 
      
    [/SIZE][/FONT][/SIZE][/FONT]
    Is there something I'm doing wrong?
    Is NT causing it? This duplicate business only occurs in live trading (on a sim account), not backtesting or optimizing.
    What can I do to prevent this in the future? Do you think it has anything to do with the warnings in the log?
    Thanks ... Ed
    Attached Files
    Last edited by edstaffin; 07-31-2016, 01:13 PM.

    #2
    Hello edstaffin, and thank you for your query. I can not see any flaws in your pseudo code. In order to help us review what occurred, could you send a copy of your log and trace folders underneath (My) Documents\NinjaTrader 8 to platformsupport[at]ninjatrader[dot]com, with attn: NinjaTrader_JessicaP and the unique ID 1551409 in the message body? Thank you in advance, this information will be very valuable for tracking down a solution.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Done!
      THanks ... Ed

      Comment


        #4
        Thank you, Ed. From your log and trace output, it looks like you may need to completely remove and readd your strategy from the chart or strategies tab where it was added.

        Should this not resolve your query, your other options in this situation including increasing the disconnect delay can be found in the NT7 Control Center -> Tools -> Options -> Strategies -> NinjaScript tab. You can push F1 in this tab to bring up context sensitive help for more information.

        Please let us know if there are any other ways we can help.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Hi Edstaffin, I have the same problem.
          Do you use a little time frame, like Renko 2 or similar?
          Your startegy work's whit the calculate on bar close?

          Comment


            #6
            Duplicate Trades

            Hi,
            I haven't seen the issue since the 29th. Just those 2 days. Increasing the disconnect time is not a very tasty solution. You said that the logs showed you something ... what? Is there something I can do other that increasing the disconnect time to avoid this. I was thinking about adding the code below as a stop-gap. I'd be interested in hearing your thoughts on it. Given that the previous code I showed seemed correct, this may just be redundant.
            I'll have to show the code in the next response. It's limiting me on the number of chars I can enter.
            Thanks ... Ed

            Comment


              #7
              Code:
              [FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][COLOR=#000000] [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][COLOR=#000000] [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][COLOR=#000000] OnMarketData([/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]MarketDataEventArgs[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][COLOR=#000000] e)[/COLOR]
               {
               [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]  if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] (BarsInProgress != 0)
               [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]    return[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2];
               [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]  if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Position[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Quantity > 1)
                 {
               [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]    //Get the duplicate trades and kill all but the 
              [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]    // one we really entered.
              [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]    var[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] q = [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]from[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] a inthis.Trades
               [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]    group[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] a [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]by[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] a.TheOrder.Name [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]into[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] g
               [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]    from[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] b [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]in[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] g
               [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]    where[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] g.Count() > 1 &&
                   b.TheOrder != [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] &&
                   b.TheOrder.OrderState == [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]OrderState[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Filled
               [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]    select[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]new
              [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]     {
                      b.TheOrder.Name,
                      b.TheOrder.IsLong,
                      b.TheOrder.IsShort,
                      Cnt = g.Count()
                   };
               [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]    foreach[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]var[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] o [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]in[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] q)
                   {
               [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]       [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Position[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].MarketPosition == [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]MarketPosition[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Long &&
                        o.IsLong == [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2])
                        ExitLong(0, o.Cnt - 1, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"DupesKilled"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2], o.Name);
                      elseif([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Position[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].MarketPosition == [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]MarketPosition[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Short &&
                        o.IsShort == [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2])
                        ExitShort(0, o.Cnt - 1, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"DuplesKilled"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2], o.Name);
                   }
                 }
               }
               [/SIZE][/FONT][/SIZE][/FONT]

              Comment


                #8
                While profiling your code is beyond the scope of the support we can provide, I would like to make a few remarks. First, the two string argument overload for ExitLong or ExitShort, ExitLong(string signalName, string fromEntrySignal) , will completely close orders on BarsInProgress == 0, and can be called safely even if you are not in a position. Second, closing trades in OrderState.Filled will likely have no effect.

                If you find yourself frequently experiencing duplicate trades, the recommended solution will instead be to investigate your Ninja installation. This is not something that should be happening frequently. Other users who experienced this have found that it is due to a strategy that was loaded into an unusable state, and that simply removing and replacing the strategy resolved their queries.

                To ensure your Ninja installation is not in a corrupt state, you may follow these instructions to completely reinstall a clean copy of Ninja while retaining e.g. your data feed connections :
                • Close NinjaTrader
                • Rename your (My) Documents\NinjaTrader 7 folder to (My) Documents\NinjaTrader 7 - old
                • Download a fresh copy of Ninja from ninjatrader.com
                • Use this installer to uninstall and reinstall NinjaTrader
                • Copy these files and folders from your old (My) Documents\NinjaTrader 7 folder to your new one, into the same file locations relative to your NinjaTrader documents directory :
                  • Config.xml
                  • bin\Custom\Indicator\*.cs (except ones starting with @)
                  • bin\Custom\Strategy\*.cs (except ones starting with @)
                  • bin\Custom\Type\*.cs (except ones starting with @)
                  • bin\Custom\*.dll (except ones starting with NinjaTrader)
                  • workspaces (except your _Workspaces.xml file, delete this first)
                  • templates
                • The first time you run Ninja, you may receive a compile error. Simply run Ninja again to get past this error



                This should guarantee you do not see the behavior you saw on the 29th again. If this does occur again, would it be possible to send a stripped down copy of your strategy to platformsupport[at]ninjatrader[dot]com with Attn:NinjaTrader_JessicaP and this unique ID in the message body? 1551409 . We will happy to help more with this or any other questions.
                Jessica P.NinjaTrader Customer Service

                Comment


                  #9
                  Wow, thanks for all the info. I've have not experienced any problems since the 29th, but will follow your instructions to a T tonight just to make sure. I wonder how it got corrupted in the first place. The thing had been running 24x7 for almost a month with no problems.
                  Oh well. I'll certainly let you know if it happens again!
                  Thanks again ... Ed

                  Comment


                    #10
                    In thinking about it more I need more of an answer. Basically, what I get from your response is that NT is aware of a problem. I'm not sure I understand what the problem is at this point, but apparently I am not the only one who has had this issue.
                    What *exactly* does the error message I got in the log mean? What is a "price connection"? How do I catch an event to let me know this is happening? Is there some kind of OnConnectionLost event I can trap? If there is and the connection being lost is the one between my machine and the broker (as opposed to my internet connection going down), then I can at least send myself an email.

                    Telling me to reload my strat etc, begs the question ... how did it get corrupted in the first place? It's been running 24x7 for a month with no problem and then all of a sudden it barfs every 10 seconds for 2 days and then magically fixes itself. This is spooky to me. I'd feel better if I understood what really happened as it doesn't seem to me that it could have anything to do with my code. Please correct me if I am wrong.
                    Thanks ... Ed

                    Comment


                      #11
                      Hello again edstaffin, I am happy to provide a more complete picture of the information we have available on our end.

                      First, I would like to provide the history I have to work with. We have seen this message occur on 3 other occasions.

                      2016 http://ninjatrader.com/support/forum...ad.php?t=86233
                      2013 http://ninjatrader.com/support/forum...ad.php?t=62522
                      2008 http://mobile.ninjatrader.com/suppor...ad.php?t=24634

                      Reviewing those threads, and your case, we can see that they have a few things in common.

                      • In each instance, there was a live data feed connection that was interrupted
                      • In each instance, removing and re-adding the strategy resolved the customer's query

                      I was also able to see in your log, that your strategy was trying to restart and reconnect almost exactly once a second. Here is some sample output with obfuscated numbers.


                      Code:
                      [FONT=Courier New]2016-07-29 00:00:00:320|#|#|Strategy 'AAAAA/########' lost price connection for more than 10 seconds and will be restarted.
                      2016-07-29 00:00:01:342|#|#|Strategy 'AAAAA/########' lost price connection for more than 10 seconds and will be restarted.
                      2016-07-29 00:00:02:358|#|#|Strategy 'AAAAA/########' lost price connection for more than 10 seconds and will be restarted.
                      2016-07-29 00:00:03:374|#|#|Strategy 'AAAAA/########' lost price connection for more than 10 seconds and will be restarted.
                      2016-07-29 00:00:04:420|#|#|Strategy 'AAAAA/########' lost price connection for more than 10 seconds and will be restarted.[/FONT]
                      While this is a very limited amount of information, when we put it together, we are left with your strategy connecting to your data feed provider at some point, that connection being disturbed mid-trade, and your strategy being left unable to recover while perpetually trying. Generally when this kind of thing occurs, it is because information on one side of a connection does not match what is on the other side. This is why removing and reading your strategy, or worst case resetting your database, were suggested as solutions. Both of these will remove the temporary information on your end that likely does not match what is at the trade desk, forcing Ninja to ask the trade desk for information to use instead.


                      To answer your other questions,


                      Originally posted by edstaffin View Post
                      What is a "price connection"?
                      This is your connection to your data feed provider.

                      Originally posted by edstaffin View Post
                      How do I catch an event to let me know this is happening? Is there some kind of OnConnectionLost event I can trap?
                      Ninja does have the OnConnectionStatus event, documented here



                      Originally posted by edstaffin View Post
                      How did it get corrupted in the first place?
                      While it is impossible to know for certain with the limited information available, I believe strongly this occurred because of a momentary internet connection interruption at an inopportune moment.

                      Please let us know if there are any other ways we can help, or if I can further clarify any of the above.
                      Last edited by NinjaTrader_JessicaP; 08-02-2016, 08:21 AM.
                      Jessica P.NinjaTrader Customer Service

                      Comment


                        #12
                        Thanks for the update. A lot to digest. One thing I did change is that I changed On Connection Lost property under Tools/Options from recalculate to Stop Strategy. This should, I think, stop the repeating entries in the log. Do you agree?
                        I'll read up on OnConnectionStatus.
                        Is there a way to monitor the log in my code and if certain errors (like this one) come up I can then send myself an email saying "Hey! Better check this out.".
                        Thanks ... Ed

                        Comment


                          #13
                          This should, I think, stop the repeating entries in the log. Do you agree?
                          I do, yes.

                          Is there a way to monitor the log in my code...
                          You bet. You will want to check out the Log method. It takes two arguments, depending on whether you want things going into just your log file, or your log and trace files both. I typically use LogLevel.Information so stuff just goes into my log file. You use Log like this,

                          Code:
                          [FONT=Courier New]Log("Your message to yourself between quote marks, maybe with " + SomeVariable, LogLevel.Information)
                          [/FONT]
                          And it is documented here,

                          Jessica P.NinjaTrader Customer Service

                          Comment


                            #14
                            HI I think you misunderstood. I want to get a notification whenever an entry in made into the log so I can test for certain errors and email myself a notification. Is there an OnLoggedEvent event?
                            Doable? If so, how?
                            THanks ... Ed

                            Comment


                              #15
                              You are right, I did misunderstand. Passing LogLevel.Alert to the log function I mentioned instead of LogLevel.Information will actually create a pop-up dialog whenever it is triggered.
                              Jessica P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by DJ888, 04-16-2024, 06:09 PM
                              4 responses
                              12 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by terofs, Today, 04:18 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post terofs
                              by terofs
                               
                              Started by nandhumca, Today, 03:41 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post nandhumca  
                              Started by The_Sec, Today, 03:37 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post The_Sec
                              by The_Sec
                               
                              Started by GwFutures1988, Today, 02:48 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Working...
                              X