![]() |
|
|||||||
| 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: Jan 2011
Posts: 58
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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.
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Jan 2011
Posts: 58
Thanks: 0
Thanked 0 times in 0 posts
|
Where do I put my two different profit targets then? Do I put it within the if statement for each time frame?
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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); }
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Jan 2011
Posts: 58
Thanks: 0
Thanked 0 times in 0 posts
|
Ok thanks I will give this a try to see if it all works.
|
|
|
|
|
|
#6 | |
|
Senior Member
Join Date: Mar 2009
Posts: 442
Thanks: 0
Thanked 25 times in 16 posts
|
Quote:
|
|
|
|
|
|
|
#7 |
|
Member
Join Date: Jan 2011
Posts: 58
Thanks: 0
Thanked 0 times in 0 posts
|
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?
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |