• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetProfitTarget not working in OnBarUpdate

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

    SetProfitTarget not working in OnBarUpdate

    I have the following bit of code that I am attempting to use to create an entry with associated trailing stops and profit target. The profit target never gets hit. Proving that to myself by commenting out the trailing stop.

    Is this the appropriate use of SetProfitTarget?

    And related, what is the impact to my backtest by setting an entry price for the EnterLongLimit that is less than current Close[0]? Is this making my results look better than reality, or is that limit actually not filled if the next bar does not have tick that would fill as in the real world?

    Code:
     
    void Buy()
    {
    	int size = 0;
    	double entryPrice = 0.0;
    			
    	if (this.TradingStocks) {
    		entryPrice = Close[0] - (_atr[0] * this.ATRMultiple);
    		size = (int) (this.InitialCapital / entryPrice);
    	}
    	else if (this.TradingFutures) {
    		entryPrice = Close[0] - (Math.Truncate(_atr[0] * this.ATRMultiple) / TickSize);
    		size = (int) (this.InitialCapital / 20000.0);
    	}
    			
    	if (size > 0) {
    		base.EnterLongLimit(size, entryPrice, "B"+base.CurrentBar);
    		base.SetProfitTarget("B"+base.CurrentBar, CalculationMode.Ticks, Math.Truncate((_atr[0] * this.ATRMultiple) / TickSize), false);
    		//base.ExitLongLimit(entryPrice + (TickSize * Math.Truncate(_atr[0] * this.ATRMultiple)), "B"+base.CurrentBar);
    		base.SetTrailStop("B"+base.CurrentBar, CalculationMode.Ticks, Math.Truncate((_atr[0] * this.ATRMultiple) / TickSize), false);
    	}
    }

    #2
    Hello RandyT,

    Thank you for your note.

    The EnterLongLimit call you have will be canceled if not filled on the bar it’s submitted. If you wanted it to remain working you could you use the syntax which includes isLiveUntilCancelled. See the last syntax at the following link,
    https://ninjatrader.com/support/help...rlonglimit.htm

    Are you seeing any errors on the log tab of the control center when running the strategy related to your profit target?

    I would suggest the following two links on debugging.

    Using prints to understand behavior:
    https://www.youtube.com/watch?v=K8v_...tu.be&t=48m45s

    Link covering debugging which you may find helpful.
    Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Alan, thanks for your response.

      I believe that the issue was more caused by my miscalculation of entry, exit and target prices.

      Can you tell me how will the system respond when trading futures contracts with specific tick values if you give it an order for something that does not round to a specific tick value? For example, sending an order to buy ES at 2800.28 vs. on the tick boundary of 2800.25?

      Comment


        #4
        Hello RandyT,

        The price will be rounded to the nearest tick. It would be good practice to avoid this though, at the very least for debugging down the road.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by safbrathpro, Today, 05:51 AM
        0 responses
        4 views
        0 likes
        Last Post safbrathpro  
        Started by abfefmu, Today, 05:33 AM
        0 responses
        4 views
        0 likes
        Last Post abfefmu
        by abfefmu
         
        Started by bbdjad, Today, 04:36 AM
        0 responses
        4 views
        0 likes
        Last Post bbdjad
        by bbdjad
         
        Started by mittie3, Today, 03:33 AM
        0 responses
        7 views
        0 likes
        Last Post mittie3
        by mittie3
         
        Started by Againmain1, Today, 03:04 AM
        0 responses
        10 views
        1 like
        Last Post Againmain1  
        Working...
        X