Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnExecution Method

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

    OnExecution Method

    Hi Guys

    I've recently introduced a fixed profit target into my system and every now and then it's causing a crash somewhere, I have checked and rechecked my code and can't see an issue, furthermore I have replayed several instances of the crash on Market Replay and it doesn't happen the way it did on the live SIM. It has occurred to me that I may be referring to objects incorrectly in my OnExecution Method. Perhaps you could confirm. I have pasted the code below, for simplicity I've removed as much of the stuff that is not relevant.

    Basically this order is a stop and reverse order that has just executed, on execution I set a profit target for the order based on a parameter that decides whether to add a fixed pip value specified in another parameter or whether to use an R-Multiple ratio which is not relevant as in this instance I'm using a fixed target. So FLTT parameter is 1.

    Here is the code:

    protectedoverridevoid OnExecution(IExecution execution)
    {
    if (ShortOrderSAR != null && ShortOrderSAR.Token == execution.Order.Token)
    {
    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
    {
    LongEntry=ShortOrderSAR.AvgFillPrice;

    if(FLTT==1)
    LongTargetPrice = LongEntry + FixedLimTarget * TickSize;
    else
    LongTargetPrice = LongEntry + ((LongPriceDifference*FixedLimTarget)*TickSize);

    ShortOrderTargetSAR = ExitLongLimit(
    1, true, execution.Order.Filled,LongTargetPrice, "SSAR P", "SSAR1");
    }

    if (execution.Order.OrderState != OrderState.PartFilled)
    {
    ShortOrderSAR =
    null;
    }
    }
    }

    What happens is intermittendly my program crashes with a could not create order below the bid etc. and says I tried to use a price of 0.0150 which is effectively my fixed target but somehow it has lost the original price that should be set as the fill price in this object. Should I be using

    LongEntry=execution.Order.AvgFillPrice;

    instead of

    LongEntry=ShortOrderSAR.AvgFillPrice;

    I can't see how this makes a difference but somewhere along the lines I seem to be getting a zero in LongEntry when I believe it should always be populated with the fill price of the order executing.

    Thanks for the help.

    Cheers
    Ross

    #2
    Hi Ross, it shouldn't matter which one you use - please work with TraceOrders and Print statements in your code to check which section of the code create the issue of the target order being submitted at the erroneous price - http://www.ninjatrader-support2.com/...ead.php?t=3418

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    79 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    45 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    29 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    32 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    65 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X