sdcoffey / techan

Technical Analysis Library for Golang
https://godoc.org/github.com/sdcoffey/techan
MIT License
840 stars 143 forks source link

this is a bug #8

Open beaquant opened 5 years ago

beaquant commented 5 years ago

Hello sdcoffey, Long time to see you here, I hope you're ok. In this function, it's not satisfied to use close price divide CostBasis

func (slr stopLossRule) IsSatisfied(index int, record *TradingRecord) bool {
    if !record.CurrentPosition().IsOpen() {
        return false
    }

    openPrice := record.CurrentPosition().CostBasis()
    loss := slr.Indicator.Calculate(index).Div(openPrice).Sub(big.ONE)
    return loss.LTE(slr.tolerance)
}

https://github.com/sdcoffey/techan/blob/e00a0328927e1200be0fdd9989d83cb494cf870d/rule_stop.go#L24

sdcoffey commented 5 years ago

Hey @beaquant,

thanks for opening this issue. Can you explain your thinking? I'm afraid I don't follow.

beaquant commented 5 years ago

thanks for your reply. the stop rule you make it, it mean stop = (current close price / open cost) -1. if i buy something 100 amount @ 3000 price, but now price is 2500, then stop=(2500/100*3000)-1, stop=-0.9916, what's mean for this -0.9916? if i buy something 200 amount @ 3000 price, but now price is 2500, then stop=(2500/200*3000)-1, stop=-0.9958, what's mean for this -0.9958?

I think stop loss is a radio for the open price. stop = (open price / current close price) -1 stop=(2500/3000)-1, stop=-0.166, loss 16% am i right to understand the rule?

beaquant commented 5 years ago

BTW, do you have any advance plane to update this repo and release new version?