NexusFi: Find Your Edge


Home Menu

 





Can I use a DataSeries as part of an 'if' statement?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one magnumdbl with 4 posts (0 thanks)
    2. looks_two ShruggedAtlas with 2 posts (2 thanks)
    3. looks_3 cory with 2 posts (2 thanks)
    4. looks_4 Big Mike with 1 posts (1 thanks)
      Best Posters
    1. looks_one cory with 1 thanks per post
    2. looks_two ShruggedAtlas with 1 thanks per post
    3. looks_3 Big Mike with 1 thanks per post
    4. looks_4 jeremytang with 1 thanks per post
    1. trending_up 4,399 views
    2. thumb_up 6 thanks given
    3. group 4 followers
    1. forum 11 posts
    2. attach_file 0 attachments




 
Search this Thread

Can I use a DataSeries as part of an 'if' statement?

  #1 (permalink)
 magnumdbl 
Cranford, New Jersey, USA
 
Experience: Advanced
Platform: Tradestation, Ninja Trader
Broker: TS and MB Trading
Trading: ES, EC
Posts: 10 since Dec 2010
Thanks Given: 8
Thanks Received: 2

I tried to use a DataSeries called "cond1"
similar to the way Scott did in his TimeToTrade code with ' _signal', but couldn't get it to work.

I declared it in Variables with
private DataSeries cond1;

I initialized it as cond1 = new DataSeries(this);

I set it with cond1.Set(+1);

I put it in Properties with
public DataSeries Cond1 (not sure which one I should use.)
{
// get { return cond1; } //c I tried both of these.
get { return Values[4]; } //d

but when I tried to use it with (not sure about this either)
// if (cond1[0] = 1) //a I tried both of these.
if (cond1 = 1) //b

I got these errors from the above combinations:

a & c = Cannot implicitly convert type double to bool
a & d = Cannot implicitly convert type double to bool
b & d = Cannot implicitly convert type 'int' to DataSeries
b & c = Cannot implicitly convert type 'int' to DataSeries

I've been programming TS for years and am 2wks into C# trying
to go thru as many webinars etc as possible.
But something is not sinking in.
Hoping someone can point me in the right direction.

Don

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Are there any eval firms that allow you to sink to your …
Traders Hideout
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Exit Strategy
NinjaTrader
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
Battlestations: Show us your trading desks!
26 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
  #3 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090


but of course, go to \My Documents\NinjaTrader 7\bin\Custom\Indicator
take a look at @stochastics.cs coding it has exactly what you are looking for

Reply With Quote
Thanked by:
  #4 (permalink)
 magnumdbl 
Cranford, New Jersey, USA
 
Experience: Advanced
Platform: Tradestation, Ninja Trader
Broker: TS and MB Trading
Trading: ES, EC
Posts: 10 since Dec 2010
Thanks Given: 8
Thanks Received: 2


cory View Post
but of course, go to \My Documents\NinjaTrader 7\bin\Custom\Indicator
take a look at @ stochastics.cs coding it has exactly what you are looking for

I noticed in that code that they didn't put anything in the 'Properties' region.
when do I have to put DataSeries etc. into the Properties?

So I took cond1 out of the properties and used the

if( cond1 = 1)

statement and got the error: cannot implicity convert 'int' to NT Data.DataSeries'

I'm stillconfused.

Thanks,
Don

Started this thread Reply With Quote
  #5 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090


magnumdbl View Post
I noticed in that code that they didn't put anything in the 'Properties' region.
when do I have to put DataSeries etc. into the Properties?

So I took cond1 out of the properties and used the

if( cond1 = 1)

statement and got the error: cannot implicity convert 'int' to NT Data.DataSeries'

I'm stillconfused.

Thanks,
Don

click + sign next to 'Properties' region to expanse it.


data series are in:
.............
#region Variables
private int periodD = 7; // SlowDperiod
private int periodK = 14; // Kperiod
private int smooth = 3; // SlowKperiod
private DataSeries den;
private DataSeries nom;
private DataSeries fastK;
#endregion
..............

protected override void Initialize()
{
Add(new Plot(Color.Green, "D"));
Add(new Plot(Color.Orange, "K"));

Add(new Line(Color.DarkViolet, 20, "Lower"));
Add(new Line(Color.YellowGreen, 80, "Upper"));

den = new DataSeries(this);
nom = new DataSeries(this);
fastK = new DataSeries(this);
}
...............

Reply With Quote
Thanked by:
  #6 (permalink)
 magnumdbl 
Cranford, New Jersey, USA
 
Experience: Advanced
Platform: Tradestation, Ninja Trader
Broker: TS and MB Trading
Trading: ES, EC
Posts: 10 since Dec 2010
Thanks Given: 8
Thanks Received: 2

Thanks for your patients, but that doesn't quite solve my problem.

e.g. I see that in the Stochastics, den is not mentioned in the Properties section.

So I took my 'cond1' variable out of my Properties section .

HOWEVER

when I set my cond1 with cond1.Set(1)

and then try to use it in an 'if' statement such as

if(cond1 = 1)

{

}

I get the error message that I cannot implicitly convert an 'int' to a DataSeries.

Does that make sense?

Don

Started this thread Reply With Quote
  #7 (permalink)
 traderwerks   is a Vendor
 
Posts: 692 since Jun 2009
Thanks Given: 436
Thanks Received: 465


magnumdbl View Post

if(cond1 = 1)

{

}

I get the error message that I cannot implicitly convert an 'int' to a DataSeries.

Does that make sense?

Don

Yes, it does. First, cond = 1 is a conversion, not a comparison.

Make sure both sides of a comparison are of the same type.

Math. A gateway drug to reality.
Reply With Quote
  #8 (permalink)
 magnumdbl 
Cranford, New Jersey, USA
 
Experience: Advanced
Platform: Tradestation, Ninja Trader
Broker: TS and MB Trading
Trading: ES, EC
Posts: 10 since Dec 2010
Thanks Given: 8
Thanks Received: 2

Thanks for your previous advice.
I did get thru another 60 pages in the C# reference manual and that helped also.

In the ZigZagUTC i see numbers with 15 decimal places. Is there a place to select how many decimals?

I also looked at the Sample FontChange reference in ninja. Was wondering if there is a demo that shows how to allow choice of font SIZE(pxl) in the Indicator Panel?

Would like to be able to make a similar choice for DrawDot size . Any references or examples of that?

Thanks,
Don

Started this thread Reply With Quote
  #9 (permalink)
 
ShruggedAtlas's Avatar
 ShruggedAtlas 
Bloomington
 
Experience: Beginner
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Stocks
Posts: 191 since Apr 2011
Thanks Given: 78
Thanks Received: 75

This maybe talking about something else entirely but i've seen this before in my own coding (i'm a beginner here)

