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 > Strategy Development

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

Reply
 
Thread Tools Display Modes
Old 09-13-2009, 04:02 PM   #1
trader413
Member
 
Join Date: Oct 2007
Posts: 95
Thanks: 0
Thanked 0 times in 0 posts
Default Resetting a variable

Hi
I am trying to reset a variable after price pass above or below a certain point. For example if price crosses above or below yesterdays close reset this variable. I tried using the cross above/below function but I got errors.

I tried this

if (CrossBelow(High[0],PriorDayOHLC().PriorClose[0]))
tradeCount = 0;

But got a error message saying "No overload for method CrossBelow take 2 arguments.

How can get this to work?

Thanks
trader413 is offline  
Reply With Quote
Old 09-13-2009, 06:33 PM   #2
trader413
Member
 
Join Date: Oct 2007
Posts: 95
Thanks: 0
Thanked 0 times in 0 posts
Default

What am I doing wrong? I am trying to get the program to only take one trade until price crosses the close of the previous day or a new trading session begins. Aften then it is allowed to take another trade.

private int tradeCounter = 0;


if (tradeCounter == 1)
return;

if (Low[0]>=PriorDayOHLC().PriorClose[0])
tradeCounter = 0;

if (High[0] >= PriorDayOHLC().PriorClose[0] )
tradeCounter = 0;
if (Bars.FirstBarOfSession && FirstTickOfBar)
tradeCounter = 0;


if ( blah blah. )
EnterLong ;
tradeCounter++;


if (blah blah)
EnterLong ;
traderCounter++;
trader413 is offline  
Reply With Quote
Old 09-13-2009, 11:54 PM   #3
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,

If this is at the top of OnBarUpdate() then the rest of the code will never work if you have one trade open. You want the rest of the code to work all the time right?:
if (tradeCounter == 1)
return;

Don't you want EnterLong and tradeCounter in brackets like this so the counter only counts when a trade is executed?:

if ( blah blah. )
{
EnterLong ;
tradeCounter++;
}
NinjaTrader_Ben is offline  
Reply With Quote
Old 09-14-2009, 09:05 AM   #4
trader413
Member
 
Join Date: Oct 2007
Posts: 95
Thanks: 0
Thanked 0 times in 0 posts
Default

Ok thanks I got it. I have another problem. I am trying to reset the same variable after price pass above or below the previous day close. For example if price crosses above or below yesterdays close reset this variable. I tried using the cross above/below function with High[0]/Low[0] and priordayHOLC indicator but that did not work. I am now using cross above/below with priordayHOLC and a 1 period sma. That works but it does do the job fully. If the Low/High of a bar move below/above the prior days close the 1 period sma will not touch or cross the previous days closing price and the variable does not get reset. How can I program this ?

Thanks
trader413 is offline  
Reply With Quote
Old 09-14-2009, 09:15 AM   #5
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

trader413,

What have you tried originally?

CrossAbove(High, PriorDayOHLC().PriorClose[0], 1)
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-14-2009, 09:23 AM   #6
trader413
Member
 
Join Date: Oct 2007
Posts: 95
Thanks: 0
Thanked 0 times in 0 posts
Default

I tried those two and got an error.

CrossAbove(High[0], PriorDayOHLC().PriorClose[0], 1)
CrossBelow(Low[0], PriorDayOHLC().PriorClose[0], 1)
trader413 is offline  
Reply With Quote
Old 09-14-2009, 09:43 AM   #7
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 973 times in 956 posts
Default

Which error exactly did you get trader413?
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 09-14-2009, 10:09 AM   #8
trader413
Member
 
Join Date: Oct 2007
Posts: 95
Thanks: 0
Thanked 0 times in 0 posts
Default

I am not on my trading computer right now but I think the error I got was
"Argument '2': cannot convert from 'double' to 'NinjaTrader.Data.IDataSeries"
trader413 is offline  
Reply With Quote
Old 09-14-2009, 10:12 AM   #9
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Remove the [0] on the High and Low. You need to check DataSeries to double value not double value vs another double value.
NinjaTrader_Josh 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
resetting indicators dirtybrown Indicator Development 9 06-01-2009 02:06 PM
Resetting account performance ? T2020 Miscellaneous Support 2 09-08-2008 07:25 AM
Data values resetting Burga1 Indicator Development 5 05-23-2008 03:25 PM
Resetting SIM trades gygraham Strategy Analyzer 1 04-14-2008 07:01 PM
chart resetting question Lupus Charting 1 03-28-2006 08:50 AM


All times are GMT -6. The time now is 01:51 PM.