Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

changing targets when averaging contracts

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

    changing targets when averaging contracts

    I'm trying to do the following:
    Enter long and set a target. No problem there. If I receive another entry condition before the target is hit, I want to add another contract but reduce the target. I can't figure out how to modify the target when >= 2 contracts are open. I tried
    Code:
    protected override void OnBarUpdate()
            {
                // Condition set 1
                if (Position.GetProfitLoss(Close[0], PerformanceUnit.Points) >= 10)
                {
                    ExitLong("Exit Long", "Long Entry");
                }
            }}
    but it doesn't seem to work. The open position never exits using this. Any thoughts how to achieve changing the target once >1 contracts are open?

    #2
    Tdschulz, to scale out of a position you would need to scale in first when using the Managed approach in NinjaScript, please take a look at this reference sample showing you how to achieve this - http://www.ninjatrader.com/support/f...ead.php?t=3751

    Comment


      #3
      Thank you for the info but I'm not trying to scale out of the position. I will scale into a position but exit at once. I have no problem if I use the same target always by use "SetProfitTarget("", CalculationMode.Ticks, 10) in the initialize section. However, I want to use a large target if I only have one contract on and use a small target if I have more than one contract on. I tried putting "SetProfitTarget" command in the OnBarUpdate section but it still doesn't seem to be working. What method do you suggest to achieve this goal?

      Comment


        #4
        Thanks for the clarification, the reason it's not triggering then for you is this line here -

        if (Position.GetProfitLoss(Close[0], PerformanceUnit.Points) >= 10)

        Points would be taken literally as 10 full points, so that's different from your 10 ticks set, as that would for example equal 2.5 points on the Emini SP.

        When working with SetProfitTarget() you would want to set the target dynamically, correct - depending on for example what Position.Quantity you current manage via the strategy - http://www.ninjatrader.com/support/h...7/quantity.htm

        Comment


          #5
          I did notice that at some point last night and corrected it but still no success. Entries are fine, stop loss is fine, but can't get the targets working. this example is for instruments with .01 tick increments. I have the following:
          Code:
           protected override void Initialize()
                  {
          
                      SetStopLoss(stoploss, false);
          		    EntriesPerDirection = MaxContracts; 
              		EntryHandling = EntryHandling.AllEntries; 
          			
          
                      CalculateOnBarClose = true;
                  }
          
                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
          	{
          			
          			if (ToTime(Time[0]) >= (starttime) && ToTime(Time[0]) < stoptime)
          				Print(Time.ToString()+"Time= "+Time[0]);
          			Print(Time.ToString()+"MarketPosition= "+Position.MarketPosition);
          		
                      // Condition set 1
          		
          			if (ToTime(Time[0]) >= (starttime) && ToTime(Time[0]) < (stoptime)) 
          			if (Position.MarketPosition == MarketPosition.Flat)
          				
          		
          				if (....................
          					
                      {
                          EnterLong(1, "LongEntry");
          		
                      }
          		
          			
          		//	Logic for adding when already in a long position
          			if (Position.MarketPosition == MarketPosition.Long)
          				if (...................
          				
                      {
                          EnterLong(1, "Buy");
          		//		SetProfitTarget("", CalculationMode.Ticks, Target2);
                      }
          
          		
                      // Condition set 2
          			
          				
          				if (ToTime(Time[0]) >= (starttime) && ToTime(Time[0]) < (stoptime))
          			if (Position.MarketPosition == MarketPosition.Flat)
          			
          					if (.............
          						
                      {
                          EnterShort(1, "ShortEntry");
          		
                      }
          			
          		
          			
          			if (Position.MarketPosition == MarketPosition.Short)
                                  if ................
          	
          					
          //					
                      {
                          EnterShort(1, "Sell");
          	
                      }
                  	
          
          			if ((Position.GetProfitLoss(Close[0], PerformanceUnit.Points) >= .2)
                          && Position.Quantity == 1)
                      {
                          ExitLong("LongTarget", "");
          		
                      }
          			if ((Position.GetProfitLoss(Close[0], PerformanceUnit.Points) >= .1)
                          && Position.Quantity >= 2)
                      {
                          ExitLong("LongTarget2", "");
          			
                      }
          			if ((Position.GetProfitLoss(Close[0], PerformanceUnit.Points) >= .2)
                          && Position.Quantity == -1)
                      {
                    
          				ExitShort("ShortTarget","");
                      }
          			if ((Position.GetProfitLoss(Close[0], PerformanceUnit.Points) >= .1)
                          && Position.Quantity < -1)
                      {
                     
          				ExitShort("ShortTarget2","");
                      }

          Comment


            #6
            I would suggest running with TraceOrders - http://www.ninjatrader.com/support/f...ead.php?t=3627 to see if you're getting any ignored orders here because your signal naming tags would be off.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            649 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            370 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            573 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            576 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X