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

 12-21-2017, 09:14 PM #1 TexFly Senior Member   Join Date: Aug 2012 Posts: 164 Thanks: 3 Thanked 4 times in 4 posts Simple calculation Hello, I'm trying to do a simple calculation on OnBarUpdate() but I keep getting errors. I have researched but I can't make it work. I have three different indicator lengths and I want to calculate the average. Something like this: This is declared in the class above the OnStateChange() private SMA SMA1; private SMA SMA2; private SMA SMA3; Then OnBarUpdate() SMA1 = SMA(5); SMA2 = SMA(20); SMA3 = SMA(50); AvgSMA=(SMA1+SMA2+SMA3)/3; double highsignal = 90; if (CrossAbove(AvgSMA, highsignal, 1)) EnterLong("AALong"); But I keep getting errors about converting double to a series and vice versa. I have tried to declare all doubles but the CrossAbove doesn't like it neither... What's the best way to accomplish this? Thanks for the help.
12-21-2017, 11:35 PM   #2
nkhoi
Senior Member

Join Date: Nov 2004
Location: , ,
Posts: 186
Thanks: 10
Thanked 38 times in 27 posts

the message is misleading, you need to use [0] for the actual calculation..
example: ZerolagTEMA[0] = 2*tema1[0] - tema2[0];
AvgSMA[0]=(SMA1[0]+SMA2[0]+SMA3[0])/3
I include an indicator from fattail to show where you suppose to call the EMAs
Attached Files
 amaZerolagTEMA.cs (6.2 KB, 3 views)
Last edited by nkhoi; 12-21-2017 at 11:39 PM.

12-22-2017, 05:45 AM   #3
TexFly
Senior Member

Join Date: Aug 2012
Posts: 164
Thanks: 3
Thanked 4 times in 4 posts

Quote:
 Originally Posted by nkhoi the message is misleading, you need to use [0] for the actual calculation.. example: ZerolagTEMA[0] = 2*tema1[0] - tema2[0]; AvgSMA[0]=(SMA1[0]+SMA2[0]+SMA3[0])/3 I include an indicator from fattail to show where you suppose to call the EMAs
Thanks nkhoi. Unfortunately it still doesn't work...

SMA1 = SMA(10);
SMA2 = SMA(20);
SMA3 = SMA3(30);

AvgSMA[0]=(SMA1[0]+SMA2[0]+SMA3[0])/3

double highsignal = 90;
double lowsignal = 10;

if (CrossAbove(AvgSMA[0], highsignal, 1))
EnterLong();

if (CrossBelow(AvgSMA[0], lowsignal, 1))
EnterShort();

plus a second error

"Cannot implicitly convert type 'NinjaTrader.NinjaScript.Indicators.SMA' to 'double'"....

I have declared the AvgSMA in the properties

public Series<double> AvgSMA
{
get { return Values[0]; }
}

and the three SMA series on top right below the class definition...

private SMA SMA1;
private SMA SMA2;
private SMA SMA3;

Any other idea?
Last edited by TexFly; 12-22-2017 at 05:48 AM.

 The following user says thank you to NinjaTrader_Paul for this post:
 12-22-2017, 06:36 PM #5 TexFly Senior Member   Join Date: Aug 2012 Posts: 164 Thanks: 3 Thanked 4 times in 4 posts Paul, Great explanation. It works now. Thanks!

 Thread Tools Display Modes Linear Mode

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home News and Announcements     News and Announcements NinjaTrader 8     Platform Technical Support     Add-On Development     Indicator Development     Strategy Development NinjaTrader 7     Platform Technical Support     General Development     Indicator Development     Strategy Development NinjaScript File Sharing     NinjaScript File Sharing Discussion     Version 8 Add-Ons     Version 8 Indicators     Version 8 Strategies     Version 7 Indicators     Version 7 Strategies     Version 7 Miscellaneous NinjaScript Educational Resources     Reference Samples     Tips Suggestions and Feedback     Suggestions And Feedback Historical Beta Archive     Version 8 Beta

 Similar Threads Thread Thread Starter Forum Replies Last Post linzvb Platform Technical Support 7 08-25-2016 08:13 AM Laimis Strategy Development 3 06-01-2016 08:10 AM eberline Platform Technical Support 19 04-07-2015 12:53 PM forrestang Indicator Development 2 01-06-2010 09:19 PM shakira Strategy Development 1 02-14-2009 11:56 AM

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

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.