-
Notifications
You must be signed in to change notification settings - Fork 154
adjust log format in LogTradesAnalysis Analyze #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
cb7f53b
abdf03e
8cdec05
cd2e5e7
77f27f7
a86ee6e
1137a25
6ebb3ef
3c20b12
a7df3b2
c10b66c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,19 @@ | ||
| package techan | ||
|
|
||
| import "github.com/sdcoffey/big" | ||
| import ( | ||
| "github.com/sdcoffey/big" | ||
| ) | ||
|
|
||
| type stopLossRule struct { | ||
| Indicator | ||
| tolerance big.Decimal | ||
| } | ||
|
|
||
| type stopGainRule struct { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You actually don't need to define a duplicate struct here, since this one is private. I would redefine the above rule as type stopRule struct {
Indicator
tolerace big.Decimal
}and then make an alias for both type stopLossRule = stopRule
type stopGainRule = stopRule |
||
| Indicator | ||
| tolerance big.Decimal | ||
| } | ||
|
|
||
| // NewStopLossRule returns a new rule that is satisfied when the given loss tolerance (a percentage) is met or exceeded. | ||
| // Loss tolerance should be a value between -1 and 1. | ||
| func NewStopLossRule(series *TimeSeries, lossTolerance float64) Rule { | ||
|
|
@@ -20,8 +27,31 @@ func (slr stopLossRule) IsSatisfied(index int, record *TradingRecord) bool { | |
| if !record.CurrentPosition().IsOpen() { | ||
| return false | ||
| } | ||
|
|
||
| openPrice := record.CurrentPosition().CostBasis() | ||
| openPrice := record.CurrentPosition().EntranceOrder().Price | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a breaking change. |
||
| loss := slr.Indicator.Calculate(index).Div(openPrice).Sub(big.ONE) | ||
| if record.CurrentPosition().IsShort() { | ||
| loss = loss.Neg() | ||
| } | ||
| return loss.LTE(slr.tolerance) | ||
| } | ||
|
|
||
| // NewStopLossRule returns a new rule that is satisfied when the given loss tolerance (a percentage) is met or exceeded. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docs are wrong here and on the line below |
||
| // Loss tolerance should be a value between -1 and 1. | ||
| func NewStopGainRule(series *TimeSeries, gainTolerance float64) Rule { | ||
| return stopGainRule{ | ||
| Indicator: NewClosePriceIndicator(series), | ||
| tolerance: big.NewDecimal(gainTolerance), | ||
| } | ||
| } | ||
|
|
||
| func (sgr stopGainRule) IsSatisfied(index int, record *TradingRecord) bool { | ||
| if !record.CurrentPosition().IsOpen() { | ||
| return false | ||
| } | ||
| openPrice := record.CurrentPosition().EntranceOrder().Price | ||
| gain := sgr.Indicator.Calculate(index).Div(openPrice).Sub(big.ONE) | ||
| if record.CurrentPosition().IsShort() { | ||
| gain = gain.Neg() | ||
| } | ||
| return gain.GTE(sgr.tolerance) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is off here.