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

NT8 storing the value of a variable, and changing the value of a variable or input

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

    #16
    Hello Robinson94,

    When using Atm Strategy methods, your stop loss and profit target distance will initially be set by the template. If you want to set this to a far distance then you can set this to a far distance in the Atm Strategy Template.



    If you want to modify a stop loss or profit target, then you have to use the name of that stop loss or profit target as they appear in the Orders tab of the Control Center.

    AtmStrategyChangeStopTarget(0, SMA(10)[0], "STOP2", "AtmIdValue");



    If you want to use a number of ticks, multiply a number by the TickSize.

    For example to get a distance of 5 ticks from the close price:
    Print(Close[0] + 5 * TickSize);
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Thanks for the clarification, but when i create the order like this :
      Code:
      			AtmStrategyCreate(OrderAction.Sell, OrderType.StopMarket, -1, -1, TimeInForce.Day, "Entry", "autotrailstop", atmtrailstop, (atmCallbackErrorCode, atmCallbackId) => {
      Its creating a new atm strategy, so i have two time the same atm strategy running a - 1 and a - 2, but since the order created by the piece of code, is also making a new strategy, this order is seen by the strategy as an entry order, and not a stop order.

      So, is there a way, to create the order in a running atm strategy, so the order can be seen as a stop and not a entry.
      I want to do this, because i think, that since the order is an entry, but i'm trying to use changeStopTarget, the name of the order cannot be recognize, and so i get the error AtmStrategyChangeStopTarget method error : Order name 'Stop1" is invalid
      And i get the same error, if i'm putting the name of the order as "Entry", or "ENTRY", even if in the control center, the name of the order is Entry.

      I'm not sure if its clear, so let's resume, the name of the order that is created by the strategy, is "Entry", in a new strategy, and not the running one, because of this, when the order is filled, since its an entry, its creating a new stop loss. And the order name, cannot be find, with the names : "Entry" "ENTRY" Entry1", "Stop" "STOP1" Stoploss", and a lot of others.
      So i want to create the order, in the running atm strategy that was launched manually, so the order created is not an entry, but a true stop.
      Is it possible ?

      Thanks !

      Comment


        #18
        Hello Robinson94,

        Thank you for your response.

        To be clear you are manually submitting the ATM Strategy through the SuperDOM and wish to have your NinjaScript strategy detect the position that the ATM Strategy is using for it's orders. You then wish to submit orders in the NinjaScript strategy to close the position under certain circumstances thus cancelling the ATM Strategy orders. Is this correct?

        I look forward to your response.

        Comment


          #19
          Hello !

          This is almost correct,
          i do enter a trade, with an atm strategy manually, and then, trough the ninjascript, i'm trying to create a trailing stop, to exit my trade, but not to close the trade.

          And if i create the trailing stop order in a new atm strategy, the order is seen as an entry, and when filled will create a stop loss, i'm trying to create the order in the running atm strategy opened manually, so the order is not seen as an entry, but as a second stop loss (i have already a stop loss manual in place, but the second stop loss, is used as a trailing stop loss).

          Then i'm trying to get the name of the stop order used as a trail stop, so i can use the name of the order, trough the AtmStrategyChangeStopTarget method, to then, move the stop order like a trail stop order, and then when i'm filled, the account become flat, and the atm strategy get disable.
          Code:
          				AtmStrategyChangeStopTarget(0, LONGautotrailstop1[0], "Stop2", atmtrailstop);
          So here's the questions :
          How can i create an order in a running manually started ATM strategy ?

          Then how can i get and/or set the name of a stop order (since i have tried and the script can't recognize the name of the order), to use the name trough AtmStrategyChangeStopTarget method.

          Thanks !!

          Comment


            #20
            Hello Robinson94,

            Thank you for your response.

            How can i create an order in a running manually started ATM strategy ?
            You cannot insert another order into the ATM strategy. You can place another order but there is no association to the ATM strategy for that order.

            Can you detail what your full intent is here without using NinjaScript or ATM Strategies terms to describe the behavior? For example: I want to have an open position with protective orders and then submit another protective order and manage it through the automation.

            I look forward to your response.

            Comment


              #21
              Ok, thanks, so here's what i'm looking to do :

              I enter a trade manually, and a protective stop loss is set manually (right now i'm creating the stop with an atm strategy, then i move it to the right amount).
              Then at a certain point, when my dynamic target created by the strategy is hit, i'm looking to create a stop sell market (or buy) order, and then, this order, that is used as a trailing stop order, will be moved on the value of an indicator by the script, and if this stop sell market order is filled, the account become flat, and the protective stop loss is canceled.

              Right now, i'm just entering manually with an atm strategy, and the protective stop is also made by the atm strategy, then the trailing stop order is made like this :
              Code:
              AtmStrategyCreate(OrderAction.Sell, OrderType.StopMarket, -1, -1, TimeInForce.Day, "Entry", "autotrailstop", atmtrailstop, (atmCallbackErrorCode, atmCallbackId) => {
              But, even if its called Entry, i dont want it to be an entry, because if its an entry, when the order is filled, it will yes flatten the account, but create a new stop loss, and not canceled the protective stop.
              So, i'm looking to have a trailing stop, that will delete the protective stop when filled, that will not create any stop loss, and that have a name, that can be used, to move the order with this piece of code, or something similar :
              Code:
              AtmStrategyChangeStopTarget(0, LONGautotrailstop1[0], "Entry", atmtrailstop);
              Thanks !

              Comment


                #22
                Hello Robinson94,

                Thank you for your response.

                The order you are trying to submit as an exit with AtmStrategyCreate will need to be submitted with a different method. You would use the Unmanaged Order Approach and submit the order through SubmitOrderUnmanaged. Please review the details at the following link on Unmanaged Order Approach: http://ninjatrader.com/support/helpG...d_approach.htm

                Please let me know if you have any questions.

                Comment


                  #23
                  Thanks a lot !
                  The unmanaged order are in did way more flexible, and, i'm facing a little problems with the Market.Position and the strategy, if its enabled after the entry of the manual trade.
                  So, i use a lot the
                  Code:
                  if ((PositionAccount.MarketPosition == MarketPosition.Long)
                  , and the short, everything work well with it, if the strategy is enabled before the entry.
                  But, since my entry is done manually, and my strategy know if i'm in a trade or not with the MarketPosition, its all good when the strategy is launched before the opening of the trade. But when i launch the strategy after the opening of the trade, the strategy will glitch out, and will right away, launch all the conditions set as soon as its enabled, which is not the case if the strategy is launched before the open of the trade.
                  My start behavior is adopt account position, its not fixing the problem, and i was using immediately submit before.
                  So, i would simply really appreciate some help, on fixing the script, and finding why, when a position is open before the strategy is launched, its glitching out, since i could not figure out the problem.

                  Here's an example of a condition set, but all the condition in onbarupdate have this problem (probably the others conditions too, but i'm not sure, i will look about this), but i'm only using condition with MarketPosition in the conditions set anyway :
                  Code:
                  			if ((PositionAccount.MarketPosition == MarketPosition.Long)
                  				&& (stopLossOrder == null)
                  				&& (State == State.Realtime)
                  				&& (creationstoploss == false))
                  Also, here's the full code, the important part of the code, is the code with MarketPosition.Long, the MarketPosition.Short part, is a copy of the long, but its not up to date, so no reason to fix the short, but if we can find why the long don't work, the short will be fixed. Thanks a lot for the help, it means a lot !!
                  PS : the code is not finished yet, so there is a bit of junk, and not completed things, don't mind
                  Attached Files

                  Comment


                    #24
                    Hello again !
                    I just want to add, that i have a little problem, related to the problem of the strategy that ignore the MarketPosition if started after the open of the trade.
                    Its this piece of code :
                    Code:
                    			if (PositionAccount.MarketPosition == MarketPosition.Long)
                    				{
                    				tradepris = true;
                    				}
                    
                    			if ((PositionAccount.MarketPosition == MarketPosition.Flat)
                    				&& (tradepris == true))
                    				{
                    				Account.Flatten( new [] { Instrument.GetInstrument (Instrument.FullName) });
                    				}
                    The idea, is if i opened a trade, so i'm at a certain point, either MarketPosition.Long or Short, the bool tradepris will set to true to tell, that we have taken a trade.
                    And i'm flat but the tradepris is true, i'm flat and i have taken a trade, so i have closed a trade. If i closed a trade, i want to flatten the account to be sure that there is no order left, and nothing left, then the strategy can terminated.

                    But, even when the strategy is started before the opening of the trade, with this piece of code, as soon as i opened a trade, and that the state become MarketPosition.Long, the entire code above will get triggered, and it will not wait until i'm flat to flatten the account. So its pretty similar to the the problem explained in the previous post, where the entire script with MarketPosition in the condition set, will triggered if the strategy is started after the opening of the trade, even if its not supposed to happen.

                    PS : the code is on OnBarUpdate, calculated on each tick, and the strategy is set to a chart, and a data series, and with a print,
                    Code:
                    					Print(Instrument.FullName);
                    , i know that the data series is detected, and the good one.

                    Thanks !!

                    Comment


                      #25
                      Hello Robinson94,

                      Thank you for your response.

                      I wish to narrow down the use case here to help in understanding what is happening and what is needed in the code.

                      Please provide a step by step detail on the intended behavior and the behavior that is seen.

                      For example:
                      • I start the strategy when my position is flat and the following occurs...
                      • I start the strategy when my position is not flat and the following occurs...


                      I will look to simplify your code into smaller chunks in order to break down the intended behavior and what is occurring. So I would ask that we begin with the first step here which is what should happen when you are flat and what should happen when you are not flat.

                      Comment


                        #26
                        Ok, thanks !

                        So, i will explain 2 states, the state that work, and the state that i want to use in trading and that don't work :

                        - The state that work :
                        If i launch, and enable the strategy, before i opened a trade, so when i'm flat, the strategy work as intended, and all condition set wait to be totally trigerred before they start to launch the code they are in charge (the code that is below a "if", and that need the "if" to be good to be launched). So, i enable the strategy, then i can enter manually with an atm strategy, or with none, trough the super dom, and with the "MarketPosition" in the code, i can get the status of the trade, and i can know if i'm flat or not, so if the strategy should run. In this case, everything work.

                        - The state that don't work :
                        If i launch, and enable the strategy, after i opened a trade, so when i'm not flat. So, like the first case, but this time, i open the trade with an atm strategy, then i enable the automated strategy. In this case, as soon as the strategy is enable (or on the first tick since i'm calculating in each.tick), all the condition set, that use the "PositionAccount.MarketPosition == MarketPosition.Long(orShort)" will have a problem, and they will all get launched at the same time. The condition are not just the MarketPosition, but all the condition set (they have multiples conditions to trigger), that use the MarketPosition, will not wait until the others conditions are good (even if the MarketPosition is not the first condition is the set, but is after a &&), since everything is activated at the same time, my strategy will launched the stop loss set, the trail stop set, the flatten in case of a news set, and all the others conditions, in the exact same time.

                        Here's the problems, its the same thing with live data, replay data, or simulated data.
                        Thanks for your future answers, since i'm really confused, and some help would be amazing !
                        PS : there is more details in the last 2 posts if i have not been clear enough in this one.

                        Have a great day !

                        Comment


                          #27
                          Hello Robinson94,

                          Thank you for your patience.

                          What Start Behavior are you using for the strategy in both cases?
                          Information on Start Behavior can be found at the following link: http://ninjatrader.com/support/helpG..._positions.htm

                          Please let me know if you have any questions.

                          Comment


                            #28
                            Hello !

                            I'm using the adopt account position, even if i was using immediately submit before, and i also try, the wait until flat. None of those start behavior make a difference (unless the wait until flat, since its not going to launch, since its the logic of this mode), but the adopt account, immediately submit, wait until flat, or wait until flat synchronize don't do any differences in the case where it don't work.
                            And where it work i use the adopt account position, the immediately submit was working too, and i think the others mode too, i can check if its important.

                            Thanks !

                            Comment


                              #29
                              Hello Robinson94,

                              Thank you for your patience.

                              So I may test the strategy please export it with the indicators (LONGautotrailstop & SHORTautotrailstop) using the following process and attach it to your repsonse.

                              You can export your strategy by going to Tools > Export > NinjaScript Add On > Add > select your strategy > OK > Export > name the file 'NTsupport' > Save.

                              The file will be located under Documents\NinjaTrader 8\bin\Custom\ExportNinjaScript. Please attach the file to your response.

                              Comment


                                #30
                                Here you go, the indicators are simply creating a dot for every down bar for the Short indicator, and every up bar for the Long indicator. Its used as a trail stop to exit a trade after the hit of the target.

                                And the target is set to the value of the one fib level of the default template for fib extension (i didn't find how to create fibs with specifics templates, you may know how ?), so you would need to put the value of the 3 variable of the script, like if you drawn a fib extension, but only with the price, and the target will be set to the value of the fib of the default template. But you need to have only one fib on the default template for the fib extension, or it will probably have some problems with trying to put multiples value in one double.

                                So, if with the strategy you take a short trade, its the Short indicator that will be used and that you can put on your chart manually if needed, and for Long, its the Long indicator.

                                Thanks a lot for testing the script
                                (By the way, if you need a export of the full strategy, and not just the code, its not a problem)
                                Attached Files

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by sidlercom80, 10-28-2023, 08:49 AM
                                168 responses
                                2,262 views
                                0 likes
                                Last Post sidlercom80  
                                Started by Barry Milan, Yesterday, 10:35 PM
                                3 responses
                                10 views
                                0 likes
                                Last Post NinjaTrader_Manfred  
                                Started by WeyldFalcon, 12-10-2020, 06:48 PM
                                14 responses
                                1,429 views
                                0 likes
                                Last Post Handclap0241  
                                Started by DJ888, 04-16-2024, 06:09 PM
                                2 responses
                                9 views
                                0 likes
                                Last Post DJ888
                                by DJ888
                                 
                                Started by jeronymite, 04-12-2024, 04:26 PM
                                3 responses
                                41 views
                                0 likes
                                Last Post jeronymite  
                                Working...
                                X