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 05-05-2011, 01:37 PM   #1
olingerc
Member
 
Join Date: Jan 2011
Posts: 58
Thanks: 0
Thanked 0 times in 0 posts
Default I need two different stop loss/profit targets on the same strategy

Ok my strategy so far only enters trades from 9:55am to 3:55pm with this code
if ((ToTime(Time[0]) >= 095500 && ToTime(Time[0]) < 155500))

I have a profit target set to 26 ticks for this time frame in the "protected override void Initialize() and its

SetProfitTarget("", CalculationMode.Ticks, myInput4);
SetStopLoss("", CalculationMode.Ticks, myInput5, false);

What I need is the time frame divided up into 9:55 to lets say 11:30am and then 11:30am to 3:55pm. I need the earlier time to have a different stop loss/profit than the 11:30 to 3:55pm time frame.

Would I have to basically divide up my entire strategy into two separate parts for each time frame? And where do I put the profit target and stop loss codes, at the moment its a global parameter. I can post most of it in psudo code if that would help.
olingerc is offline  
Reply With Quote
Old 05-05-2011, 01:56 PM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hello olingerc,

Set statements will use the last value submitted. You can conditionally set them using OnBarUpdate(). If you're setting conditionally like this, you should replace the input you're using currently with a hard coded value or private variable.

if ((ToTime(Time[0]) >= 095500 && ToTime(Time[0]) < 113000))
//Set as 1 value here.


if ((ToTime(Time[0]) >= 113100 && ToTime(Time[0]) < 155500))
//Set as another value here.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 05-05-2011, 02:06 PM   #3
olingerc
Member
 
Join Date: Jan 2011
Posts: 58
Thanks: 0
Thanked 0 times in 0 posts
Default

Where do I put my two different profit targets then? Do I put it within the if statement for each time frame?
olingerc is offline  
Reply With Quote
Old 05-05-2011, 02:14 PM   #4
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Yes, you can adjust both stop loss and profit targets in the same block. If you have more than one line you wanted actioned after an if statement, place all lines within curly brackets {}

if ((ToTime(Time[0]) >= 095500 && ToTime(Time[0]) < 113000))
{
SetProfitTarget("", CalculationMode.Ticks, myInput4);
SetStopLoss("", CalculationMode.Ticks, myInput5, false);
}
NinjaTrader_RyanM is offline  
Reply With Quote
Old 05-05-2011, 02:19 PM   #5
olingerc
Member
 
Join Date: Jan 2011
Posts: 58
Thanks: 0
Thanked 0 times in 0 posts
Default

Ok thanks I will give this a try to see if it all works.
olingerc is offline  
Reply With Quote
Old 05-06-2011, 12:26 AM   #6
Baruch
Senior Member
 
Join Date: Mar 2009
Posts: 442
Thanks: 0
Thanked 25 times in 16 posts
Default

Quote:
Where do I put my two different profit targets then?
Don't do it like this. Just run two strategies. Each with its own SL&PT.
Baruch is offline  
Reply With Quote
Old 05-06-2011, 05:48 AM   #7
olingerc
Member
 
Join Date: Jan 2011
Posts: 58
Thanks: 0
Thanked 0 times in 0 posts
Default

I will try both. I do not know the code to flatten all current positions though. I have it to flatten all at end of trading cessions. But how do I flatten everything at lets say 11:30am?
olingerc is offline  
Reply With Quote
Old 05-06-2011, 06:02 AM   #8
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

You could only exit positions that are currently held by your individual strategy, just check for a certain time (Time property) and then call ExitLong() and ExitShort() as needed.
NinjaTrader_Bertrand 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
Wizard - strategy always exits on close instead of profit/stop targets Dan Leontieff Strategy Development 4 04-23-2009 05:27 AM
Stop loss / Profit targets raycam Automated Trading 2 02-27-2009 11:08 AM
Trailing Stop Loss/Profit Targets BigDog008 Strategy Development 3 02-26-2009 07:47 AM
How to set up profit and loss targets Owlman Strategy Development 4 12-14-2008 05:25 AM
how to place stop loss and profit targets qwert12 Automated Trading 1 11-04-2008 09:20 AM


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