NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > Application Technical Support > Automated Trading

Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader.

Reply
 
Thread Tools Display Modes
Old 03-30-2007, 01:35 AM   #1
Oli
Member
 
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

Is there a way for me to make a Strategy terminate?

I would like to be able to build into my code a bunch of checking logic that if not satisfied will terminate the script.

Is this possible?
Oli is offline  
Reply With Quote
Old 03-30-2007, 01:59 AM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

The suggested method is checking for the condition to stop your strategy from processing and return out of the OnBarUdpate() method.

if (StopStrategyFromRunningCondition == true)
return;


NinjaTrader_Ray is offline  
Reply With Quote
Old 03-30-2007, 01:59 AM   #3
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

I should add, this should be called from OnBarUpdate() not Initialize(), I am unsure of implications of it being called there.
NinjaTrader_Ray is offline  
Reply With Quote
Old 03-30-2007, 02:12 AM   #4
Oli
Member
 
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

Thanks Ray,

I have been trying to set alerts with no luck, nothing happens:

Alert(
"string", Priority.Low,"Position Reported as Flat","C:\\Documents and Settings\\Trader\\My Documents\\Finance\\alert wavs\\alarm2.wav",5,Color.Beige,Color.AliceBlue);

The double \\ were necessary as the compiler keeps saying @unknown escape sequence@ which makes sense...

Maybe the Log is better than the Alert window...


Oli is offline  
Reply With Quote
Old 03-30-2007, 02:21 AM   #5
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

Try this:

Alert("string", Priority.Low,"Position Reported as Flat",@"C:\Documents and Settings\Trader\My Documents\Finance\alert wavs\alarm2.wav",5,Color.Beige,Color.AliceBlue);
NinjaTrader_Ray is offline  
Reply With Quote
Old 03-30-2007, 02:23 AM   #6
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

Also, I changed my post below, development corrected me and suggested not to set Running = false.

What is suggested is leaving the strategy running but returning out of OnBarUpdate().

So,

if (TerminateStrategyCondition == true)
return;


Ray
NinjaTrader_Ray is offline  
Reply With Quote
Old 03-30-2007, 02:33 AM   #7
Oli
Member
 
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

Still no good.

Am using this code with private bool Init = true; declared in variables :



protectedoverridevoid OnBarUpdate()

{

if (Init){

Alert(
"string", Priority.Low,"Position Reported as Flat",@"C:\Documents and Settings\Trader\My Documents\Finance\alert wavs\alarm2.wav",5,Color.Beige,Color.AliceBlue);



Log(Instrument +
" reported FLAT", LogLevel.Information);

Init =
false;

}

}
Oli is offline  
Reply With Quote
Old 03-30-2007, 02:33 AM   #8
Oli
Member
 
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

Ah yes the empty return... and the Log write works, only the Alert doesn't
Oli is offline  
Reply With Quote
Old 03-30-2007, 02:55 AM   #9
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

For clarification,

- The alert will not compile?
- The alert does not generate an alert?

If the latter, alerts only trigger on real-time data, not historical.

Ray
NinjaTrader_Ray is offline  
Reply With Quote
Old 03-30-2007, 02:58 AM   #10
Oli
Member
 
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

Compiles and runs fine:

Chart is real time with live data

the condition Init is true under all conditions and should trigger OnBarUpdate.


The alert window remains empty
Oli is offline  
Reply With Quote
Old 03-30-2007, 03:06 AM   #11
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

By the looks of your code sample, it should trigger only once on the first bar and not after that since you are setting Init= false.

If you create a new strategy an in the OnBarUpdate() include the following line, you will see alerts generated.

Alert(
"string", Priority.Low, "Position is reported as flat", @"C:\Program Files\NinjaTrader 6\Sounds\Alert1.wav", 5, Color.Black, Color.Yellow);

Ray
NinjaTrader_Ray 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


All times are GMT -6. The time now is 12:09 AM.