Reputation: 13
I'm trying to make a back trading class. but I don't really get how spread works for example if you buy in 1.06649 how will spread works here? and in the same trade if I exit in my intended take profit where will it stop? I'm also confuse with how spread works in stoploss
def calculate_take_profit_buy(self, current_price, point_value, take_profit_points, spread):
return current_price + (take_profit_points * point_value)
def calculate_stop_loss_buy(self, current_price, point_value, stop_loss_points, spread):
return current_price - (stop_loss_points * point_value)
def calculate_take_profit_sell(self, current_price, point_value, take_profit_points, spread):
return current_price - (take_profit_points * point_value)
def calculate_stop_loss_sell(self, current_price, point_value, stop_loss_points, spread):
return current_price + (stop_loss_points * point_value)
I tried to chat gpt it seems more confusing. I found a forum from 2006 that I should add the spread in entry when buying and add spread on exit when selling. not sure if it's true until today
Upvotes: 0
Views: 77
Reputation: 439
You can think of just two separate prices - ask
and bid
, one is always higher than the other, and spread is just the difference between them. You open your trade in ask and close in bid (when buying), or vice versa (when selling).
Spread always works against your profits: if you buy in 1.06649 and the spread is 0.01, the selling price at the moment of buying will be 1.05649. If you sell because you think the price should go down - the spread will make your closing price slightly higher.
Other way to see this:
your profit = (change of price(bid or ask, depending on you buy or sell) - spread in the moment of closing) * trade size
And if you want to close trade when you have specific profit, closing price can be calculated (for buying):
close price bid =
(desired profit / profit per point) * (current price bid - open price ask) =
(desired profit / profit per point) * (current price ask - current spread - open price ask)
Upvotes: 0