Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Output when changing order

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

    Output when changing order

    Hello

    I have an strategy where stop order change to BE in certain conditions. It runs OnEachTick.

    if (MyBreakEven == BreakEven.Yes
    && stopShortOrder != null
    && stopShortPrice > Position.AveragePrice
    && CurrentBar > barNumberOfEntryShort)
    {
    targetShortPricetoBE = (Position.AveragePrice - ((Position.AveragePrice - targetShortPrice) * 0.5));
    if (Low[0] <= targetShortPricetoBE)
    {
    ChangeOrder(stopShortOrder, stopShortOrder.Quantity, 0, Position.AveragePrice);
    if (!printOnce)
    {
    Print(Time[0] + " || " + Name + " || " + Account + " || " + Instrument);
    Print(" StopShort to BE " + targetShortPricetoBE + " Objetivo " + targetShortPrice);
    Print("");
    printOnce = true;
    }
    }
    }

    The problem is that when it occurs, output windows print a line every tick until position is closed

    30/12/2020 20:03:04 Strategy 'TrendFree V 1.01/137491657': Changed custom managed order: orderId='b2f88af3e99f433e95447cb75c7be0a5' account='SimStrategies' name='Stop S1' orderState=Accepted instrument='NQ 03-21' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=12869.375 quantity=2 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=42868 time='2020-12-30 20:01:17' gtd='2099-12-01' statementDate='2020-12-30' limitPriceChanged=0 quantityChanged=2 stopPriceChanged=12869,375
    30/12/2020 20:03:04 Strategy 'TrendFree V 1.01/137491657': Changed custom managed order: orderId='b2f88af3e99f433e95447cb75c7be0a5' account='SimStrategies' name='Stop S1' orderState=Accepted instrument='NQ 03-21' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=12869.375 quantity=2 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=42868 time='2020-12-30 20:01:17' gtd='2099-12-01' statementDate='2020-12-30' limitPriceChanged=0 quantityChanged=2 stopPriceChanged=12869,375
    30/12/2020 20:03:04 Strategy 'TrendFree V 1.01/137491657': Changed custom managed order: orderId='b2f88af3e99f433e95447cb75c7be0a5' account='SimStrategies' name='Stop S1' orderState=Accepted instrument='NQ 03-21' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=12869.375 quantity=2 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=42868 time='2020-12-30 20:01:17' gtd='2099-12-01' statementDate='2020-12-30' limitPriceChanged=0 quantityChanged=2 stopPriceChanged=12869,375
    30/12/2020 20:03:04 Strategy 'TrendFree V 1.01/137491657': Changed custom managed order: orderId='b2f88af3e99f433e95447cb75c7be0a5' account='SimStrategies' name='Stop S1' orderState=Accepted instrument='NQ 03-21' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=12869.375 quantity=2 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=42868 time='2020-12-30 20:01:17' gtd='2099-12-01' statementDate='2020-12-30' limitPriceChanged=0 quantityChanged=2 stopPriceChanged=12869,375
    30/12/2020 20:03:05 Strategy 'TrendFree V 1.01/137491657': Changed custom managed order: orderId='b2f88af3e99f433e95447cb75c7be0a5' account='SimStrategies' name='Stop S1' orderState=Accepted instrument='NQ 03-21' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=12869.375 quantity=2 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=42868 time='2020-12-30 20:01:17' gtd='2099-12-01' statementDate='2020-12-30' limitPriceChanged=0 quantityChanged=2 stopPriceChanged=12869,375
    30/12/2020 20:03:05 Strategy 'TrendFree V 1.01/137491657': Changed custom managed order: orderId='b2f88af3e99f433e95447cb75c7be0a5' account='SimStrategies' name='Stop S1' orderState=Accepted instrument='NQ 03-21' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=12869.375 quantity=2 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=42868 time='2020-12-30 20:01:17' gtd='2099-12-01' statementDate='2020-12-30' limitPriceChanged=0 quantityChanged=2 stopPriceChanged=12869,375
    30/12/2020 20:03:05 Strategy 'TrendFree V 1.01/137491657': Changed custom managed order: orderId='b2f88af3e99f433e95447cb75c7be0a5' account='SimStrategies' name='Stop S1' orderState=Accepted instrument='NQ 03-21' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=12869.375 quantity=2 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=42868 time='2020-12-30 20:01:17' gtd='2099-12-01' statementDate='2020-12-30' limitPriceChanged=0 quantityChanged=2 stopPriceChanged=12869,375

    How can I prevent from this behaviour?

    Thanks

    #2
    Hello impeeza,

    Thank you for your reply.

    This doesn't have anything to do with your print statements, this looks like it's from the Log tab of the Control Center or printed in the Output log if you have TraceOrders = true in State.SetDefaults. It's occurring because this will fire off on each tick when the current Low is less than or equal to your TargetShortPricetoBE value.

    if (Low[0] <= targetShortPricetoBE)
    {
    ChangeOrder(stopShortOrder, stopShortOrder.Quantity, 0, Position.AveragePrice);
    //code continues

    It's because this gets fired off repeatedly for that same order. I'd perhaps consider using a bool to only trigger this one time, when the Low is initially below the target short price, and reset that bool when the position is exited, much like you're doing with that printOnce bool.

    Please let us know if we may be of further assistance to you.

    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by zstheorist, Today, 07:52 PM
    0 responses
    7 views
    0 likes
    Last Post zstheorist  
    Started by pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    150 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Started by mattbsea, Today, 05:44 PM
    0 responses
    6 views
    0 likes
    Last Post mattbsea  
    Started by RideMe, 04-07-2024, 04:54 PM
    6 responses
    33 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Started by tkaboris, Today, 05:13 PM
    0 responses
    6 views
    0 likes
    Last Post tkaboris  
    Working...
    X