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

Manual Trade Entry with Auto Strategy for Profit and Stop

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

    Manual Trade Entry with Auto Strategy for Profit and Stop

    I would like to be able to place a manual trade and have a strategy running in the background that automatically places a stop and a profit target when I am either long or shot. Per previous threads, I understand it can be done, but I'm having trouble with the script.

    Currently I just have the stops set up

    For the Longs I have this
    Code:
    			if (Position.MarketPosition == MarketPosition.Long)
    			{
    				longStopPrice = Low[0]  - 4 * TickSize;
    				SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket,1,0,longStopPrice);
    			}
    For Shorts I have this:
    Code:
    			if (Position.MarketPosition == MarketPosition.Short)
    			{
    				shortStopPrice = High[0] + 4 * TickSize;
    				SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.StopMarket,1,0,shortStopPrice);
    			}

    The longStopPrice and shortStopPrice are defined in public class
    public class TestManual : Strategy
    {
    private int longOrderBar = 0;
    private int shortOrderBar = 0;

    When I test the strategy I enable the strategy in the strategy tab, and then take a position and the strategy immediately goes from True to False on the Sync.

    Attached is a shot of my settings, which I believe should be correct for the unmanaged approach. For Stop & Target submission, I have tried both "By Strategy position" and "Per Entry Execution" and neither have worked.

    Any ideas what may be causing this to not place my stop?
    Attached Files
    -EC_Chris-
    NinjaTrader Ecosystem Vendor - Emergent Cybernetics

    #2
    Hello EC_Chris,

    NinjaScript Strategies are not able to see trades that are placed manually or from another instance of a strategy.

    These have their own internal position and are only able to see orders placed through the strategy.

    I recommend you have the strategy add a button and when the button is pressed, submit the entry order from from the strategy itself.

    Below is a publicly available link to an example.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea, but this isn't really what I need or am referring to.

      This thread is what I am referring to.


      Here they discuss manually entered trades and the ability to have a script running which automatically places a stop/target if the position is long or short. This is what I am trying to do.
      -EC_Chris-
      NinjaTrader Ecosystem Vendor - Emergent Cybernetics

      Comment


        #4
        Actually Chelsea, I got it to work by changing
        if (Position.MarketPosition == MarketPosition.Long)
        to
        if (PositionAccount.MarketPosition == MarketPosition.Long)

        I also had to switch the strategy to "On each Tick"

        However, now with each tick, the NT audio alert says "Order Pending" because it trying to move the stop.

        Is there any way to disable the audio "order pending" in that script itself just for that stop?
        -EC_Chris-
        NinjaTrader Ecosystem Vendor - Emergent Cybernetics

        Comment


          #5
          Hello EC_Chris,

          In this thread you will see that the user experienced unexpected pairing and performance.

          The strategy is not able to see the manually place trades.

          Instead, when the account position changed, their script placed an order. To the strategy, it sees that order as an entry order and not an exit order. The strategy will never see the entry order, but is possible to peak at the account position.

          It is expected that if you started the strategy with the strategy position in sync with account position and then you place a trade to the account and change the account position that the strategy would no longer be in sync. Placing a manual order to an account does not cause the strategy position to change. Only the account position will change.

          That said, if this is what you want to do, this would be up to you.


          The suggestions from Dave where back when NinjaTrader 8 was still in Beta and we didn't have as much information about how scripts should work.


          From what you are trying to achieve I still recommend adding a button to your script and having the script place the entry order so that the position of both the strategy and the account change, or using the Addon approach to detect changes to the account and drop using a ninjascript strategy at all.

          Last, here is a link that details strategy position vs account position.


          And publicly available links to the help guide on the Addon approach.



          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thanks again Chelsea, great details. Please check out my last post, I was able to get it to work. But wanted to see if anything could be done about the "order pending" audio alert specifically in the script. Thanks!
            -EC_Chris-
            NinjaTrader Ecosystem Vendor - Emergent Cybernetics

            Comment


              #7
              Hello EC_Chris,

              You can disable sounds in Tools -> Options -> General.

              Click the x next to Order pending to disable the sound.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hi Chelsea,

                I added the button script as you mentioned. While this logic works well for what I need, the biggest issue I noticed was the time it takes for the order to fill. Even with OnEachTick selected for the strategy, it could take up to 10 seconds or longer for an order to fill if there are no ticks.

                The only way for the button to work is if it fills immediately after it is pressed. Is there any way to force the trade once that button is pressed and not have to wait for a new tick?

                Thanks
                -EC_Chris-
                NinjaTrader Ecosystem Vendor - Emergent Cybernetics

                Comment


                  #9
                  Hello EC_Chris,

                  Thank you for your response.

                  There is no means to force an order to fill in any context when trading live. You can force immediate fills in the simulator by going to the NinjaTrader Control Center > Tools > Options > Trading > Simulator > enable the 'Enforce immediate fills' option > OK.

                  Please let me know if you have any questions.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by algospoke, Yesterday, 06:40 PM
                  2 responses
                  21 views
                  0 likes
                  Last Post algospoke  
                  Started by ghoul, Today, 06:02 PM
                  3 responses
                  14 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  3 responses
                  45 views
                  0 likes
                  Last Post jeronymite  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  7 responses
                  21 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by AttiM, 02-14-2024, 05:20 PM
                  10 responses
                  181 views
                  0 likes
                  Last Post jeronymite  
                  Working...
                  X