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 07-03-2007, 01:10 PM   #1
aethelwulf
Junior Member
 
Join Date: Jul 2007
Posts: 3
Thanks: 0
Thanked 0 times in 0 posts
Default SetStopLoss Question

I'm trying to create a SetStopLoss that will place the stop loss at the low of the previous bar minus 2 pips. My entry name is called L1.

SetStopLoss("L1", CalculationMode.Price, Low[1]-2*TickSize, true);

This is what I came up with but it seems not to be working when a place the strategy on the chart or the backtester. Thanks for any help.
aethelwulf is offline  
Reply With Quote
Old 07-03-2007, 03:25 PM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

SetStopLoss() is a method that submits a stop loss triggered by the incoming fills of an order. Therefore, its called before any position is open.

There are many approaches to get done what you want but it depends on several variables. First one is, are you entering "L1" using a market order?

If yes, you can add the line as you shown in your post one line before your EnterLong() or EnterShort() call. This should do the trick.
NinjaTrader_Ray is offline  
Reply With Quote
Old 07-03-2007, 03:49 PM   #3
aethelwulf
Junior Member
 
Join Date: Jul 2007
Posts: 3
Thanks: 0
Thanked 0 times in 0 posts
Default

Thank you, that works good. I was wondering if i can enter a EMA stop loss instead of a Low[1]-2*ticksize. The ema would follow the ema after each new bar. Do i have to enter a bar update code to have the stop loss follow the EMA?
aethelwulf is offline  
Reply With Quote
Old 07-03-2007, 04:00 PM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Your understanding is correct. A few hints -

- When long, make sure the EMA value is less than the current bid, current ask when short...otherwise you can get rejected orders since the price may be invalid

- Yes, you have to update the price on each new OnBarUpdate() and pass in the new EMA value ... SetStopLoss("L1", CalculationMode.Price, EMA(20)[0], true);

- Make sure that the above call is ONLY made if you have an open position
NinjaTrader_Ray 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
Dynamically Modifying SetStopLoss() whitmark Strategy Development 6 10-13-2008 12:17 PM
SetStopLoss() & SetTrailStop() Concurrent Use whitmark Strategy Development 8 11-14-2007 09:05 AM
Currency in SetProfitTarget / SetStopLoss DarrylT Strategy Development 1 05-12-2007 10:54 AM
SetStopLoss and SetProfitTarget in Initialize FireFly Strategy Development 9 04-05-2007 11:52 PM
setstoploss order from TS 8.1 ppreal Automated Trading 15 12-20-2006 07:46 AM


All times are GMT -6. The time now is 10:41 PM.