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 AaronKoRn, Today, 09:49 PM
    0 responses
    2 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Today, 08:42 PM
    0 responses
    8 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Today, 07:51 PM
    0 responses
    9 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,975 views
    3 likes
    Last Post jhudas88  
    Started by rbeckmann05, Today, 06:48 PM
    0 responses
    9 views
    0 likes
    Last Post rbeckmann05  
    Working...
    X