# trailing stop order

hey there, this is the function i created in my script, for some reason when a trailing stop order is placed right i am trying to figure it out why it is not being updated or moving when the price is in the desired direction i set it to. i dont get it why .the all purpose of trailing stop is to move within the callback rate once the price goes up isnt it ? please help on this… i understand that the trailing stop order is for minimzing loses if the price goes in the expected direction and saving profits. if i set it to 0.1% call back this means the callback will be 0.1% moves each time it goes up or down. i think i understand that but still it doesnt seem to be properly works in futures .

def place_order_ta_stp_trailing_stop(self, side, amount, trailing_percentage=1.02, stop_loss_percentage=10.0,take_profit_percentage=1.02):
try:
# Fetch the current market price
current_price = self.get_last_price()
if current_price is None:
logging.error('Failed to fetch current market price')
return None

# Calculate the limit order price as 0.00000001% above the current market price
limit_order_price = current_price * (1 + 0.000000000000000000000000000000001) if side == 'BUY' else current_price * (1 - 0.000000000000000000000000000000001)

# Place the limit order
order = self.exchange.create_order(
symbol=self.pair,
type='LIMIT',
side=side,
price=limit_order_price,
amount=amount,
)
logging.info(f"Limit order placed at {limit_order_price}: {order}")

# Adjust the execution price based on the limit order price
execution_price = float(order['price'])

# Determine closing side based on the order side
closing_side = 'BUY' if side == 'SELL' else 'SELL'

# Calculate callbackRate for trailing stop, stop loss price, and take profit price
callback_rate = trailing_percentage
stop_loss_price = execution_price * (
1 - stop_loss_percentage / 100) if side == 'BUY' else execution_price * (
1 + stop_loss_percentage / 100)
take_profit_price = execution_price * (
1 + take_profit_percentage / 100) if side == 'BUY' else execution_price * (
1 - take_profit_percentage / 100)

# Create TRAILING_STOP_MARKET order with specified callback rate and activation price
self.exchange.create_order(
symbol=self.pair,
type='TRAILING_STOP_MARKET',
side=closing_side,
amount=amount,
params={
'callbackRate': trailing_percentage,
'activationPrice': execution_price,
'reduceOnly': 'True'
}
)
logging.info(
f"Trailing stop order set for {side} position with callback rate of {trailing_percentage}% at activation price {execution_price}")

# Create STOP_MARKET order for fixed stop loss
self.exchange.create_order(
symbol=self.pair,
type='STOP_MARKET',
side=closing_side,
amount=amount,
params={
'stopPrice': stop_loss_price,
'reduceOnly': 'True'
}
)
logging.info(f"Fixed stop loss order set for {side} position at price {stop_loss_price}")

# Create TAKE_PROFIT_MARKET order for take profit
self.exchange.create_order(
symbol=self.pair,
type='TAKE_PROFIT_MARKET',
side=closing_side,
amount=amount,
params={
'stopPrice': take_profit_price,
'reduceOnly': 'True'
}
)
logging.info(f"Take profit order set for {side} position at price {take_profit_price}")

return order
except Exception as err:
logging.error(f'An error occurred: {err}')
return None

could you please provide more details, did the order get triggered , what price is it when triggered?

the trailing stop is triggered with the same price the limit order is triggered. once an active limit order is triggered and I have activated the position it should have been moved in the favour of my position up or down with the specific call-back rate. I have 3 open orders for 1 active position = stop loss, take profit, and trailing stop. but it seems like the behavior of the trailing stop is a fixed stop loss percent from the price I entered and not being dynamically changed once the price goes in my favor, e.g. 0.1% up is not being updated or closing the positions if it returns to 0.09.

.e.g. I entered long position on Bitcoin when it was 35,000
I set the trailing stop to 0.1% which is 0.01% (correct me if I am wrong)
this means if the price goes to 35,070 then the new trailing stop will be 35,035 am I right?
then if the price drops down to 35,035 it will sell cause the new trailing stop is set to 35,035. but if the price continues to go up and let’s say it gets to 35,105, then the new trailing stop will be 35,070 and so forth and this isn’t happening for some reason and I don’t get why…

Any suggestions?
btw I’ve tried to delay the trailing stop order to be activated only 3-4 seconds after I have active positions or above a few points of the entry price I entered.

thanks for the fast reply btw!

the trailing stop is triggered with the same price the limit order is triggered. once an active limit order is triggered and I have activated the position it should have been moved in the favour of my position up or down with the specific call-back rate. I have 3 open orders for 1 active position = stop loss, take profit, and trailing stop. but it seems like the behavior of the trailing stop is a fixed stop loss percent from the price I entered and not being dynamically changed once the price goes in my favor, e.g. 0.1% up is not being updated or closing the positions if it returns to 0.09.

.e.g. I entered long position on Bitcoin when it was 35,000
I set the trailing stop to 0.1% which is 0.01% (correct me if I am wrong)
this means if the price goes to 35,070 then the new trailing stop will be 35,035 am I right?
then if the price drops down to 35,035 it will sell cause the new trailing stop is set to 35,035. but if the price continues to go up and let’s say it gets to 35,105, then the new trailing stop will be 35,070 and so forth and this isn’t happening for some reason and I don’t get why…

Any suggestions?
btw I’ve tried to delay the trailing stop order to be activated only 3-4 seconds after I have active positions or above a few points of the entry price I entered.

thanks for the fast reply btw!