NexusFi: Find Your Edge


Home Menu

 





NT: How I got market replay to work like live


Discussion in NinjaTrader

Updated
    1. trending_up 4,880 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 1 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
kandlekid
College Point, NY (Queens)
 
Posts: 63 since Nov 2009
Thanks Given: 5
Thanks Received: 20

How I got NinjaTrader Market Replay to work live it's live ...

The Problem ... Market replay sets the state of NT based on a number of historical bars it sees prior to the start of the replay (i.e. real time bar). It will run the Initialization method, etc at the first historical bar. So to make replay work like live, we've got to get NT to ignore all the bars prior to the first real time bar (just like a live connection).

Here's how I did it ... note: assume there are several boolean states as follows ...

iAmNoPosition, iAmLong, iAmShort.

To see the difference with how market replay normally runs, I added the following code to my strategy ...

private bool iAmLong = false;
private bool iAmShort = false;
private bool iAmNoPosition = true;

private int once = 1; // Note, not static !

private int tickCnt = 1;
private int prevBar;

...

private void ClearPositions()
{
iAmLong = false;
iAmShort = false;
iAmNoPosition = true;
}

...

protected override void Initialize()
{
...

prevBar = -1;

CalculateOnBarClose = false;
}


protected override void OnBarUpdate()
{
if ( prevBar != CurrentBar ) // Historical bars and 1st tick of a real time bar.
{
prevBar = CurrentBar;
tickCnt = 1;
}
else if ( prevBar == CurrentBar ) // Real time bars only.
{
tickCnt++;
}

// Testing only - because market replay sets state prior to the
// real time date, I want to ignore that setting.
//

if ( true == IsMarketReplay && once == 1 && tickCnt > 1 )
{
ClearPositions();

Print("\n\nCleared all.\n\n");

once = 0;
}


That's it !!!!!

To see the difference between how market replay normally runs and this work-around,
change this line ...

if ( true == IsMarketReplay && once == 1 && tickCnt > 1 )

to this ...

if ( true == IsMarketReplay && once == 1 )

Cheers


Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Weekend Update: First Qatari LNG Transit Attempted -- IR …
Traders Hideout
Iran Airspace Contract Surges to 33.5% as Project Freedo …
Prediction Markets & Event Contracts
$500M Riding on World Cup 2026: France/Spain Co-Favored …
Prediction Markets & Event Contracts
Warsh Opens Today, Hormuz June 19 -- WTI Below $80, Fran …
Prediction Markets & Event Contracts
World Cup Opens: USA at 45.5% Tonight as Markets Push Ba …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
8 thanks
Darmok and Jalad at Tanagra
1 thanks
  #2 (permalink)
 goldilocks 
NYC, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: NT
Trading: ES
Posts: 65 since Sep 2009
Thanks Given: 117
Thanks Received: 81


kandlekid View Post
How I got NinjaTrader Market Replay to work live it's live ...


I would like to try to do this, but I don't know how to add this code where I'm supposed to... if it's not too difficult to do, would someone be able to help me set this up?

thanks!!


Reply With Quote




Last Updated on December 10, 2009


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts