Announcement

Collapse
No announcement yet.

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.

    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.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        81 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        41 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        64 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        66 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        54 views
        0 likes
        Last Post CarlTrading  
        Working...
        X