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!
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!