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!
See more
See less

Partner 728x90

Collapse

Strategy Builder: Add ATR-value as TakeProfit and StopLoss

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #61
    Originally posted by Trader17 View Post
    I think you need to set that value to ticks and then use it in the stop and target.
    I am working with Forex. When I set it to ticks I get exactly the same result. When I set it to price then the orders are not even placed, although the arrow plots (indicating that the conditions were met for an order)

    Comment


      #62
      See the value the indicator returns at the bottom of the chart. In forex you need to be careful with the decimals. Do you have the code where you convert the ATR value?

      Comment


        #63
        This is a 5 minute ES chart. The ATR value is in points if you see and not ticks. You need to convert it to use in a strategy.
        Attached Files

        Comment


          #64
          Originally posted by Trader17 View Post
          This is a 5 minute ES chart. The ATR value is in points if you see and not ticks. You need to convert it to use in a strategy.
          Thanks. on the GBPUSD pair on my chart it looks to be in pips?

          Comment


            #65
            Sorry, I mean my chart displays price. It relates to 10.4 pips?

            Comment


              #66
              Where is the code?

              Comment


                #67
                i built this is the wizard. I followed the steps as per the video on page 1.

                Comment


                  #68
                  That is the problem. I was told by support it cannot be done in the Wizard. You need to unlock the code first and then modify the script.

                  Comment


                    #69
                    I tried within the code to calculate ATR/TickSize, but still have the same results.

                    My charts definitely shows price for the ATR and not pips or ticks.

                    Comment


                      #70
                      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


                        #71
                        Originally posted by NinjaTrader_Jim View Post
                        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.
                        Thanks,

                        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


                          #72
                          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?

                          Comment


                            #73
                            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


                              #74
                              Originally posted by NinjaTrader_Jim View Post
                              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.
                              Thanks.

                              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


                                #75
                                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 PhillT
                                by PhillT
                                 
                                Started by ageeholdings, 05-01-2024, 05:22 AM
                                5 responses
                                36 views
                                0 likes
                                Last Post ageeholdings  
                                Started by reynoldsn, Today, 02:34 PM
                                0 responses
                                7 views
                                0 likes
                                Last Post reynoldsn  
                                Started by nightstalker, Today, 02:05 PM
                                0 responses
                                12 views
                                0 likes
                                Last Post nightstalker  
                                Started by llanqui, Yesterday, 09:59 AM
                                8 responses
                                29 views
                                0 likes
                                Last Post llanqui
                                by llanqui
                                 
                                Working...
                                X