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

does SetStopLoss function causes extra queries?

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

    does SetStopLoss function causes extra queries?

    1) In each OnBarUpdate, i have set `SetStopLoss`, so i think it executes on every tick.
    Does that cause to send extra queries to broker (plus, output order/log messages on every tick)?

    2) let's say, the solution is to move that inside condition (i.e. in OnExecution) , but i am mostly worried with MoveToBreakEven, because i use :


    Code:
    ...
    if(MarketPosition == MarketPosition.Long){
      if (TicksFromEntry > MoveToBE_Enough_ticks) {
          SetStopLoss (........);
      }
    }
    ...
    then once it goes over the BE_points, then on every next tick, it still causes to issue SetStopLoss. Should I code it more, to execute that command only once? or can i leave it as is (but i see the log appearing on every tick, that i dont like and only want to execute once).

    Should I use:


    Code:
    ... 
    ...
      if (TicksFromEntry > MoveToBE_Enough_ticks) {
         if(!be_executed) {
           SetStopLoss (........);
           be_executed=true;
         }
      }
    ...
    ...

    #2
    Hello selnomeria,

    Thanks for opening the thread.

    You are coming up with valid approaches to the issue you are facing. Calling SetStopLoss() on every tick can send extra updates that may modify the stop loss and perform the internal logic behind the method. If the price for the SetStopLoss() does not change from last time it was called no further action will be taken. However, calling it only as often as needed would be advised.

    Using a doOnce bool to control the breakeven so it occurs once would be a good solution.

    If you have any additional questions, please don't hesitate to ask.
    JimNinjaTrader Customer Service

    Comment


      #3
      so, as i understand, the problem arises when the price is different.
      so, as long as price is be same, calling SetStopLoss on every tick, causes:

      A) nothing at all
      B) just outputing log messages in LOG tab, but doesnt submits order to brokers
      C) B, also sending an command to broker (but broker doesnt react with same stoploss value)

      As i understand, B is right?
      Last edited by ttodua; 09-09-2017, 01:17 AM.

      Comment


        #4
        Hello selnomeria,

        You are on the right track, but to be exact, the order method will always have some sort of output feedback in the Output window with TraceOrders enabled. The behavior is between A and B. If the price does not change, there will not be a noted change in the log tab of the Control Center and there will not be an additional submission sent to the broker.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by elderan, Today, 08:03 PM
        0 responses
        2 views
        0 likes
        Last Post elderan
        by elderan
         
        Started by algospoke, Today, 06:40 PM
        0 responses
        10 views
        0 likes
        Last Post algospoke  
        Started by maybeimnotrader, Today, 05:46 PM
        0 responses
        9 views
        0 likes
        Last Post maybeimnotrader  
        Started by quantismo, Today, 05:13 PM
        0 responses
        7 views
        0 likes
        Last Post quantismo  
        Started by AttiM, 02-14-2024, 05:20 PM
        8 responses
        169 views
        0 likes
        Last Post jeronymite  
        Working...
        X