Square Off Order in Advance


In Live Trading, since tick by tick data is unavailable on the platform, can I place the square off order at the time placing entry order.

  1. For eg, place BUY order at 10.00 am at market price of 90 and square off order (SELL) at 100 as a LIMIT order, will it be placed with my broker?

  2. How will it reflect in PnL tracker? Will it reflect?

Example Code:

def strategy_enter_position(self, candle, instrument, sideband_info):
    self.logger.info('Entering Position')
    self.main_order_map[instrument] = self.broker.OrderRegular(instrument, sideband_info['action'], quantity=self.number_of_lots * instrument.lot_size, position=BrokerExistingOrderPositionConstants.ENTER)
    buy_order_status = str(self.main_order_map[instrument].get_order_status())
    child = sideband_info['child']
    if buy_order_status == 'COMPLETE':

self.order_details[‘FirstSellOrder’]=self.broker.OrderRegular(instrument=instrument, order_transaction_type=‘SELL’, quantity=2*self.instrument.lot_size, related_order=self.main_order_map[instrument], position=BrokerExistingOrderPositionConstants.EXIT, order_variety=BrokerOrderVarietyConstants.LIMIT, price = self.Action[child][‘Target1’])


        self.order_details['SecondSellOrder']=self.broker.OrderRegular(instrument=instrument, order_transaction_type='SELL', quantity=2*self.instrument.lot_size, related_order=self.main_order_map[instrument], position=BrokerExistingOrderPositionConstants.EXIT, order_variety=BrokerOrderVarietyConstants.LIMIT, price=self.Action[child]['Target2'])

Hi @Rutul_Patel,

Your logic is sound and we think this will work correctly and the PnL will also get reflected as required.

Kindly let us know if you face issues here, after implementing your logic.

Warm Regards,

So if I just put these orders then nothing in code to check entry exit, based on market prices, orders at broker end will be executed and same will automatically get reflected in PnL?

Hi @Rutul_Patel,

We place 2 orders:

  1. Entry order
  2. Exit order (LIMIT)

We believe that the PnL will get reflected correctly once the LIMIT order gets executed.


Hi @Rutul_Patel,

Kindly see this post and join us on Slack.


Thank you for your reply on this.

Once the LIMIT order is executed on the broker platform,

  1. Will the status be automatically updated in AlgoBulls platform?
  2. Do I need to check the status only under strategy_exit_position method? or can it be checked at the end of every candle in strategy_select_instruments_for_exit or strategy_select_instruments_for_entry