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

Flatten by account and instrument not happening.

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

    Flatten by account and instrument not happening.

    Hi,

    I am trying to flatten account by instrument during loss but thats not happening.

    Click image for larger version  Name:	image.png Views:	0 Size:	17.8 KB ID:	1286670

    But in the simulation log,

    Click image for larger version  Name:	image.png Views:	0 Size:	32.4 KB ID:	1286671
    If you see the above log,

    There is a entry @ 1.38 PM on Jan 8th which supposed to close when loss hit, but it got closed with loss of $19k - but the flattening logic triggering on 10th Jan only.

    Even it triggers flatten, its throwing the error - Connection
    Last edited by kaviyas; 01-16-2024, 09:02 AM.

    #2
    Hello kaviyas,

    The accounts Flatten method is not intended for a strategy to use, strategies are only able to manage the positions that they create. The Flatten method is part of the addon framework which is separate from strategies.

    If you are trying to close the position that your strategy started you can use exit orders or also CloseStrategy which also terminates the strategy.



    JesseNinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_Jesse Thanks for the reply, actually the intention is to close the position which got opened, which is not happening that why i was trying to use FLATTEN.

      If you see the logs which i shared earlier, there was order on 8th Jan 1.38 PM which was supposed to trigger stop limit but thats not happening.

      And that particular short trade was closed on the End of the Day reason. If stop loss triggered properly even close position is also not required in my case.

      Can you please help to identify why the stoploss is not triggering

      Comment


        #4
        Hello kaviyas,

        From the images I wouldn't be able to tell what may have happened with the stop limit, the only thing I can see from that output is that some order was expired which is a normal process when using the managed approach. If you are submitting stop limit orders on your own after an entry those orders are only valid for 1 bar unless you keep them active by calling the order method for each bar where they were not filled. If you do not do that then they will be expired at the bar close.

        If you have more specific details on what you tried in your logic surrounding the targets that may help to see what is happening. You would otherwise need to adjust your logic if those orders are being expired.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Actually the order which i placed is filled already - and i am not calling the order method for each bar. For Managed orders, can you please let me know how can i find the current opened position in my strategy and close

          Comment


            #6
            Hello kaviyas,

            To close a strategies position you need to use either exit market orders or targets. The general flow of a entry/exit strategy is that you submit an entry and once that has filled you could submit targets that are active until one fills or you use conditions to submit an exit market order when you feel that you wanted to close the position.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Can you please share the syntax for the strategy position exit market order or target scenario ?

              Comment


                #8
                Hello kaviyas,

                You can find samples of each of the order methods in the following link:



                A market order would be the ExitLong or ExitShort method.




                If you are just getting started with NinjaScript I would suggest using the strategy builder as a starting point. You can view the code that it makes by clicking ViewCode which will help with learning the manually coded side of NinjaScript. In the strategy builder you can use the stops and targets page if you wanted to make a strategy that uses targets or you can use the Sets to make conditions to exit and then as an action submit a market exit.

                JesseNinjaTrader Customer Service

                Comment


                  #9
                  NinjaTrader_Jesse Thanks for sharing this details.

                  If you see the 1/8 1.39 PM and 1.44 PM entries, the exists are Session end not stop loss.

                  Click image for larger version

Name:	image.png
Views:	60
Size:	5.2 KB
ID:	1286702
                  My stop loss configured in this way, only $2 price change or 8 ticks, but still the stop loss not triggered. I m using all managed entry and exists only.


                  Click image for larger version

Name:	image.png
Views:	60
Size:	80.3 KB
ID:	1286701

                  Comment


                    #10
                    Hello kaviyas,

                    From that image all I can tell is that your profit target is frequently being hit and that some of your entries were placed at a time where the stop or target did not fill so the exit on session close was run. That doesn't tell us the stop isn't being submitted.

                    As a first step try removing the profit target, that will mean that only exit on session close or the stop could be hit, that will let you know if the profit target is just close to market and is being filled first.

                    In the code you provided you are using the from entry signal "sell" with the stop, if you don't have an entry named sell that target wont be submitted. That needs to match the entry name you wanted the stop to apply to.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks a lot after setting the stoploss after the entry and exist worked.

                      Click image for larger version

Name:	image.png
Views:	60
Size:	19.7 KB
ID:	1286710

                      Also the first 2 params in the Entry Method for both short and log
                      1. barInProgressIndex should be 0 for the current data series.
                      2. IsLiveUntilCancel should be false so it wont say for fill.

                      Comment


                        #12
                        Hello kaviyas,

                        From the image you need to reverse the order of the two methods so that a new price is used for the stop. Placing it after the entry will mean that the previous entries average entry price is used for the stop. It should be:

                        SetStopLoss()
                        EnterShortLimit()

                        The reason that works now is because you used the name "vwapshort" instead of "sell" which you had in your other image.

                        The parameters in the limit order mean that 0 for the bars in progress the order will be submitted to the primary series the strategy uses. If you want the order to be filled on the 1 minute series you added you would need to use 1 instead of 0.

                        IsLiveUntilCancelled is used to keep an order active without having to call the method again. Using false means you have to keep calling EnterShortLimit for each bar where it is not filled otherwise it will be expired. I see some expired messages in the log you provided earlier which would relate to using false for that order. If you use true that means the order is kept alive until filled or if you cancel the order yourself.



                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          Got it thanks a lot !!!

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by fx.practic, 10-15-2013, 12:53 AM
                          5 responses
                          5,403 views
                          0 likes
                          Last Post Bidder
                          by Bidder
                           
                          Started by Shai Samuel, 07-02-2022, 02:46 PM
                          4 responses
                          94 views
                          0 likes
                          Last Post Bidder
                          by Bidder
                           
                          Started by DJ888, Yesterday, 10:57 PM
                          0 responses
                          6 views
                          0 likes
                          Last Post DJ888
                          by DJ888
                           
                          Started by MacDad, 02-25-2024, 11:48 PM
                          7 responses
                          158 views
                          0 likes
                          Last Post loganjarosz123  
                          Started by Belfortbucks, Yesterday, 09:29 PM
                          0 responses
                          8 views
                          0 likes
                          Last Post Belfortbucks  
                          Working...
                          X