ArjunVachhani / order-matcher

simple, fast and feature rich order matching engine supports limit, market, stop-loss, iceberg, IOC, FOK, GTD orders
MIT License
137 stars 70 forks source link

Logic behind triggering stop orders while _marketprice differs! #48

Closed Kordeone closed 2 years ago

Kordeone commented 2 years ago

I would like to know why you limited triggering stop orders as _marketPrice changes! I have read articles and I think the if condition for triggering them is somehow an action of fear

if (_marketPrice > previousMarketPrice)
{
    var priceLevels = _book.RemoveStopBids(_marketPrice);
    AddStopToOrderBook(priceLevels);
}
else if (_marketPrice < previousMarketPrice)
{
    var priceLevels = _book.RemoveStopAsks(_marketPrice);
    AddStopToOrderBook(priceLevels);
}

doesn't this limit when I want to sell when the price breaks a higher resistance on a better price?

ArjunVachhani commented 2 years ago

I am not sure I understand you question, lets say current price is 100, you want to sell at 105 then you could use just a limit order(setting price 105). other situation you want to sell only if price goes below 95 then you will use stop order(setting stop price to 95)

Kordeone commented 2 years ago

While the market price goes up only buy stop orders will be triggered. so if I have a sell order with trigger price of 52 and the _marketPrice is 50 and it goes up to 52, my order will not be triggered. but if it was a buy order with StopPrice of 52 it would be triggered!

ArjunVachhani commented 2 years ago

for buy orders stop price will be higher then market price, for sell orders stop price would be lower then market price. hence if price goes up then only need to trigger for buy stop orders, similarly if price goes down only need to trigger for sell stop orders

Kordeone commented 2 years ago

I do understand how it works, but what if I want to sell if the market is going up and after a certain price I want to trigger my sell price!? I would have to wait for it to pass the trigger and then come back to it so my stop order will be pushed to the market!

ArjunVachhani commented 2 years ago

I guess then you could use limit sell order.