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

Unmanaged Orders

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

    Unmanaged Orders

    I would like to be able to adjust the Profit Target and Stop Loss similar to entering an ATM order from the chart trader where you can drag the profit and stop on the chart.

    Is using an Unmanaged order the only way to accomplish this?

    #2
    Hello sdauteuil,

    Thank you for your post.

    Setting a Profit Target and Stop Loss that is able to be manually adjusted on the chart could be accomplished using the Managed Approach with Exit Methods. Please see the attached example script, ExitMethodsSample, which demonstrates how you could use Exit methods to place an adjustable Profit Target and Stop Loss. We use a bool in our script to ensure that orders are submitted once and not for each time OnBarUpdate is processed. This allows us to manually adjust the Profit Target and Stop Loss.

    In the example script, we check if we are in a flat position by using Position.MarketPosition == MarketPosition.Flat. If we are in a flat position then the script calls EnterLong to place an entry order and we set a bool variable to true. Then, the script checks if we are in a long position and if the bool == true followed by using ExitLongStopMarket and ExitLongLimit to place a Profit Target and Stop Loss and we also flip our bool back to false.

    Please see the help guide documentation below for more information.
    ExitLongLimit - https://ninjatrader.com/support/help...tlonglimit.htm
    ExitLongStopMarket - https://ninjatrader.com/support/help...stopmarket.htm
    Position.MarketPosition - https://ninjatrader.com/support/help...etposition.htm

    Let us know if we may assist further.
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      That seems simple enough.

      what is the purpose of State == State.Historical in this instance?

      should I include this in my code and If so would the code below be the correct order?



      protected override void OnBarUpdate()

      if (State == State.Historical)
      return;


      if ((CurrentBars[0] < 20)
      || (CurrentBars[1] < 20)
      || (CurrentBars[2] < 20))
      return;

      if (BarsInProgress != 0)
      return;

      // rest of code

      Thanks for the help

      Comment


        #4
        Hello sdauteuil,

        Thank you for your note.

        State == State.Historical checks to see if the strategy is processing historical data. If it is and we call return, the strategy will skip historical data processing.

        Yes, that is the correct order for using if (State == State.Historical) return;.

        Please let us know if we may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by WHICKED, Today, 12:45 PM
        2 responses
        18 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Started by GussJ, 03-04-2020, 03:11 PM
        15 responses
        3,276 views
        0 likes
        Last Post xiinteractive  
        Started by Tim-c, Today, 02:10 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Taddypole, Today, 02:47 PM
        0 responses
        5 views
        0 likes
        Last Post Taddypole  
        Started by chbruno, 04-24-2024, 04:10 PM
        4 responses
        51 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Working...
        X