If statements compare two or more data types that must be the same. It must evaluate to either true or false (a bool)

if(EMA(8))
{ //would produces a type conversion error because it's looking to evaluate to bool but this is a series}

if(EMA(8)[0]))
{//would produce a type conversion error because this statement does not produce true or false evaluation only an int}

if(EMA(8)[0] == EMA(8)[0])
{//this would produce either a true or false evaluation and would not produce any errors because the conditions of the
// if statement have been satisfied}

In your code find out exactly what cond1 is. if it is s series you need to choose one data point in the series and compare it to another piece of data of the same type in order to have a valid if statement.

I could be wrong here but I went through the same issues when i was figuring out conditional statements like if. Can someone else verify that I'm correct?

"I've missed more than 9,000 shots in my career. I've lost almost 300 games. 26 times, I've been trusted to take the game-winning shot and missed. I've failed over and over and over again in my life. And that is why I succeed."
- Michael Jordan, 5-Time NBA Most Valuable Player, 6-Time NBA Champion
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #10 (permalink)
 
ShruggedAtlas's Avatar
 ShruggedAtlas 
Bloomington
 
Experience: Beginner
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Stocks
Posts: 191 since Apr 2011
Thanks Given: 78
Thanks Received: 75



traderwerks View Post
Yes, it does. First, cond = 1 is a conversion, not a comparison.

Make sure both sides of a comparison are of the same type.

Oh i just noticed that!

you would want something like this:

if (cond1 == 1)

but that won't work if cond1 is a series. You'd get an error I think

"I've missed more than 9,000 shots in my career. I've lost almost 300 games. 26 times, I've been trusted to take the game-winning shot and missed. I've failed over and over and over again in my life. And that is why I succeed."
- Michael Jordan, 5-Time NBA Most Valuable Player, 6-Time NBA Champion
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on February 11, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts