PDA

View Full Version : SetStopLoss and SetProfitTarget Assistance Needed


Scotty.Trump
07-07-2010, 01:04 PM
Hello,

I am attempting to code a simple short term long only strategy. For Profit Target and Stop Loss exits my attempts are:

if (Position.MarketPosition == MarketPosition.Long)
//(BarsSinceEntry() > 0)
{
SetProfitTarget(CalculationMode.Price, (Position.AvgPrice + ATR(5)[0]));
SetStopLoss(CalculationMode.Price, (Position.AvgPrice - ATR(5)[0]));
}

I want to take profit at my entry price plus ATR(5) and reverse for stop loss.

There are no compiling errors. My problem is that the exit values when backtesting are close to the nominal ATR value (rather than nominal ATR value plus/ minus the entry price). I am a beginner coder and cannot find the correct coding on any of the forums. Any direction for the proper code or helpful links would be appreciated.

Thanks!

NinjaTrader_Tim
07-07-2010, 02:10 PM
Hi Scotty.Trump,

What instrument is this on? It's possible that the value is negligible and you are seeing it as the same value of the current price.

A few things to check...
1. You can print the ATR value to the output using Print() statements
Something like... Print(ATR(5)[0]);
Print() - http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?Print

2. You can use TraceOrders to check if the orders are being submitted at a price you expect.
TraceOrders - http://www.ninjatrader.com/support/forum/showthread.php?t=3627

3. Also, ensure you are resetting the prices, as detailed in this sample - http://www.ninjatrader.com/support/forum/showthread.php?t=3222

Scotty.Trump
07-08-2010, 12:43 PM
Thank you Tim. I am testing on all instrument components in S&P. Thanks again, I will take a look.