NexusFi: Find Your Edge


Home Menu

 





NT: How I got market replay to work like live


Discussion in NinjaTrader

Updated
    1. trending_up 4,768 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?
$24.5 Billion Record Month: Prediction Markets Shatter A …
Prediction Markets & Event Contracts
Iran Ceasefire Surges to 19.5% on US 15-Point Plan -- 82 …
Prediction Markets & Event Contracts
Energy Futures Shatter All-Time Daily Volume: 8.3 Millio …
Commodities
Hungary Called for Magyar at 97pct, Ending 16-Year Orban …
Prediction Markets & Event Contracts
CFTC Launches Innovation Task Force for AI Trading Syste …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
22 thanks
2026 Jlab journal
10 thanks
Trying to learn Volume and price action correlation
8 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
5 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