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

    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by mgco4you, Today, 09:46 PM
    1 response
    2 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by wzgy0920, Today, 09:53 PM
    0 responses
    3 views
    0 likes
    Last Post wzgy0920  
    Started by Rapine Heihei, Today, 08:19 PM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by Rapine Heihei, Today, 08:25 PM
    0 responses
    6 views
    0 likes
    Last Post Rapine Heihei  
    Started by f.saeidi, Today, 08:01 PM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Working...
    X