NexusFi: Find Your Edge


Home Menu

 





NT: How I got market replay to work like live


Discussion in NinjaTrader

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




 
Search this Thread

NT: How I got market replay to work like live

  #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?
Are there any eval firms that allow you to sink to your …
Traders Hideout
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
ZombieSqueeze
Platforms and Indicators
Exit Strategy
NinjaTrader
Futures True Range Report
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
Battlestations: Show us your trading desks!
26 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 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


© 2024 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 - Privacy Policy - Downloads - Top
no new posts