NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 08-18-2012, 12:54 PM   #1
alabell
Senior Member
 
Join Date: Jun 2011
Posts: 214
Thanks: 34
Thanked 10 times in 10 posts
Default Question on resetting a stopLoss value

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
alabell is offline  
Reply With Quote
Old 08-18-2012, 02:52 PM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Andrew,

You could use something like :

if ( Position.MarketPosition == MarketPosition.Flat )
{

SetProfitTarget("SellShort", CalculationMode.Price, Default1);

SetStopLoss("SellShort", CalculationMode.Price, Default2 , false);

}
NinjaTrader_AdamP is offline  
Reply With Quote
The following user says thank you to NinjaTrader_AdamP for this post:
Old 08-18-2012, 04:01 PM   #3
alabell
Senior Member
 
Join Date: Jun 2011
Posts: 214
Thanks: 34
Thanked 10 times in 10 posts
Default

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.
alabell is offline  
Reply With Quote
Old 08-19-2012, 10:57 AM   #4
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

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.
NinjaTrader_AdamP is offline  
Reply With Quote
The following user says thank you to NinjaTrader_AdamP for this post:
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
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


All times are GMT -6. The time now is 08:33 AM.