View Full Version : Problems with Set Profit Target?
mazachan
09-20-2007, 03:13 PM
Hi I have been trying to move my profit targets, but I am experience an interesting phenomena. If I move the profit target, it seems like if I was in a long position, it will exit that position and enter a short position. Would I be better off using an ExitLongLimit instead?
Thanks
NinjaTrader_Ray
09-20-2007, 03:18 PM
- How are you moving it?
- SetProfitTarget() will not reverse your position so there must be something else triggering a reverse position
Thanks
mazachan
09-20-2007, 03:20 PM
hmm. I just have SetProfitTarget and SetStopLoss on FirstBarOfTick. I put in debugging statements in the method and it's printing out the stop loss and the profit targets correctly. I am also checking the market position and adjusting the targets accordingly.
NinjaTrader_Ray
09-20-2007, 03:23 PM
Please take a look at the following reference file for the correct approach to modifying a orders generated by a Set..() method.
http://www.ninjatrader-support.com/vb/showthread.php?t=3222
mazachan
09-20-2007, 03:27 PM
While it does not explicitly state it, when I submit a new SetProfitTarget does that cancel and replace the old one?
NinjaTrader_Ray
09-20-2007, 03:30 PM
Not if is at the same price, if its a different price it will change it.
mazachan
09-20-2007, 03:49 PM
Is there a way to "force" a strategy into a position so that I can better debug this?
NinjaTrader_Ray
09-20-2007, 03:51 PM
Sure, try:
EnterLong();
as the first line of your OnBarUpdate() method.
mazachan
09-20-2007, 04:31 PM
This is odd. I have EnterLong as the first line of OnBarUpdate and I ran the strategy. I set the session times to 12:00 AM-12:00AM and set the account to Sim101. I have it running on the Simulator feed and nothing clicked in. Are there any other restrictions that are preventing the strategy from entering a trade?
Edit: NM, it seems to have clicked in, however the stop and the profit targets are not showing up.
NinjaTrader_Ray
09-20-2007, 04:41 PM
In post #4 there is a link to a reference sample illustrating the correct use of the Set...() methods. A great start would be to take that sample, run that, then make minor modifications so that you become familiar with the operation and expected behaviour.
mazachan
09-20-2007, 04:48 PM
Yes, I am currently doing that. However, there does not seem to be any rhyme or reason as to why my code is not working and I am trying to work through that.
Thanks for your help Ray.
mazachan
09-20-2007, 05:25 PM
Hi Ray, I think I found the issue(s). For some reason if I call SetTrailStop or SetProfitTarget within a helper function in the class, it would not execute an EnterLong order. Once I moved my logic for changing the stops and profit targets to within OnBarUpdate, it seems to have fixed the problem.
NinjaTrader_Ray
09-21-2007, 06:52 AM
Excellent, thanks for reporting back.