Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ninja Trader Strategy and Exits

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

    Ninja Trader Strategy and Exits

    Hi, I´m programming my first module for Ninja Trader in C#, I use Kwik Indicators, and I complete it with not problem detecting and sending alerts for buy-sell situations.

    The problem starts when I change my buy and sell alerts with EnterLon-Short and Exit Long-short commands. When I load My stratregy in chart, the historical orders affect my first purchase! The ExiLong and ExitShort enter and buy and sell positions instead of exit! What can i do? I need a flat position to enter, but the system load all strategy and get my flags and vars in game when i enter!

    #2
    Not sure if I completely understand but...

    As you start a strategy, it will calculate it current position and orders state. It may be that the strategy calculates that it is long 1. You should then synchronize your brokerage account to this positon by placing an order that makes you live account 1 long. This can be done in the Orders tab.
    RayNinjaTrader Customer Service

    Comment


      #3
      this is a example code:

      Code:
      case "Buy":	// Case of severals options, from general Switch var TipoTrade
            if (Position.Quantity > 0 )	
      	{
      	      ExitLong ( "Buy"); // Buy is the Name of EnterLong
      	      Thread.Sleep(2000);  // I try to delay to give time to exit succesfully
                        EnterShort ( NumeroVenta, "Sale"); // Get a Short Position 
      	       TipoTrade = "Sale" ;  // a flag var that i use.
      	       Alert("AlertaVenta2", Priority.High, "Venta KwikPivotPop. Estado Bandera: " + TipoTrade + " Posiciones: " + Position.Quantity.ToString(), @"C:\Archivos de Programa\NinjaTrader 6\sounds\Alert2.wav", 60, Color.LightPink, Color.Black);     // Alert message
      					}
      	break;
      In this case, the system give me several error messages about the handle of Long short operations.


      The other code is this:

      Code:
      if (CrossBelow(KPA900(), KPAutoStop(), 1))  // Indicators from Kwiwk No problem with the event :)
                  {
                      	
      		 if ( Position.Quantity > 0 && TipoTrade == "Compra")	
       {
      					
           ExitLong();  // I want exit of all Long positions to flat!
          TipoTrade = "FreeforTrade";  // var flag
          Alert("MyAlert3", Priority.High, "Saliendo de una Compra, Estado Bandera: " + TipoTrade + " Posiciones: " + Position.Quantity.ToString(), @"C:\Archivos de Programa\NinjaTrader 6\sounds\Alert2.wav", 60, Color.PaleGreen, Color.Black); // Alert
      		} 			
                  }
      In this case, if i start the trade with a "historical" estrategy on course, it ExitLong dont work and get options instead of exit!
      Last edited by Agamenon; 11-06-2007, 02:09 PM.

      Comment


        #4
        In the first case you don't need to ExitLong before EnterShort. If you have an open long position and you do an EnterShort it will automatically close the long position and then reverse you into a short position.

        In the second code you may want to check your NinjaScript settings. http://www.ninjatrader-support.com/H...tegiesTab.html
        You want to choose "Wait until flat before executing live". Alternatively, you can use this in your code to prevent any flag setting/virtual trades on historical data.
        Code:
        if (Historical)
             return;
        Place this in the beginning of OnBarUpdate() method.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          nice, them is correct to use EnterShort or Long to cut and get reverse in another contrary EnterLong-Short if my strategy needed! Thx

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          633 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          364 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          567 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          568 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X