![]() |
|
|||||||
| 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. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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;
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
I should add, this should be called from OnBarUpdate() not Initialize(), I am unsure of implications of it being called there.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#4 |
|
Member
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
|
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... |
|
|
|
|
|
#5 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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);
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Member
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
|
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; } } |
|
|
|
|
|
#8 |
|
Member
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
|
Ah yes the empty return... and the Log write works, only the Alert doesn't
|
|
|
|
|
|
#9 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Member
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#11 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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
Ray
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|