NinjaTrader Support Forum  

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 05-16-2008, 11:04 AM   #1
Burga1
Senior Member
 
Join Date: Nov 2007
Posts: 388
Thanks: 0
Thanked 0 times in 0 posts
Default Strange effect

Greetings,

I have the following code to write to a file, taken directly from MSDN, the file writes to the NT 6.5 folder, and it works just fine:

string path = Cbi.Core.UserDataDir.ToString() + 17Closes.inp"; FileInfo fi1 = new FileInfo(path);
if (!fi1.Exists)
{
//Create a file to write to.
using (StreamWriter sw = fi1.CreateText())
{
sw.WriteLine("Hello");
sw.WriteLine("And");
sw.WriteLine("Welcome");
sw.Close(); Print("Wrote a Line");
}
}

If I add some code just before that, a "loop" designed to take a sequence of Close periods in order to average them, for example:

COUNTER = 17; AI_index = 0; AVERAGE = 0; FIRST_ROUND = 0;


LOADER:


if(FIRST_ROUND == 0)
{
value = Close[AI_index];
INPUTS.Set(AI_index, value);
AVERAGE += INPUTS[AI_index];
} //FIRST_ROUND is 0

AI_index += 1; if(AI_index < COUNTER){goto LOADER;}

Print( "0: " + INPUTS[0]); Print( "1: " + INPUTS[1]);
...etc to INPUTS[16]



Suddenly everything changes. The previous output file does not get created, and the Output Window does not show the "Print" commands. Obviously there is a problem being caused by the "looping" code, but I have no idea what it is...seperately both sets of code work perfectly, combined not at all...why? Any ideas appreciated.
Burga1 is offline  
Reply With Quote
Old 05-16-2008, 11:32 AM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

You would need to roll up your sleeves and debug your code e.g. per here: http://www.ninjatrader-support.com/v...ead.php?t=3418
NinjaTrader_Dierk is offline  
Reply With Quote
Old 05-16-2008, 12:26 PM   #3
Burga1
Senior Member
 
Join Date: Nov 2007
Posts: 388
Thanks: 0
Thanked 0 times in 0 posts
Default

Thank you. Is there any efficient way to determine if a price of an instrument is an "even base" number, for example prices like: 1.5600, 1.5500, 1.5400, 1.5300...etc? I believe it is related to my problem.
Burga1 is offline  
Reply With Quote
Old 05-16-2008, 12:46 PM   #4
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Could could try playing with the '%' C# operator. This calculates the remainder.

if ((value * 1000) % 100 == 0) { /* do something */ }

Please check out the MS docs for how this works.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 05-16-2008, 01:14 PM   #5
Burga1
Senior Member
 
Join Date: Nov 2007
Posts: 388
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Dierk, that seems helpful. Is it possible to pass that Modulo info into another value such as a double or a string?
Burga1 is offline  
Reply With Quote
Old 05-16-2008, 11:08 PM   #6
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Yes it is.
NinjaTrader_Dierk 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
When does re-compiled strategy take effect verge Strategy Development 1 05-16-2008 03:45 AM
Strange T&S output foxthorn Miscellaneous Support 1 11-29-2007 09:58 AM
Compilation not taking effect astrolobe Indicator Development 5 10-25-2007 12:54 AM
Strange Strategy behavior scjohn Strategy Development 1 07-24-2007 11:35 AM
Strange error on compile maxpi Indicator Development 4 07-24-2007 07:20 AM


All times are GMT -6. The time now is 01:56 AM.