PDA

View Full Version : questions from New Subscriber


murfinp
01-31-2007, 10:08 AM
Hi

A couple of questions maybe osomebody can help me with:

1) How do I determine if a price tick is the first tick of a new bar

2) How do I move a stop loss

3) How do I specify the no of fx mini contracts

Thanks



Paul

NinjaTrader_Ray
01-31-2007, 10:32 AM
Paul,

1) Seethe Help Guide FirstTickOfBar property (this is only of value when CalculateOnBarClose == false)

2) Are you submitting a stop loss via SetStopLoss() or ExitLongStop() or ExitShortStop()

3) Any of the Enter() or Exit() methods have an optional quantity parameter or if not passed in, you can set the quantity when adding a strategy to a chart in the strategy dialogue window.

Ray

murfinp
02-01-2007, 05:57 AM
Hi Ray



I don't know - just looking at how to do it. Basically I want to place a market order with an initial stop loss then on the first tick of each new bar I want to move the stop loss to n pips from a moving average based level. Also if a certain other condition gets hit I want to close the position and obviously remove the stop loss. What would be the best way to implement this.



Thanks for your help



Paul

NinjaTrader_Ray
02-01-2007, 12:53 PM
Here is a snippet for the OnBarUpdate() method thatis an example that will do what you want.

// This method will create a stop loss order 10 ticks from entry on incoming fill from an entry order
if (Position.MarketPosition == MarketPosition.Flat)
SetStopLoss(CalculationMode.Ticks, 10);

// Go long if close is greater than 15 ticks above the 50 period SMA
if (Close[0] > SMA(50)[0] + 15 * TickSize)
EnterLong();

// If long, change the stop price to 1 tick below the 50 period SMA
if (Position.MarketPosition == MarketPosition.Long)
SetStopLoss(CalculationMode.Price, SMA(50)[0] - TickSize);

// Exit if close is less than 15 ticks above 50 period SMA and have been in trade 30 bars
if (Close[0] < SMA(50)[0] + 15 * TickSize && BarsSinceEntry() >= 30)
ExitLong();

KBJ
03-24-2007, 05:46 AM
Does this then mean that a stop loss can be changed once set for a trade?

Part of my confusion on this is that your example...

// If long, change the stop price to 1 tick below the 50 period SMA
if (Position.MarketPosition == MarketPosition.Long) SetStopLoss(CalculationMode.Price, SMA(50)[0] - TickSize);
...is obviously for use in the OnBarUpdate() method, whereas the help file description of SetStopLoss() says it "should be called from within the strategy Initialize() method."

So, have the rules changed on this? And what happens if additional SetStopLoss() calls are made for subsequent OnBarUpdate() calls? Will each one replace the last? And can we selectively replace the stop losses by specifying a "fromEntrySignal" parameter on each SetStopLoss() call?

NinjaTrader_Ray
03-24-2007, 05:54 AM
KBJ wrote: Does this then mean that a stop loss can be changed once set for a trade?Yes.

Part of my confusion on this is that your example...

// If long, change the stop price to 1 tick below the 50 period SMA if (Position.MarketPosition == MarketPosition.Long) SetStopLoss(CalculationMode.Price, SMA(50)[0] - TickSize);
...is obviously for use in the OnBarUpdate() method, whereas the help file description of SetStopLoss() says it "should be called from within the strategy Initialize() method."Documentation will be updated with the next release.

So, have the rules changed on this? And what happens if additional SetStopLoss() calls are made for subsequent OnBarUpdate() calls? Will each one replace the last?Correct. Because of this, it is important to add a check in OnBarUpdate() for a flat position, and then call the SetStopLoss() method again and pass in the starting offset of a stop loss price when a new position is entered, otherwise the last known offset value will be used. And can we selectively replace the stop losses by specifying a "fromEntrySignal" parameter on each SetStopLoss() call?Yes you can.