Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

chase profit target not working

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

    chase profit target not working

    Dear NT team,

    Need some clarifications in the ProfitChaseStopTrailExitOrdersExample that was posted some time back in the NT forum. I'm trying to chase my profit target based on the implementation given in this example, but it is not working. Not sure why the chase profit target is not working, so, i try to print the profitTarget objects, I get error Null object. Could you please help me to understand this peice of logic, how it works?


    Print(" line 188 - profit target order state");
    Print("profit target order state"+ profitTarget.OrderState);
    Print("tick Secondary "+ tickSizeSecondary);
    Print("profit target distance"+ ProfitTargetDistance);

    // trailing logic
    // the profitTarget/stopLoss is first created when the entry order fills. If it exists then move it.

    // trigger the chase action when the current price is further than the set distance to the profit target
    if (ChaseProfitTarget &&
    profitTarget != null && (profitTarget.OrderState == OrderState.Accepted || profitTarget.OrderState == OrderState.Working) &&
    Close[0] < currentPtPrice - ProfitTargetDistance * tickSizeSecondary)
    {
    Print(Time[0].ToString());
    Print(" line 198 - inside chase profit target order state");
    currentPtPrice = Close[0] + ProfitTargetDistance * tickSizeSecondary;
    ExitLongLimit(1, true, entryOrder.Quantity, currentPtPrice, "profit target", entryOrder.Name);
    }

    // trigger the trail action when the current price is further than the set distance to the stop loss
    if (TrailStopLoss &&
    stopLoss != null && (stopLoss.OrderState == OrderState.Accepted || stopLoss.OrderState == OrderState.Working) &&
    Close[0] > currentSlPrice + StopLossDistance * tickSizeSecondary)
    {
    currentSlPrice = Close[0] - StopLossDistance * tickSizeSecondary;
    ExitLongStopMarket(1, true, entryOrder.Quantity, currentSlPrice, "stop loss", entryOrder.Name);
    }
    Attached Files

    #2
    Hi, thanks for posting.

    Does the original example work when you test it? What did you change about this original example and what is the exact null reference you are getting? If you are unsure where the null reference is coming from, use Visual Studio to break when the exception occurs, see here for a guide on how to do this:



    Kind regards,
    -ChrisL

    Comment


      #3
      Printing the objects of profitTarget throwing error. is it a callback function? Does the chase profit target work based on OnOrderUpdate() ?


      Print(" line 188 - profit target order state");
      Print("profit target order state"+ profitTarget.OrderState);
      Print("tick Secondary "+ tickSizeSecondary);
      Print("profit target distance"+ ProfitTargetDistance);

      Comment


        #4
        Hi radhmu978, thanks for the follow up. I am not sure what function you are asking about here, Print() is not a callback function, nor do you use callback functions very much in the NinjaScript library by default. The chasing/trailing in this example takes place within OnBarUpdate during the 1 Tick series update. For a more simple example of advanced order handling, see this example:


        Best regards,
        -ChrisL

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        52 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        70 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        43 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        47 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X