NT7 programming - reset value of a variable at each bar - futures io
futures io futures trading



NT7 programming - reset value of a variable at each bar


Discussion in NinjaTrader

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




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
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.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

NT7 programming - reset value of a variable at each bar

(login for full post details)
  #1 (permalink)
Budapest, Hungary
 
Experience: None
Platform: ninjatrader
Trading: FGBL / FESX / ES / ZN / ZB
 
adamov's Avatar
 
Posts: 84 since Jun 2012
Thanks: 37 given, 49 received

Hi

I have a continuous tick by tick calculation. I need the changes of its value on each bar. I need a dataseries of them to make calculations.

I tried to reset the value with FirstTickOfBar. But sometimes it seems to ignore this part and adds the change to the value of the previous bar.
Could you tell me what is the problem or suggest any other solution to get the changes in value?

 
Code
		protected override void OnBarUpdate()
		{
			totalvol = totalvol + eVol;
			totalvolplot.Set(totalvol);	
			if(FirstTickOfBar)
			{
				totalvol = eVol;
			}
				
		}
				
		
		protected override void OnMarketData(MarketDataEventArgs e)
		{
			
			//Set AskPrice
			if(e.MarketDataType == MarketDataType.Ask)
			{
				AskPrice = e.Price;
			}
			
			//Set BidPrice
			if(e.MarketDataType == MarketDataType.Bid)
			{
				BidPrice = e.Price;
			}
			
			//Trade calculations done on incoming trade data
			if (e.MarketDataType == MarketDataType.Last)
			{
						
			//Buys calculations
				if(e.Price >= AskPrice)
				{
					eVol = e.Volume;
				}
		
				//Sells calculations
				if(e.Price <= BidPrice)
				{
					eVol = e.Volume;
				}
			}
		}

Started this thread Reply With Quote

Can you help answer these questions
from other members on futures io?
Webinar: Finding your own way in trading w/Adam Grimes
The Elite Circle
MACD line not plotting after change of plot order
NinjaTrader
OFA (Order Flow Analytics) Licence
NinjaTrader
ZigZag with Depth and Backstep
EasyLanguage Programming
Automatic pattern research with NT
Elite Algorithmic NinjaTrader Trading
 
 
(login for full post details)
  #2 (permalink)
Birmingham UK
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
 
ratfink's Avatar
 
Posts: 3,651 since Dec 2012
Thanks: 17,422 given, 8,403 received

 
Code
protected override void OnBarUpdate()
		{
			if(FirstTickOfBar)
	 		{
				totalvol = eVol;
			}
			else
			{
				totalvol = totalvol + eVol;
			}
				
			totalvolplot.Set(totalvol);	
		}
I would usually keep all summation calcs inside the OMD routine and only do a zero reset inside OnBarUpdate but try that instead.

Cheers

Travel Well
Visit my futures io Trade Journal Reply With Quote
The following 2 users say Thank You to ratfink for this post:


futures io Trading Community Platforms and Indicators NinjaTrader > NT7 programming - reset value of a variable at each bar


Last Updated on March 7, 2016


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 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