NinjaTrader script redundancy in variables calculation - NinjaTrader | futures io social day trading
futures io futures trading


NinjaTrader script redundancy in variables calculation
Updated: Views / Replies:665 / 8
Created: by Astrogirl Attachments:0

Welcome to futures io.

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

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • 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.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

NinjaTrader script redundancy in variables calculation

  #1 (permalink)
Trading for Fun
Milan/Italy
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: ES, YM, NQ, FDAX
 
Astrogirl's Avatar
 
Posts: 51 since Oct 2013
Thanks: 25 given, 7 received

NinjaTrader script redundancy in variables calculation

Hallo, I'm a beginner. My NT script calculates the values of several variables when a price condition is reached. I noticed (with the Print command on the monitor) that it is repeated each minute (that is my market data time-frame) thousand of times until the condition remains true! I guess it takes a lot of work and time for RAM and CPU and it is absolutely redundant as it is needed that the variables assignment happen only once when the condition is reached (and once again when the condition is no longer true).
How can I avoid that?


Last edited by Astrogirl; August 6th, 2015 at 07:15 AM.
Reply With Quote
 
  #2 (permalink)
Elite Member
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,336 since Dec 2012
Thanks: 11,276 given, 7,090 received

Answer
This post has been selected as an answer to the original posters question Answer


Astrogirl View Post
Hallo, I'm a beginner. My NT script calculates the values of several variables when a price condition is reached. I noticed (with the Print command on the monitor) that it is repeated each minute thousand of times until the condition remains true! I guess it takes a lot of work and time for RAM and CPU and it is absolutely redundant as it is needed that the variables assignment happen only once when the condition is reached (and once again when the condition is no longer true).
How can I avoid that?

Just a simple 'bool' flag, set when the calc is needed, clear it when not.

Unless it's just that the code is being called on each Historical bar, depends what you want, without seeing the code, hard to say.

Redundancy in code is not always a problem, so long as you are aware of what is needed and whether there are spare resources or not, Ghz are very different form human hurts.

Task Manager/Resource Manager in Windows will show if much cpu/ram is getting used, Print statements will slug it but are great for fast debugging visiblity. Can always be left in code and just switched on/off by a bool variable as well.

Travel Well
Reply With Quote
 
  #3 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,653 since Mar 2010
Thanks: 4,226 given, 25,601 received
Forum Reputation: Legendary

Answer
This post has been selected as an answer to the original posters question Answer



Astrogirl View Post
Hallo, I'm a beginner. My NT script calculates the values of several variables when a price condition is reached. I noticed (with the Print command on the monitor) that it is repeated each minute (that is my market data time-frame) thousand of times until the condition remains true! I guess it takes a lot of work and time for RAM and CPU and it is absolutely redundant as it is needed that the variables assignment happen only once when the condition is reached (and once again when the condition is no longer true).
How can I avoid that?

You can avoid that by setting your indicator to "CalculateOnBarClose = true". In that case there will be only one calculation per bar.

By the way "CalculateOnBarClose = true" is the default setting for most indicators. Did you change it?

Reply With Quote
 
  #4 (permalink)
Trading for Fun
Milan/Italy
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: ES, YM, NQ, FDAX
 
Astrogirl's Avatar
 
Posts: 51 since Oct 2013
Thanks: 25 given, 7 received

 
Code
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
///// GESTIONE POSIZIONE APERTA		
		if 	(
		        Position.MarketPosition != MarketPosition.Flat
			)
			{	
                        price1 = 10*100
                        price2 = 20*100
                        price3 = 30*100
                        price4 = 40*100

			if (Close[0] < 60000 && Close[0] >59000)	
				{
				Print (" CHECK 1: " + price1 + " " + price2); 
				}
			else if (Close[0] < 59001 && Close[0] > 58000) 
				{
				Print (" CHECK 2: " + price3 + " " + price4); 
				}
	                }
	 }
This is a sample of the code block (the real one has a lot more of complicated calculations for variables, lots of conditions to check and lots of operations to do).

The monitor says that the variables are calculated on each minute and the operations are executed each minute too. How to make it happens once until the condition remains true?

My target is to make the script much efficient and, above all, fast on backtesting.

(Please sorry for my weak English)


Last edited by Astrogirl; August 6th, 2015 at 02:26 PM.
Reply With Quote
 
  #5 (permalink)
Trading for Fun
Milan/Italy
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: ES, YM, NQ, FDAX
 
Astrogirl's Avatar
 
Posts: 51 since Oct 2013
Thanks: 25 given, 7 received


ratfink View Post
Redundancy in code is not always a problem, so long as you are aware of what is needed and whether there are spare resources or not, Ghz are very different form human hurts.

Should I let the script doing each of hundreds operations on each updating bar as it will not affect the efficiency and backtest speed anyway?
In effect the script does its job quite fine and it doesn't take so much time: about 3 minutes on each backtest. The matter is on optimization where my PC seems really suffering...



fat tails
By the way "CalculateOnBarClose = true" is the default setting for most indicators. Did you change it?

No, I didn't change it. It is on true... I'm going to make some tests and see what happen.


Last edited by Astrogirl; August 6th, 2015 at 02:30 PM.
Reply With Quote
 
  #6 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,653 since Mar 2010
Thanks: 4,226 given, 25,601 received
Forum Reputation: Legendary


