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

The problem with the number of reverses

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

    The problem with the number of reverses

    Hello, help please, I made a strategy with the reverse position when triggered stop loss, but it so happened that now the position is flipped each time it is triggered stop until closed by take profit, please tell me how to make the reverse worked only once at the closing of the stop loss?

    #2
    Originally posted by Kovalev View Post
    Hello, help please, I made a strategy with the reverse position when triggered stop loss, but it so happened that now the position is flipped each time it is triggered stop until closed by take profit, please tell me how to make the reverse worked only once at the closing of the stop loss?
    When building and coding your own NinjaTrader strategy, you can program you logic and spend 1000s of hours re-inventing the wheel and if you are not an expert your strategy will never be a reliable live trading commercial standard you need to use NinjaTrader unmanaged code and be a c# developer of some 5 years plus to be an ok commercial level at coding.. However there is no need for that.

    you can simply use this free NinjaTrader developer technology and build your own strategies. Please see the MTDS7 Strategy Development Kit – Trade Engine
    MTDS7 Strategy Development Kit Automated Algorithmic Trading Framework API advanced strategy development foundation for NinjaTrader. Build Your Automated Trading Systems Developed with the MTDS7 Strategy Development Kit in NinjaTrader 7 Unmanaged Mode for Professional reliability and execution.

    MTDS7 was purpose built for live trading & Rapid Strategy Creation in just 2 lines of code with unrivaled features the first and only of it’s kind and it’s 100% FREE for sim trading unlimited! - you can download it here 100% always free and use the ready to trade,edit, modify sample open source ninjatrader strategies.

    http://microtrends.co/ninjatrader-downloads#MTDS
    MicroTrends
    NinjaTrader Ecosystem Vendor - micro-trends.co.uk

    Comment


      #3
      Hello Kovalev,

      If you would like help with your existing NinjaScript strategy could you please provide the script you are currently working on? It would be difficult to say what may be happening without seeing what you are currently trying.
      If this is a wizard strategy, you could also include screen shots of the wizard steps as that would be helpful.

      You can export a strategy using the following steps: http://ninjatrader.com/support/helpG...nt7/export.htm

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

      Comment


        #4
        Yes of course, here it is

        conditions of entry example of
        Attached Files

        Comment


          #5
          Hello Kovalev,

          Thank you for posting the example that helps.

          I wanted to clarify, you said that you want the reversal to happen only once after the stoploss is closed(filled?). Did you mean that you only want it to reverse one time and then prevent the reversal from being able to happen again? Could you explain further what action is currently happening? It may help if you post an image of the results you are currently seeing as well.

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

          Comment


            #6
            So I sketched schematically
            Attached Files

            Comment


              #7
              Hello Kovalev,

              Thank you for the image.

              To prevent further trading after 1 reversal, you would need to account for that with logic.

              You could do something as simple as using an int counter or a bool variable. Because you're entering in one of two directions you would likely need to check if the direction has previously been used by setting a variable to a specific value. You could then check this value in your entries conditions and prevent them if the variable is set.

              Can you confirm, is this what you had intended per your image or stop trading completely once the reversal occurs?

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

              Comment


                #8
                Hello NinjaTrader_Jesse, Yes, that's exactly what I wanted, you understood correctly.
                And could you throw an example, at least in general terms?

                Comment


                  #9
                  Hello Kovalev,

                  I will provide a very simple example of what I am referring to below, you could choose how you want to implement this further in your own script. Mainly you just need to set a variable to know the condition has already happened, once it has you can change the outcome of your logic if so.
                  Code:
                  [B]private bool reversedToLong = false;
                  private bool reversedToShort = false;[/B]
                  
                  		
                  protected override void OnOrderUpdate(IOrder order)
                  {
                  	// Handle entry orders here. The entryOrder object allows us to identify that the order that is calling the OnOrderUpdate() method is the entry order.
                  	if (entryOrder != null && entryOrder == order)
                  	{	
                  		// Reset the entryOrder object to null if order was cancelled without any fill
                  		if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                  		{
                  			entryOrder = null;
                  		}
                  	}
                  	if ((entryOrder == null) && (order.Name == "MyLongStop") && (order.OrderState == OrderState.Filled) [B]&& !reversedToShort[/B])
                  	{
                  		entryOrder = EnterShortLimit(1, order.StopPrice, "Short");
                  		r[B]eversedToShort = true;[/B]
                  	}
                  	if ((entryOrder == null) && (order.Name == "MyShortStop") && (order.OrderState == OrderState.Filled) [B]&& !reversedToLong[/B])
                  	{
                  		entryOrder = EnterLongLimit(1, order.StopPrice, "Long");
                  		[B]reversedToLong = true;[/B]
                  	}
                  }
                  Using a bool you can set if the reverse condition had previously become true, you could also move this to when the opposing order actually fills if you wanted as well. This is just to mark that the order has been reversed once, now that it has happened it won't allow it to do this again.

                  You would need to experiment to see what works best for what you are trying to achieve, this would just be a general example and may not produce the desired result. This specific example is more or less to demonstrate a concept of defining a condition and variable for that condition.

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

                  Comment


                    #10
                    Thank you so much, your help is invaluable!

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by RookieTrader, Today, 09:37 AM
                    3 responses
                    15 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by kulwinder73, Today, 10:31 AM
                    0 responses
                    8 views
                    0 likes
                    Last Post kulwinder73  
                    Started by terofs, Yesterday, 04:18 PM
                    1 response
                    24 views
                    0 likes
                    Last Post terofs
                    by terofs
                     
                    Started by CommonWhale, Today, 09:55 AM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_Erick  
                    Started by Gerik, Today, 09:40 AM
                    2 responses
                    8 views
                    0 likes
                    Last Post Gerik
                    by Gerik
                     
                    Working...
                    X