Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Best way evaluate position and exit trades between bars in replay mode?

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

    Best way evaluate position and exit trades between bars in replay mode?

    Hi,

    I'm using replay mode to test strategies and need to exit a position between bars, e.g. exit if unrealized gain/loss >= $ or time >= 4:14pm.
    I thought it would be easy, but I've tried these methods so far with no success:
    - setting CalculateOnBarClose false
    - putting my conditions and exit code in the OnMarketData event.
    - I've also tried to at least satisfy the latter condition by setting the strategy 'Exit On Close' parameters, expecting them to exit at 4:14, but that never occurred either.

    And OnMarketData behaved completely differently than I expected, e.g. when printing a Time[0], it's out of sync (falls way behind) the actual replay time?

    So I'm not sure what to try next, but I need to find some way to do this.
    I suspect (hope) I'm just missing something simple (I'd imagine this would be a common requirement).
    Any advice would be greatly appreciated.

    #2
    Originally posted by raysdbar View Post
    Hi,

    I'm using replay mode to test strategies and need to exit a position between bars, e.g. exit if unrealized gain/loss >= $ or time >= 4:14pm.
    I thought it would be easy, but I've tried these methods so far with no success:
    - setting CalculateOnBarClose false
    - putting my conditions and exit code in the OnMarketData event.
    - I've also tried to at least satisfy the latter condition by setting the strategy 'Exit On Close' parameters, expecting them to exit at 4:14, but that never occurred either.

    And OnMarketData behaved completely differently than I expected, e.g. when printing a Time[0], it's out of sync (falls way behind) the actual replay time?

    So I'm not sure what to try next, but I need to find some way to do this.
    I suspect (hope) I'm just missing something simple (I'd imagine this would be a common requirement).
    Any advice would be greatly appreciated.
    Using the OnMarketData() event is the easiest way, though you could use COBC = false too. Without seeing your code, nobody can tell where things are not being correctly done, but I definitely use OnMarketData() for doing what you want to do, and it works just fine, both for setting dynamic stops, and for exiting and quitting at a specified time.

    Comment


      #3
      Thanks for the reply kogonam!
      The problem I'm seeing with OnMarketData is an apparent inconsistency. I don't know if it's a replay issue, but while I would expect to see an event firing on every tick, in fact I see relatively few events, and I also expected there to be multiple events per minute. If you can see the attached image, you can see that while the replay clock is at 1:09:36am, the event time is way back at 12:58:31am?
      The only logic in the OnMarketData right now is the Print() statement, which is what you see in this image (a Time[0] and e.ToString()).


      Comment


        #4
        raysdbar,

        What is in your OnMarketData() method? Only a single print statement?
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Yes, just: Print(Time[0]+" "+e.ToString());

          Comment


            #6
            raysdbar,

            The time stamp of the first part of the output would be the time stamp of the bar that last called the OnBarUpdate(). The time stamp after "Time" is the time stamp of that particular tick that called OnMarketData().

            If you notice the time stamps, for example :

            5/25/2012 2:30:00 AM Instrument='ES 06-12 Globex' Type=Bid Price=1328.25 Volume=69 Time=5/25/2012 2:38:59 AM
            5/25/2012 2:30:00 AM Instrument='ES 06-12 Globex' Type=Bid Price=1328.25 Volume=67 Time=5/25/2012 2:38:59 AM
            5/25/2012 2:30:00 AM Instrument='ES 06-12 Globex' Type=Bid Price=1328.25 Volume=66 Time=5/25/2012 2:38:59 AM
            5/25/2012 2:30:00 AM Instrument='ES 06-12 Globex' Type=Bid Price=1328.25 Volume=64 Time=5/25/2012 2:38:59 AM
            5/25/2012 2:30:00 AM Instrument='ES 06-12 Globex' Type=Ask Price=1328.5 Volume=132 Time=5/25/2012 2:38:59 AM

            The 2:38:59 print occurs multiple times in that 1 second. There were about 20 more here so I am getting multiple ticks per second. I am noticing in your output you are also getting multiple ticks per second. Tick time stamps only have second granularity at this time but they should come in sequence of how they were recieved. I was running this on a 30 minute chart so the first time stamp was at 2:30:00 since I was on the 2:30:00 bar, but printing tick-by-tick.

            What time frame chart was this you were running on?

            Please let me know if I may assist further.
            Last edited by NinjaTrader_AdamP; 05-29-2012, 10:31 AM.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              It looked like they were printing much slower during the run, but I can see that the tick times were in fact synced ok, now that you point it out - sorry to have wasted your time!
              The bars were 8 brick Renkos.
              Thanks!

              Comment


                #8
                raysdbar,

                Its never a waste of time. We are happy to help.

                Please let me know if I may be of further assistance.
                Adam P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by hazylizard, Today, 08:38 AM
                2 responses
                8 views
                0 likes
                Last Post hazylizard  
                Started by geddyisodin, Today, 05:20 AM
                2 responses
                18 views
                0 likes
                Last Post geddyisodin  
                Started by Max238, Today, 01:28 AM
                5 responses
                47 views
                0 likes
                Last Post Max238
                by Max238
                 
                Started by giulyko00, Yesterday, 12:03 PM
                3 responses
                13 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by habeebft, Today, 07:27 AM
                1 response
                16 views
                0 likes
                Last Post NinjaTrader_ChristopherS  
                Working...
                X