Astrogirl View Post
Should I let the script doing each of hundreds operations on each updating bar as it will not affect the efficiency and backtest speed anyway?
In effect the script does its job quite fine and it doesn't take so much time: about 3 minutes on each backtest. The matter is on optimization where my PC seems really suffering...




No, I didn't change it. It is on true... I'm going to make some tests and see what happen.


All backtests are executed in mode "CalculateOnBarClose = true". This means that all calculations are only performed once per bar.

If you look for efficiency, you need to decomplexify the code. For example the word "decomplexify" can be easily decomplexified and becomes "simplified".

Reply With Quote
The following user says Thank You to Fat Tails for this post:
 
  #7 (permalink)
Trading for Fun
Milan/Italy
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: ES, YM, NQ, FDAX
 
Astrogirl's Avatar
 
Posts: 51 since Oct 2013
Thanks: 25 given, 7 received


ratfink View Post
If you look for efficiency, you need to decomplexify the code. For example the word "decomplexify" can be easily decomplexified and becomes "simplified".




My idea is to use a C# block as such as the "protected override void Initialize()" and then to call it only once until the relative condition in the "protected override void OnBarUpdate()"
is no longer true.

(At the same time I'm wondering if it could be just a nice way to complexify instead of simplify ! )


Last edited by Astrogirl; August 6th, 2015 at 03:41 PM.
Reply With Quote
 
  #8 (permalink)
Elite Member
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,336 since Dec 2012
Thanks: 11,276 given, 7,090 received


Astrogirl View Post
 
Code
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
///// GESTIONE POSIZIONE APERTA		
		if 	(
		        Position.MarketPosition != MarketPosition.Flat
			)
			{	
  
			if (Close[0] < 60000 && Close[0] >59000)	
				{
                                price1 = 10*100
                                price2 = 20*100
				Print (" CHECK 1: " + price1 + " " + price2); 
				}
			else if (Close[0] < 59001 && Close[0] > 58000) 
				{
                                price3 = 30*100
                                price4 = 40*100
				Print (" CHECK 2: " + price3 + " " + price4); 
				}
	                }
	 }
This is a sample of the code block (the real one has a lot more of complicated calculations for variables, lots of conditions to check and lots of operations to do).

The monitor says that the variables are calculated on each minute and the operations are executed each minute too. How to make it happens once until the condition remains true?

My target is to make the script much efficient and, above all, fast on backtesting.

(Please sorry for my weak English)

Unless I am misunderstanding just moving the calculation blocks inside the conditionals as I have illustrated will help - so long as it is actually CPU bound and not hard page faulting from excessive ram use. You can see that in the Windows Task Manager and Resource Manager to check what is different during the optimisation run.

If you are using too much ram cut down the degrees of freedom or ranges of the optimisation parameters. Guessing here as I do know systems inside out but I don't use the optimiser.

Cheers

Travel Well
Reply With Quote
The following user says Thank You to ratfink for this post:
 
  #9 (permalink)
Trading for Fun
Milan/Italy
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: ES, YM, NQ, FDAX
 
Astrogirl's Avatar
 
Posts: 51 since Oct 2013
Thanks: 25 given, 7 received


ratfink View Post
Redundancy in code is not always a problem, so long as you are aware of what is needed and whether there are spare resources or not, Ghz are very different form human hurts.

Task Manager/Resource Manager in Windows will show if much cpu/ram is getting used, Print statements will slug it but are great for fast debugging visiblity. Can always be left in code and just switched on/off by a bool variable as well.

As you said, after several tests with Task Manager (great advice!) I can confirm that RAM and CPU were not used so much during a simple backtest. I'm really not competent on PC's hardware but what matters, in backtest speed, seems to be the CPU GHz rate. (Any comment by experts is welcome )


ratfink View Post
Unless I am misunderstanding just moving the calculation blocks inside the conditionals as I have illustrated will help - so long as it is actually CPU bound and not hard page faulting from excessive ram use. You can see that in the Windows Task Manager and Resource Manager to check what is different during the optimisation run.

If you are using too much ram cut down the degrees of freedom or ranges of the optimisation parameters. Guessing here as I do know systems inside out but I don't use the optimiser.

Cheers

Thanks! Using the logic of your modified code and switch on/off boolean variables, the backtest takes 15% less time!


Last edited by Astrogirl; August 6th, 2015 at 06:28 PM.
Reply With Quote
The following user says Thank You to Astrogirl for this post:

Reply



futures io > > > > NinjaTrader script redundancy in variables calculation

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
[NinjaTrader]    Converting Multicharts variables to NinjaTrader jjsshh NinjaTrader Programming 4 July 21st, 2015 10:24 AM
Does NinjaTrader have 'script' and 'backtest in visual mode' as Metatrader4, or not? umbertosm NinjaTrader Programming 3 February 18th, 2015 05:30 AM
Sending a keyboard Command from a NinjaTrader Script ECI Ed NinjaTrader 2 November 4th, 2014 01:43 PM
Programming with NinjaTrader script Wolfgang NinjaTrader Programming 4 February 25th, 2014 12:11 PM
Need little help with a Ninjatrader script raindrop NinjaTrader Programming 9 April 20th, 2011 11:35 PM


All times are GMT -4. The time now is 08:49 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-12-13 in 0.15 seconds with 37 queries on phoenix via your IP 54.160.245.121