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

Order taggin problem.

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

    Order taggin problem.

    hi, i am currently using this code for entering my trades.

    private void GoLong(){
    SetStopLoss("target1",CalculationMode.Price,Close[0] - (stop/10000d), false);
    SetProfitTarget("target1",CalculationMode.Price,Cl ose[0] + ((target/10000d)-0.00001));
    EnterLongLimit(Close[0], "target1");
    }
    private void GoShort(){
    SetStopLoss("target1",CalculationMode.Price,Close[0] + (stop/10000d), false);
    SetProfitTarget("target1",CalculationMode.Price,Cl ose[0] - ((target/10000d)-0.00001));
    EnterShortLimit(Close[0], "target1");
    }

    private void ManagedOrders(){
    if(Position.MarketPosition == MarketPosition.Long)
    {
    if (...)
    SetStopLoss("target1",CalculationMode.Price, Close[10],false);
    }
    if(Position.MarketPosition == MarketPosition.Short)
    {
    if (...)
    SetStopLoss("target1",CalculationMode.Price, Close[10],false);
    }
    }
    2 questions:

    Firstly: I am currently using stop/10000d so my stop parameter as a real number gets calculated down to eurusd pips. but ofc this doesnt work for jpy pairs, thats why i have to change it when im testing those. is there a workaround for it, so it always knows the correct pip amount

    Secondly(and more importantly) regarding multiple positions: with this setup i am ofc not able to generate unique entries, i either have to wait for 1 trade to finish, or it will scale up my target and stoploss everytime im gettin a new entrysignal for all existing positions.

    an easy workaround would be to just use "target1"+currentbar for target and stoploss as well as for the entry. since they are all calucalted on the same bar, the tag would fit.

    the problem that arises is now that my order management is ofc not calculated on that same bar, so im assuming that "target1"+currentbar wouldnt do anything here, bc the tag would be wrong, and therefore the stop would never be trimmed for the right position.

    any idea how to work around that? how to do it so that managed oders() will know for what position to adjust the stop and will do it only for that then.

    thanks

    #2
    just as a sidenote, it would be enough if i could just set all stoplosses of all open positions to the price i want.
    but when im using this instead for managed orders

    private void ManagedOrders(){
    if(Position.MarketPosition == MarketPosition.Long)
    {
    if (...)
    SetStopLoss(CalculationMode.Price, Close[10]);
    }
    if(Position.MarketPosition == MarketPosition.Short)
    {
    if (...)
    SetStopLoss(CalculationMode.Price, Close[10]);
    }
    }
    and the "target"+currentbar tag for everything else, it seems ninjatrader still doesnt change any stoplosses.

    Comment


      #3
      Hello,

      Thank you for the questions.

      I wanted to first get some clarification on your questions.

      For the first question, are you asking how to determine if you are using a JPY instrument in order to change the calculation you need for pips?

      For the second question, I am not completely sure but this sounds like you are asking how to differentiate orders so that you can use multiple entries per direction.

      Can you tell me if this is correct thinking on these items? If not can you provide a clear example of the questions?

      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #4
        1)yes
        2)yes but with the focus on the problem with managing trades (i.e. trimming the stoploss) rather than just how to differentiate orders

        to rephrase it

        if im using something like this to go long -
        Code:
        private void GoLong(){
                    SetStopLoss("target"+CurrentBar,CalculationMode.Price,Close[0] - (stop/10000d), false);
                    SetProfitTarget("target"+CurrentBar,CalculationMode.Price,Cl  ose[0] + ((target/10000d)-0.00001));
                    EnterLongLimit(Close[0], "target"+CurrentBar);
                }
        - i would be able to use as many multiple entries as i like (which is what im looking for)

        i now also wanna use a condition to set my stoploss to breakeven and trim it further, with
        Code:
        if(Position.MarketPosition == MarketPosition.Short)
                    {
                        if (...)
                            SetStopLoss();
        but when im doin this im struggleing with the tagging. i cant use "target"+Currentbar, because the currentbar is diffrent than at entry, further even something like this

        Code:
        SetStopLoss(CalculationMode.Price, Close[10]);
        doesnt seem to work, because the stoploss is still not connected to the other or any stoploss that is currently set with "target"+CurrentBar

        Comment


          #5
          in a nutshell 2) would be how can i use unique entries including unique targets and stoplosses and then move all unique stoplosses to a certain point.

          Comment


            #6
            Hello,

            Thank you for the reply.

            To determine the instrument being used, you could use:

            Code:
            Instrument.FullName
            This would be the full name of the current instrument and you could create a condition based on this stings value.

            Regarding the orders, In general the suggested way to use multiple entries is simply giving the Entries a unique name and associating that name with the FromSignal on your Set methods.

            For example, if you wanted 2 unique entries with 2 unique stops, the following would be one way of doing that, keep in mind in the properties when you configure the strategy you would need to choose 2 entries per direction and UniqueEntries for the Entry Handling :

            Code:
            if(Position.MarketPosition == MarketPosition.Flat)
            {
            	//set initial values for the stops for the entry
            	SetStopLoss("Long1", CalculationMode.Ticks, Close[0] - 10 * TickSize, false);
            	SetStopLoss("Long2", CalculationMode.Ticks, Close[0] - 10 * TickSize, false);
            	EnterLong("Long1");	
            	EnterLong("Long2");
            }
            			
            if(Position.MarketPosition != MarketPosition.Flat )
            {
            	//adjust the existing stop values by calling the FromSignal name
            	SetStopLoss("Long1", CalculationMode.Ticks, Close[0] - 1 * TickSize, false);
            	SetStopLoss("Long2", CalculationMode.Ticks, Close[0] - 3 * TickSize, false);
            }

            You could name the entries anything you want so long as they are unique and used as the FromSignal to link the stop with its specific entry. if you will have a unknown number of orders, you may have to create custom logic to name the orders as you need.

            Please let me know if I may be of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              i think this is not goin to work.
              i dont have unique entries based on diffrent entry conditions, which looks like, this setup is fitting for.

              what i am tryin to achieve is, that the strategy enters a new position on every single following candle where the entrycondition is still true.
              what currently is happing is that i have to wait for the trade to finish till he searches for a new entry.

              and thats why i have no defined amount of unique entries. because depending on how often the signal fires after the first trade, i could have a huge amount of entries.
              thats why i worked with "tag"+currentbar to make them unique. rather than a fix name.
              again, the only problem is, that i cant access the unique stops, once the next candle prints, bc the currentbar is diffrent. so i need something to move all currently active stopoders for every trade as a package to a certain point. but how shall i grab all of them as a package if i cant reproduce the tags (tag+currentbar) i used to create the stoporders.

              Comment


                #8
                Hello,

                Thank you for the reply.

                The purpose of the prior example was just to explain that multiple entries are linked with their stops by the signal name, in your situation you would likely need to come up with your own logic regarding the SignalName which does not include the CurrentBar but instead just a number system that increments or subtracts if the order is filled.

                The CurrentBar would only be valuable if you need to reference a prior bar, in this case you would never hit that bar number again making it difficult to use as an increment.

                One item which may help is that you can assign the Entry order to a variable so you could just an Array or List to store any amount of order objects. The naming would be based on what logic you come up with but this would likely be the way you need to go.

                There is a simple example in the help guide here for using IOrder objects : http://ninjatrader.com/support/helpG...ightsub=iorder

                This would go back to standard C# programming and logic, using the IOrder objects you can retrieve the orders SignalName or other information, you could also compare the object to Executions or Order Updates for all strategy orders using OnOrderUpdate or OnExecution. This would give you the ability to see which orders have filled to remove them from any arrays or lists, also you could do additional logic based on signal names etc..

                This would be the closes sample I can think of that shows how to store IOrder objects in an ArrayList and then later check the list and access the orders: http://ninjatrader.com/support/forum...ead.php?t=5790

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by benmarkal, Yesterday, 12:52 PM
                3 responses
                23 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by helpwanted, Today, 03:06 AM
                1 response
                19 views
                0 likes
                Last Post sarafuenonly123  
                Started by Brevo, Today, 01:45 AM
                0 responses
                11 views
                0 likes
                Last Post Brevo
                by Brevo
                 
                Started by pvincent, 06-23-2022, 12:53 PM
                14 responses
                244 views
                0 likes
                Last Post Nyman
                by Nyman
                 
                Started by TraderG23, 12-08-2023, 07:56 AM
                9 responses
                388 views
                1 like
                Last Post Gavini
                by Gavini
                 
                Working...
                X