NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


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

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 05-08-2012, 06:23 AM   #1
rodlm
Junior Member
 
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default Boolean SuperTrend

Hello, I'm trying to create a simple indicator to display 1 or 0 on the Market Analyzer according to the SuperTrend indicator. The idea is simple: return 1 if trend is up and return 0 if trend is down. However, my code is somehow not working. Can you please help me ?

The code is:

protected override void OnBarUpdate()
{
if (Close[0] > SuperTrend(14, 2.618, true).UpTrend[0])

Plot0.Set(1);

else if (Close[0] < SuperTrend(14, 2.618, true).DownTrend[0])

Plot0.Set(0);

}
rodlm is offline  
Reply With Quote
Old 05-08-2012, 06:38 AM   #2
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello rodlm,
Welcome to the forum and I am happy to assist you.

Please check for a valid plot before accessing the values from the indicator. Please try the below code and see if it works or not
Code:
if (this.SuperTrend(14,2.618, false).UpTrend.IsValidPlot(0) && this.SuperTrend(14,2.618, false).UpTrend[0] < Close[0])
{
      Plot0.Set(1);
}
else if (this.SuperTrend(14,2.618, false).DownTrend.IsValidPlot(0) && this.SuperTrend(14,2.618, false).DownTrend[0] > Close[0])
{
	Plot0.Set(0);
}
Please let me know if I can assist you any further.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 05-08-2012, 09:40 AM   #3
rodlm
Junior Member
 
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

Hello Joydeep,

I've changed the code and I always get the number 1 in my Market Analyzer. The indicator is working perfectly on charts... but its not working in the Market Analyzer...

I'm sending you the complete code:

namespace NinjaTrader.Indicator
{
/// <summary>
/// Market Analyzer indicator. Returns 1 if trend is up and 0 if trend is down.
/// </summary>
[Description("Market Analyzer indicator. Returns 1 if trend is up and 0 if trend is down.")]
public class BooleanSuperTrend : Indicator
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// User defined variables (add any user defined variables below)
#endregion

/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
Overlay = false;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{

if (this.SuperTrend(14,2.618, false).UpTrend.IsValidPlot(0) && this.SuperTrend(14,2.618, false).UpTrend[0] < Close[0])
{
Plot0.Set(1);
}
else if (this.SuperTrend(14,2.618, false).DownTrend.IsValidPlot(0) && this.SuperTrend(14,2.618, false).DownTrend[0] > Close[0])
{
Plot0.Set(0);
}

}
rodlm is offline  
Reply With Quote
Old 05-08-2012, 11:09 AM   #4
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello,
It might be the case that the SuperTrend indicator is returning a wrong values in realtime mode. If I use the below code to print out the realtime values with CalculateOnBarClose set to false then it is only returning 0's (zero's).

Code:
if (!Historical) Print(SuperTrend(14,2.618, false).UpTrend[0].ToString() + "         " + SuperTrend(14,2.618, false).DownTrend[0].ToString());
Please debug your code using the Print function and make sure you are getting the correct values. Please refer to get an idea on how to debug a NinjaScript code efficiently
http://www.ninjatrader.com/support/f...ead.php?t=3418
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 05-08-2012, 02:47 PM   #5
rodlm
Junior Member
 
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

Humm... it's gonna be hard... and actually I don't understand, because the indicator works perfectly on charts in real time and in historical data...

The problem occurs only when trying to use it on Market Analyzer...

Anyway, thank you for your attention.
rodlm is offline  
Reply With Quote
Old 05-08-2012, 02:58 PM   #6
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

rodlm,

If you have you code available, please post and we could possibly see if we can identify the issue. I see you have code below. Did you change any of the custom plot series, or the properties section of the code?
NinjaTrader_AdamP is offline  
Reply With Quote
Old 05-09-2012, 05:28 AM   #7
rodlm
Junior Member
 
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

Hello AdamP,

I'm sending the code attached. Thank you for the reply.
Rodlm
Attached Files
File Type: cs BooleanSuperTrend.cs (7.2 KB, 9 views)
rodlm is offline  
Reply With Quote
Old 05-09-2012, 07:32 AM   #8
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

rod,

Please try adding the following and reporting any error messages.

try
{

// code I want to try

}
catch(Exception e)
{

Print(e.ToString());

}


This will print out if there are any errors at run time.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 05-09-2012, 12:34 PM   #9
rodlm
Junior Member
 
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

If I add the code I get the error message "Statement expected."
rodlm is offline  
Reply With Quote
Old 05-09-2012, 12:36 PM   #10
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

rodlm,

You most likely are missing a bracket somewhere or some other needed syntax item.

{ or } or ;
NinjaTrader_AdamP is offline  
Reply With Quote
Old 05-09-2012, 01:33 PM   #11
rodlm
Junior Member
 
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

Could you then post the complete code in the forum?
rodlm is offline  
Reply With Quote
Old 05-09-2012, 01:41 PM   #12
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

rod,

Using the indicator attached, I get market analyzer 0's and 1's and it works correctly on my charts.
Attached Files
File Type: zip BooleanSuperTrend.zip (5.9 KB, 46 views)
NinjaTrader_AdamP is offline  
Reply With Quote
Old 05-09-2012, 01:53 PM   #13
rodlm
Junior Member
 
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

Thank you very much for the code, AdamP...

I think there is any problem with my SuperTrend indicator, because I'm still getting only 1's in the Market Analyzer.

Its really funny, because it works perfectly on Charts...

:-(

Any suggestions? Reinstall SuperTrend indicator, maybe?
rodlm is offline  
Reply With Quote
Old 05-09-2012, 01:56 PM   #14
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

rod,

You may want to try using the supertrend that is included in that file.

Who is your data provider?
NinjaTrader_AdamP is offline  
Reply With Quote
Old 05-09-2012, 02:18 PM   #15
rodlm
Junior Member
 
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

I use eSignal and PFG Best.

Usually I'm connected with both services.

I usually connect first to PFG and second to eSignal.

And by the way, I reinstalled the SuperTrend indicator and now I'm using the one you provided.
rodlm 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
Historical boolean hamburglergt Strategy Development 1 03-01-2012 08:36 AM
Boolean Usage reference Faspomy Strategy Development 0 09-03-2009 09:33 PM
Boolean expressions and the Strat Wizard MXASJ Strategy Development 2 06-14-2009 06:28 AM
Why doesn't this boolean parameter work? cassb General Programming 2 09-22-2008 06:58 AM
Boolean log with integers jeremymgp Indicator Development 5 01-04-2008 07:36 AM


All times are GMT -6. The time now is 03:26 PM.