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
Strategy Builder: Add ATR-value as TakeProfit and StopLoss
Collapse
X
-
Hello Induna,
The trade is getting stopped out with an order called "Stop loss" This would be seen when using SetStopLoss. Set methods in the Strategy Builder will be placed in State.Configure which is processed on strategy start up. Setting SetStopLoss to a variable that changes in OnBarUpdate will not have an effect here since the method is not called again.
You can use exit methods in Conditions and Actions to move a Stop Market order to a value that is calculated when the strategy processes data. (I.E. indicator plots or variables calculated in Conditions and Actions.)
If you would like to look further into how a strategy can move the stop loss using Set methods, this will require unlocking the code, but you can use the example below for reference.
Please let us know if we can be of further assistance.JimNinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Jim View PostHello Induna,
The trade is getting stopped out with an order called "Stop loss" This would be seen when using SetStopLoss. Set methods in the Strategy Builder will be placed in State.Configure which is processed on strategy start up. Setting SetStopLoss to a variable that changes in OnBarUpdate will not have an effect here since the method is not called again.
You can use exit methods in Conditions and Actions to move a Stop Market order to a value that is calculated when the strategy processes data. (I.E. indicator plots or variables calculated in Conditions and Actions.)
If you would like to look further into how a strategy can move the stop loss using Set methods, this will require unlocking the code, but you can use the example below for reference.
Please let us know if we can be of further assistance.
So I can cut the SetStoploss and the SetProfitTargets from the OnStateChange area and paste it into the OnBarUpdate area?
Also refer to this thread:
Hi I know there are a few posts around using ATR based targets & stops, none of them seem to cover the issue I'm having though sorry. When I use the below code, the targets look to be getting set to the entry price & the trade is opening & closing immediately, clearly I'm doing something wrong but not sure what
How do I do the ticksize conversion in the code to allow my ATR entry, stop and target to work?
Comment
-
OK, so now I got the entry and stoploss working. I moved the SetStoploss and the SetProfitTargets from the OnStateChange area and paste it into the OnBarUpdate area and I also had to put the command /TickSize into the Enter, Profit and Stop signals.
I do however see that my entry is not offset, as required. I want to offset my entry at ATR*0,25 from the low of the bar (shorts) and the high of the bar (longs)
What should I change to make this condition true?1 Photo
Comment
-
Hello Induna,
When using Set methods in OnBarUpdate, please ensure that you are resetting the Stop Loss and Profit Target to initial levels when the strategy is flat and before the next entry is made. The example I linked can provide demonstration.
Market If Touched orders behave similarly to Limit orders, where if the market price is better than the order's price, the order will fill at the current market price. Debugging prints can be used to print out the value that you are calculating to submit the order to. For example, before your order submission, you can print out CurrentBar and the value calculated from (Lows[1][0] - ((ATR1[0] - EntryFactor/TickSize))) to confirm the price level submitted with the order method.
Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm
If you want to enter at the current market price once it touches a specific level without following the same rules as a MArket If Touched or Limit order, you can check if the current market price equals that level, and then to submit a market order with EnterLong or EnterShort.
Please let me know if I can be of further assistance.JimNinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Jim View PostHello Induna,
When using Set methods in OnBarUpdate, please ensure that you are resetting the Stop Loss and Profit Target to initial levels when the strategy is flat and before the next entry is made. The example I linked can provide demonstration.
Market If Touched orders behave similarly to Limit orders, where if the market price is better than the order's price, the order will fill at the current market price. Debugging prints can be used to print out the value that you are calculating to submit the order to. For example, before your order submission, you can print out CurrentBar and the value calculated from (Lows[1][0] - ((ATR1[0] - EntryFactor/TickSize))) to confirm the price level submitted with the order method.
Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm
If you want to enter at the current market price once it touches a specific level without following the same rules as a MArket If Touched or Limit order, you can check if the current market price equals that level, and then to submit a market order with EnterLong or EnterShort.
Please let me know if I can be of further assistance.
How do I reset the Stop Loss and Target levels to intial when the strategy is flat? Can you provide me the command please?
Comment
-
Hello Induna,
You would check if the strategy is in a flat position, and then to call the Set method before the next entry. Please see the example linked in post 71. Lines 69-72 show where the strategy checks if the position is flat and then the stop loss is set back to its initial level. (Set methods prep NinjaTrader to submit the Target/Stop upon the execution of the entry order.)
We look forward to assisting.JimNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by PhillT, 04-19-2024, 02:16 PM
|
4 responses
30 views
0 likes
|
Last Post
by PhillT
Today, 04:24 PM
|
||
Started by ageeholdings, 05-01-2024, 05:22 AM
|
5 responses
36 views
0 likes
|
Last Post
by ageeholdings
Today, 03:21 PM
|
||
Started by reynoldsn, Today, 02:34 PM
|
0 responses
7 views
0 likes
|
Last Post
by reynoldsn
Today, 02:34 PM
|
||
Started by nightstalker, Today, 02:05 PM
|
0 responses
12 views
0 likes
|
Last Post
by nightstalker
Today, 02:05 PM
|
||
Started by llanqui, Yesterday, 09:59 AM
|
8 responses
29 views
0 likes
|
Last Post
by llanqui
Today, 01:57 PM
|
Comment