Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Different take profit exit conditions
Collapse
X
-
Different take profit exit conditions
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.Tags: None
-
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.RayNinjaTrader Customer Service
-
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.
Comment
-
creztor,
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
Enterlong(1,"ContractL1");
EnterLong(1,"ContractL2");
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
if(Position.MarketPosition==MarketPosition.Flat)
SetStopLoss("ContractL1",CalculationMode etc);
SetStopLoss("ContractL2",CalculationMode etc);
(you might reset here profittarget for ContractL2)
// Move StopLoss to Breakeven after T1
if(Position.Quantity==1)
SetStopLoss("ContractL2",CalculationMode.Price,Entryprice+TickSize,false);
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.
Comment
-
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?
Comment
-
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/v...ead.php?t=4033RayNinjaTrader Customer Service
Comment
-
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.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Touch-Ups, Today, 10:36 AM
|
0 responses
2 views
0 likes
|
Last Post
by Touch-Ups
Today, 10:36 AM
|
||
Started by geddyisodin, 04-25-2024, 05:20 AM
|
8 responses
61 views
0 likes
|
Last Post Yesterday, 10:45 AM | ||
Started by jxs_xrj, 01-12-2020, 09:49 AM
|
4 responses
3,289 views
1 like
|
Last Post
by jgualdronc
Today, 10:02 AM
|
||
Can someone turn this thinkscript into a ninjascript. 5PM CST OHL and Previous Day
by Option Whisperer
Started by Option Whisperer, Today, 09:55 AM
|
0 responses
5 views
0 likes
|
Last Post Today, 09:55 AM | ||
Started by halgo_boulder, 04-20-2024, 08:44 AM
|
2 responses
22 views
0 likes
|
Last Post Today, 09:41 AM |
Comment