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 judysamnt7, 03-13-2023, 09:11 AM
    4 responses
    59 views
    0 likes
    Last Post DynamicTest  
    Started by ScottWalsh, Today, 06:52 PM
    4 responses
    36 views
    0 likes
    Last Post ScottWalsh  
    Started by olisav57, Today, 07:39 PM
    0 responses
    7 views
    0 likes
    Last Post olisav57  
    Started by trilliantrader, Today, 03:01 PM
    2 responses
    22 views
    0 likes
    Last Post helpwanted  
    Started by cre8able, Today, 07:24 PM
    0 responses
    10 views
    0 likes
    Last Post cre8able  
    Working...
    X