View Full Version : Different take profit exit conditions
07-19-2007, 06:59 AM
Ok yes I do realize this is most likely beyond support offered by NT staff, but if anyone else can help would be appreciated. I enter a trade with 2 positions and stoploss set at x pips. I am looking to exit 1 lot at x pips profit and move the 2nd lot stoploss to breakeven and then set its new take profit at x pips. Any help and point in a direction to read would be greatly appreciated, with chocolate on top.
07-19-2007, 07:41 AM
What I usually do is break down a task into individual components. I tackle component 1, ensure it works as expected and then layer on component 2.
So in your case, I would start by creating a strategy that enters 1 lot, exits at predetermined stop and profit. Get this to work as you expect. Then add the next layer of logic, move the target to the next end point, then add logic to move stop to breakeven once first profit level is reached. Once you have this working, then work on adding the second position.
07-20-2007, 10:08 AM
Thanks for that, yes I completely agree a task needs to be broken down into steps. So this is for other members of the forum who can help if possible please. I am looking at how exactly to close different lots at different set targets. I have no problems making a system that enters 2 lots and then exits at a specified target (thanks to the great auto system generator in NT) my problem lies with moving stops to breakeven and then setting a new take profit level. If there was example code that came with NT I would look at it but from what Ive seen the examples dont get this complex.
08-15-2007, 12:01 PM
I am trying to do the same as you do.
I tell you what I did, however I am still missing one piece, namely the entry price.
But you see my way of thinking
First I think that CalculateOn BarClose should be set to false, because the moment T1 is reached you want to set the stoploss to breakeven.
If you want to trade at the end of the bar you might include in your entry conditions
if(Bars.PercentComplete>0.9 the entry will be executed when 90 % or more of the bar is completed.
Lets take the long side.
the entry might look like
In the initialize section you might put
SetProfitTarget("ContractL1", CalculationMode etc ); //for ContractL1
SetStopLoss("ContractL1"',CalculationMode etc ); // for ContractL1
SetStopLoss("ContractL2"',CalculationMode etc ); // for ContractL2
In the OnBarUpdate section you might put
// reset Stoploss at flat position
(you might reset here profittarget for ContractL2)
// Move StopLoss to Breakeven after T1
Here you can also put a (new) profittarget for ContractL2
I still have to find out how to get the the entry price of ContractL2. I have seen something like Position.AvgPrice
I hope that this is usefull. Should appreciate your - and from anybody else- comments.
08-15-2007, 12:43 PM
If you separate the entry order in separate orders of 1 contract you need to put in the initialize section
(if you have 5 separate orders)
I was just running the strategy on live data and it took only 1 contract.
01-16-2008, 11:11 AM
How does roll in forex effect the entry price of a position if you use the Position.AvgPrice method to retrieve that price to use for exit orders?
01-16-2008, 11:31 AM
What do you mean by roll? Position.AvgPrice in a strategy is based on executions in the strategy and not your account position.
More information on that here - http://www.ninjatrader-support.com/vb/showthread.php?t=4033
01-16-2008, 11:36 AM
My fault, I had a typo in my code and couldn't figure out why it was generating the wrong order. I have that part working now. Thank you.