NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 08-15-2011, 10:16 AM   #1
jhill
Member
 
Join Date: Jul 2009
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
Default Previous Bar Strategy Question

When writing a Strategy Script, how can I test for the Background Color of the chart that was used on the Previous Bar?

Thanks,

jhill
jhill is offline  
Reply With Quote
Old 08-15-2011, 10:19 AM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hi jhill,

There's unfortunately no supported way to access this from a strategy. You need to be able to know the conditions that caused a background color change, and can then use these same conditions in a strategy.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 08-15-2011, 10:25 AM   #3
jhill
Member
 
Join Date: Jul 2009
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks very much for your prompt reply.

jhill
jhill is offline  
Reply With Quote
Old 08-15-2011, 10:28 AM   #4
jhill
Member
 
Join Date: Jul 2009
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Ryan,

One more question if I may.
When writing a Strategy Script, how can I test for the Background Color of the chart that is used on the current Bar?

Thanks,

jhill
jhill is offline  
Reply With Quote
Old 08-15-2011, 10:30 AM   #5
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

There is no way to access this from any bar. You need the underlying conditions that cause a background color change.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 08-15-2011, 11:05 AM   #6
jhill
Member
 
Join Date: Jul 2009
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Ryan for your response. The conditions that you referred to are in a 3rd party Indicator script. Since I won’t be needing the plotting logic in my Strategy Script, can you suggest a simple way of eliminating the script that is only associated with the actual plotting, keeping only the conditions necessary for determining a color change?

Also, I use 4 different indicators in order to visually place a trade, so do I assume correctly that I’ll have to merge the 4 of them together into one Strategy in order to properly place an Auto Trade?
jhill is offline  
Reply With Quote
Old 08-15-2011, 11:10 AM   #7
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

If you don't have the source code available for these indicators, you will not be able to access the color changing conditions from a strategy.

Without the source code from the indicator, the only values you can access from the strategy are indicator plots.

Best may be to work with the 3rd party vendor to see if they offer an automated trading system based on their indicators.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 08-15-2011, 11:19 AM   #8
jhill
Member
 
Join Date: Jul 2009
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
Default

Again, thanks for your time and prompt responses. I have set up a good Trading methodology using these indicators but wanted to try and create an auto system for me to eliminate the Psy. problems that I have in pulling the trigger. I'll keep plugging along to try and get the auto system to work.

jhill
jhill is offline  
Reply With Quote
Old 08-15-2011, 12:20 PM   #9
jhill
Member
 
Join Date: Jul 2009
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Ryan, your response resulted in one more question.

Thanks for your prompt response!

I have the .cs files from the 3rd party, for the indicators I currently use, and have opened them with the NinjaScript Editor. I assume that these .cs files are the source code which you addressed in the previous email?

If so, is there a simple way to create a Strategy from the Indicator script?

Thanks,

jhill
jhill is offline  
Reply With Quote
Old 08-15-2011, 01:12 PM   #10
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Yes .cs can be used as source files, but also as a wrapper for protected dlls.

If you can view the indicator source code, you should be able to see the conditions that result in background color change. You can use the same conditions that are in the indicator code in your strategy, or create a bool series from the conditions, and expose the values of the boolseries following this sample:

http://www.ninjatrader.com/support/f...ead.php?t=4991
Last edited by NinjaTrader_RyanM; 08-15-2011 at 01:36 PM.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 08-15-2011, 01:40 PM   #11
jhill
Member
 
Join Date: Jul 2009
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
Default

Again Ryan your time and responses are very much appreciated.

thanks,

jhill
jhill is offline  
Reply With Quote
Old 08-15-2011, 01:42 PM   #12
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

You're welcome, jhill. Best of luck with the strategy creation. Let me know if you have any additional questions.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 08-15-2011, 04:26 PM   #13
jhill
Member
 
Join Date: Jul 2009
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Ryan,
I have pasted below, the script that I added to my Indicator and Strategy, which follows the Strategy and Indicator examples in the SampleBoolSeries.zip from NT. My Indicator compiled fine, but the Strategy generated an error. Could you look at the code and help me understand what I need to correct? Thanks so much for your help!


MY STRATEGY:

protected override void Initialize()
{
// Add(JnD_ZlemaVma(14,6,9)); //JnD
// Add(JnD_ZlemaVma()); //JnD
CalculateOnBarClose = false;
}

MY INDICATOR:

namespace NinjaTrader.Indicator
{
[Description("Combination of ZLEMA and VMA with background shading when the two cross. (v7.1)")]
public class JnD_ZlemaVma : Indicator
/*
Revision 0. Combined indicators and used background flooding schemes and rising/falling selectable colors.
Revision 1. Corrected error that removed changes to background flooding when the program was rebooted.
*/

{
#region Variables
private int zlemaPeriod = 14;
private int downIntensity = 65;
private int upIntensity = 75;
private int direction = 0;
private int lag = 0;
private int vmaPeriod = 9;
private int volatilityPeriod = 9;

private double value1 = 0;
private double value2 = 0;
private double k = 0;
private double oneMinusK = 0;

private bool showFlooding = true;

private Color backColorUp = Color.Green;
private Color backColorDown = Color.Red;
private Color colorUp = Color.Green;
private Color colorDown = Color.Red;

private DataSeries zlemaSeries;

private BoolSeries bearIndication; //JnD
private BoolSeries bullIndication; //JnD
private double exposedVariable; //JnD
#endregion
jhill is offline  
Reply With Quote
Old 08-15-2011, 04:27 PM   #14
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,199
Thanks: 24
Thanked 1,225 times in 996 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by jhill View Post
Thanks Ryan for your response. The conditions that you referred to are in a 3rd party Indicator script. Since I won’t be needing the plotting logic in my Strategy Script, can you suggest a simple way of eliminating the script that is only associated with the actual plotting, keeping only the conditions necessary for determining a color change?

Also, I use 4 different indicators in order to visually place a trade, so do I assume correctly that I’ll have to merge the 4 of them together into one Strategy in order to properly place an Auto Trade?
The only things that an indicator exposes are its public properties and methods. You need to know how those properties and methods create the color change. Then you just need to call them directly in your strategy, by reference to the indicator.

In other words, if the indicator generates trade signals, then the calculation logic behind those signals is implied by the signals themselves: you only need to process the signals, as if they were coming from a black box, which, in the absence of the source code, they in fact, are.
koganam is offline  
Reply With Quote
Old 08-15-2011, 04:43 PM   #15
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

In your indicator code, you need a couple more components:

You need to set the boolseries when your condition is true.
You need the properties region linking the private boolseries to the public (Uppercase) one that you then reference in your strategy.

This is all in the sample you downloaded, so will have to look at how it's used there and do the same in your scripts.
NinjaTrader_RyanM is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing Previous Bar Data Question Dreamer88zzz Indicator Development 1 01-25-2011 06:57 AM
if Target Profit reached on previous bar, dont trade current bar paschall Strategy Development 4 09-02-2009 10:34 PM
Current Bar Open Equals Previous Bar Close ramacan Charting 6 05-23-2009 11:07 AM
High and Low of previous bar and actual bar Fernando Miscellaneous Support 1 03-18-2009 10:54 AM
CrossBelow previous bar and omit current bar ct General Programming 1 06-03-2007 02:54 AM


All times are GMT -6. The time now is 12:37 AM.