Access Tick Data within BarsInProgress minute loop - NinjaTrader | futures io social trading
futures io futures trading


Access Tick Data within BarsInProgress minute loop
Updated: Views / Replies:280 / 4
Created: by spinnybobo Attachments:0

Welcome to futures io.

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.


You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

-- Big Mike

Reply
 
Thread Tools Search this Thread
 

Access Tick Data within BarsInProgress minute loop

  #1 (permalink)
Elite Member
Crete, IL/USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 171 since Aug 2009
Thanks: 99 given, 47 received

Access Tick Data within BarsInProgress minute loop

Hello

I am writing an indicator in which have the requirements of COBC = true
Most everything is on Close to collect values

But there is a part of the indicator when I evaluate everything and then it has a condition that when price hits a certain level, I want this to be updated tick by tick

 
Code
private BoolSeries entryCondition = null;
private double fibLevel;
private bool signal = false;

protected override void Initialize()
{
   entryCondition = new BoolSeries(this);
   Add(PeriodType.Tick, 1);
}
// and then in OnBarUpdate I have to separate them
// let's just say for sake of argument the entryCondition and the fibLevel are  already "set" somewhere else

protected override void OnBarUpdate()
{
    if (CurrentBars[0] > 3)
    {
        if (BarsInProgress == 0) // for the base chart
        {
              if (entryCondition[0])
              {
                   // now I want to monitor price by tick by tick
                   // as soon as it hits the fib level 
                  // 
                  if (BarsInProgress == 1) // tick series
                  {
                       if (Highs[0][1] > fibLevel)
                          signal = true; // this would go to market analyzer
                  }

               } 
         }

    }
}
So it seems like because I went

 
Code
if (BarsInProgress == 0)
   // anything inside here or executed from here will be ONLY coming in at a speed of the base chart.
  // if I have a 30 minute chart, it will only read it everything 30 minutes even though I can access the 
 // BIP == 1 values via Close[0][1]
The only thing I can think of is creating a boolean variable is like

 
Code
bool startTick = false;
and when it signals, startTick = true
Then in a separate block

 
Code
if (BarsInProgress == 1)
  // perform that stuff there

I just didn't know if there was a better way?
I am also going to try adding a break; to the if statement but not sure the best way to do this either

any help would be great

thanks
Spencer

Reply With Quote
 
  #2 (permalink)
Market Wizard
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,083 since Dec 2012
Thanks: 10,246 given, 6,321 received
Forum Reputation: Legendary

 
Code
private BoolSeries entryCondition = null;
private double fibLevel;
private bool signal = false;
private bool monitor = false;

protected override void Initialize()
{
   entryCondition = new BoolSeries(this);
   Add(PeriodType.Tick, 1);
}
// and then in OnBarUpdate I have to separate them
// let's just say for sake of argument the entryCondition and the fibLevel are  already "set" somewhere else

protected override void OnBarUpdate()
{
    if (CurrentBars[0] > 3)
    {
        if (BarsInProgress == 0) // for the base chart
        {
              if (entryCondition[0])
              {
                   // now I want to monitor price by tick by tick
                   // as soon as it hits the fib level 

                  monitor = true;
              }
         }
         else // in the tick series
         {
              if (monitor)
              {
                 if (High[0] > fibLevel)
                 {
                      signal = true; // this would go to market analyzer
                 }
              }
         }
    }
}

I think you want something like that. Remember to clear 'monitor' wherever else you are looking after signal and entryCondition.

Cheers

Travel Well
Reply With Quote
 
  #3 (permalink)
Elite Member
Crete, IL/USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 171 since Aug 2009
Thanks: 99 given, 47 received

found out the answer! OnMarketData works awesome!


So as an update here is what I discovered

my new friend is OnMarketData !

I knew I needed some type of an event similar to OnOrderUpdate and OnExecution, but since this is not a strategy I didn't know what other events I could use.

Now that I am aware of this event (I heard of it before just never used it) and what I can use it for, I will keep my eyes on the lookout for ALL of the events available in NinjaTrader 7 as well as 8.

The events built in really did save the day

Here is what I was looking for. My strategy is COBC = true because if I did COBC = false and used FirstTickOfBar to help calculate things, it does not give the same exact values bar by bar on a consistent basis, so I could not go down that route.

