PDA

View Full Version : Changing the Profit Target


SuzyG
01-04-2007, 07:34 AM
From a strategy script, can I change the target in SetProfitTarget elsewhere other than ininitialize()?

NinjaTrader_Ray
01-04-2007, 09:39 AM
No, this method is not intended to dynamically changea profit target, from what I recall, will check on that.

Here is an option:

In replace of SetProfitTarget(),use an ExitLimit() within the OnBarUpdate() method itself. Just make sure youcall this method on each bar. Theupsideis you can change the price on each bar/tick. The downside is thatthe order will not be submitted until the followingbar/tick afterentry.

Example code:
private double targetPrice = 0;
private override void OnBarUpdate()
{
if (SMA(5)[0]> SMA(10)[0])
EnterLong();

targetPrice = Math.Max(targetPrice, Low[0]);
ExitLongLimit(targetPrice);
}

NinjaTrader_Ray
01-05-2007, 07:55 AM
Suzy,

Apparently it should work within the OnBarUpdate() method. Reviewing the code and running the test script below works.



/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>



protected override void OnBarUpdate()

{

if (Historical)

return;



EnterLong();



if (Position.MarketPosition == MarketPosition.Flat || BarsSinceEntry() < 3)

SetStopLoss(CalculationMode.Ticks, 10);

else



SetStopLoss(CalculationMode.Ticks, 5);

}