NexusFi: Find Your Edge


Home Menu

 





Access Tick Data within BarsInProgress minute loop


Discussion in NinjaTrader

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




 
Search this Thread

Access Tick Data within BarsInProgress minute loop

  #1 (permalink)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61

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

Follow me on Twitter Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
Exit Strategy
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
ZombieSqueeze
Platforms and Indicators
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
26 thanks
Just another trading journal: PA, Wyckoff & Trends
24 thanks
Tao te Trade: way of the WLD
22 thanks
My NQ Trading Journal
16 thanks
HumbleTraders next chapter
9 thanks
  #2 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425

 
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
Visit my NexusFi Trade Journal Reply With Quote
  #3 (permalink)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61


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.

Follow me on Twitter Started this thread Reply With Quote
  #4 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425


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
Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61


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.

Follow me on Twitter Started this thread Reply With Quote
Thanked by:




Last Updated on September 13, 2016


© 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