I didn't want to Add(PeriodType.Tick, 1) because it takes FOREVER to load when you put it on the chart.

Plus this is Forex and I am not sure if FXCM adds the ticks as easy as futures for CQG. I would always get an error and this is not good if you are writing something for a client.

Therefore I wanted COBC = true, but when a certain price is reached, I wanted it to start monitoring it in real time tick by tick.

Enter the OnMarketData. It works great!

 
Code
		bool signal = false;
		bool monitorFibLevel = false;
		int fibLevel;
		protected override void OnMarketData(MarketDataEventArgs e)
		{
			if (e.MarketDataType == MarketDataType.Last)
			{
				Print("OnMarketData.Last = " + e.Price);
				
				if (monitorFibLevel && e.Price <= fibLevel) 
				{
					Print("Price hit at : " + Time[0]);
					signal = true; // we have a signal
					monitorFibLevel = false;
				}
			}
		}
So since Ninja is event driven, and they seem to not have bugs in the events, I am definitely going to make myself aware of all of the available events.

This will probably only enhance my code making it "lighter" and easier to load as well as more accurate.

Reply With Quote
 
  #4 (permalink)
Market Wizard
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,083 since Dec 2012
Thanks: 10,246 given, 6,321 received
Forum Reputation: Legendary


spinnybobo View Post
Enter the OnMarketData. It works great!

It is good for live work, just be aware that it's no use in backtesting (no data), or in replay (1s accuracy) in NT7.

Travel Well
Reply With Quote
 
  #5 (permalink)
Elite Member
Crete, IL/USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 171 since Aug 2009
Thanks: 99 given, 47 received


ratfink View Post
It is good for live work, just be aware that it's no use in backtesting (no data), or in replay (1s accuracy) in NT7.

Hey

yes I am aware it is only for real time data. so since this is just an indicator and does need it to be tick by tick for Historical, that is fine. I am mainly talking about situations in which you want to jump into tick right away

if it was a strategy and the stop needed to be trailed and I wanted to backtest it, then yes I would need to add tick data to the chart and handle it
However, in that situation I would use IOrder states to trigger as opposed to a boolean like

 
Code
private IOrder entryOrder = null;
private IOrder stopOrder = null;
private int tickSeries = 1;

protected override void Initialize()
{
     Add(PeriodType.Tick, 1);
}
protected override void OnBarUpdate()
{
   if (BarsInProgress == tickSeries && Long && stopOrder != null)
   {
        // logic to trail stop
   }
}

private bool Long{ get { return(Position.MarketPosition == MarketPosition.Long); }}
private bool Short{ get { return(Position.MarketPosition == MarketPosition.Short); }}
private bool Flat{ get { return(Position.MarketPosition == MarketPosition.Flat); }}
then I would need the ticks to be added.

Reply With Quote
The following user says Thank You to spinnybobo for this post:

Reply



futures io > > > > Access Tick Data within BarsInProgress minute loop

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

FIO Journal Challenge featuring NinjaTrader ($2,000+ of prizes)

May

An overview of volumetric analytical tools w/Sergey Sokolov @ PTMC

Elite only

John Hoagland (TBA)

Elite only

FuturesTrader71 Extended Ask Me Anything (AMA)

Elite only

Pete @ Jigsaw Trading (TBA)

Elite only

John @ No BS Day Trading (TBA)

Elite only

An Afternoon with FIO member Softsoap (being rescheduled)

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multicharts: Importing tick data (and converting it to minute bar data) pedrosimao MultiCharts 4 May 23rd, 2016 07:01 AM
Tick data / 1 minute data with developing value area 6E treydog999 Traders Hideout 3 December 31st, 2014 09:40 PM
Historical CL Tick Data and Minute Data Big Mike The Elite Circle 112 July 26th, 2014 06:07 PM
Historical YM Tick Data and Minute Data?? Hermo The Elite Circle 3 December 1st, 2012 01:56 PM
Purchasing tick / minute data patbateman The Elite Circle 9 April 22nd, 2012 02:12 PM


All times are GMT -4. The time now is 04:36 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-05-28 in 0.10 seconds with 19 queries on phoenix via your IP 54.162.44.105