![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jun 2011
Posts: 214
Thanks: 34
Thanked 10 times in 10 posts
|
In help, I have read:
"· It is suggested to call this method from within the strategy Initialize() method if your stop loss price/offset is static · You may call this method from within the strategy OnBarUpdate() method should you wish to dynamically change the stop loss price while in an open position · Should you call this method to dynamically change the stop loss price in the strategy OnBarUpdate() method, you should always reset the stop loss price/offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss order on your next open position." I am calculating a value that will need to be reset as the market moves. My code currently looks like this: SetProfitTarget("SellShort", CalculationMode.Price, (Position.AvgPrice - shortProfit)); SetStopLoss("SellShort", CalculationMode.Price, (Position.AvgPrice + shortStopLoss), false); How do reset said value as mentioned above so that when I flatten i can begin the process completely anew...? Thanks in advance, Andrew |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
Andrew,
You could use something like : if ( Position.MarketPosition == MarketPosition.Flat ) { SetProfitTarget("SellShort", CalculationMode.Price, Default1); SetStopLoss("SellShort", CalculationMode.Price, Default2 , false); }
Adam P.
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_AdamP for this post: |
|
|
|
#3 |
|
Senior Member
Join Date: Jun 2011
Posts: 214
Thanks: 34
Thanked 10 times in 10 posts
|
Ty Adam,
the obvious question emerges: Why does setting something to default1 or 2 help my process, and how do I define these values? Isn't that no better than leaving them alone...or is the process actually there to create a condition of "flat" which then becomes false upon new entry? ...so i could make double default1 equal to "1,000,000,000,000" and double default 2 equal to "0.00003"...? Do I have this right? Thanks and regards. |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
alabell,
The default1 and default2 were just place-holders. You can set these fields to whatever you want. Essentially, the idea is to reset your stop loss and take profit to a default value that you can either setup as a variable or just put it directly where default1 or default2 sit.
Adam P.
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_AdamP for this post: |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why is setstop resetting when I don't think it should be? | coolmoss | Strategy Development | 5 | 03-28-2012 08:40 AM |
| Stoploss question | maratrm | Charting | 3 | 02-21-2012 01:02 PM |
| StopLoss Question | edgeliner | Strategy Development | 2 | 05-05-2011 11:32 AM |
| Resetting a variable | trader413 | Strategy Development | 8 | 09-14-2009 10:12 AM |
| chart resetting question | Lupus | Charting | 1 | 03-28-2006 08:50 AM |