![]() |
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
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
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); } |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
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);
}
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
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); } } |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
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()); http://www.ninjatrader.com/support/f...ead.php?t=3418
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
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?
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
Hello AdamP,
I'm sending the code attached. Thank you for the reply. Rodlm |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
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.
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Junior Member
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
If I add the code I get the error message "Statement expected."
|
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
rodlm,
You most likely are missing a bracket somewhere or some other needed syntax item. { or } or ;
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Junior Member
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
Could you then post the complete code in the forum?
|
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
rod,
Using the indicator attached, I get market analyzer 0's and 1's and it works correctly on my charts.
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Junior Member
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#14 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
rod,
You may want to try using the supertrend that is included in that file. Who is your data provider?
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#15 |
|
Junior Member
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |