sTrading

package
v0.6.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Side_Buy     = Side(1)
	Side_Sell    = Side(-1)
	Side_DEFAULT = Side(0)
)
View Source
const (
	State_Win         = State(1)
	State_Loss        = State(-1)
	State_InTrade     = State(2)
	State_CloseTs     = State(3) // CloseTs: Max In Trade Time permitted from Entry
	State_CancelTs    = State(4) // CancelTs: Max Excursion Time permitted from Trigger
	State_CancelPrice = State(5) // CancelPrice: Max Favorable Excursion permitted from Entry
	State_NotEntry    = State(6) // NotEntry: Never reached Entry Price
	State_BrakeEven   = State(7) // BrakeEven: Never reached Brake Even Price
	State_DEFAULT     = State(0)
)

Variables

This section is empty.

Functions

func CalcOrderPrices

func CalcOrderPrices(priceFrom, priceTo, stepPercentage, profitPercentage, stopLossPercentage float64) (pricesIn, pricesOut []float64)

func CalcOrderPricesSizes

func CalcOrderPricesSizes(priceFrom, priceTo, stepPercentage, profitPercentage, stopLossPercentage, balance, sizeStepPercentage float64, weighted, unifiedProfit bool) (pricesIn, pricesOut, sizes []float64, stopLoss float64)

func CalcOrderSizes

func CalcOrderSizes(pricesIn []float64, balance float64) (sizes []float64)

func CalcOrderSizesStep

func CalcOrderSizesStep(pricesIn []float64, balance, step float64) (sizes []float64)

func CalcOrderSizesWeighted

func CalcOrderSizesWeighted(pricesIn []float64, balance float64) (sizes []float64)

func CalcProfitAndLoss

func CalcProfitAndLoss(pricesIn, pricesOut, sizes []float64, side Side) (totalReturn float64, slice []float64)

func CalcProfitOut

func CalcProfitOut(pricesIn, sizes []float64, stopLossPercentage, balance float64) (pricesOut []float64)

func CalcStopLossOut

func CalcStopLossOut(pricesIn, sizes []float64, stopLossPercentage, balance float64) float64

func TakeProfitStoploss added in v0.3.5

func TakeProfitStoploss(entry_price, take_profit_perc, stop_loss_perc float64, side Side) (take_profit, stop_loss float64)

TakeProfitStoploss: returns take_profit and stop_loss prices

Types

type BacktestPositions added in v0.3.4

type BacktestPositions struct {
	Positions Positions `bson:"positions" json:"positions"`
}

func (BacktestPositions) Export added in v0.3.4

func (bp BacktestPositions) Export(file_path string) error

The file_path is the path to the file where the positions will be exported. The file will be deleted if it exists.

type Position added in v0.3.4

type Position struct {
	Side       int     `bson:"type" json:"type"` // 0 - Long / 1 - Short
	EntryPrice float64 `bson:"entryPrice" json:"entryPrice"`
	EntryTs    int64   `bson:"entryTS" json:"entryTS"`
	ExitTs     int64   `bson:"exitTS" json:"exitTS"`
	TakeProfit float64 `bson:"tp" json:"tp"`
	StopLoss   float64 `bson:"sl" json:"sl"`
}

type Positions added in v0.3.4

type Positions []*Position

type Side added in v0.3.4

type Side int

func GetSide

func GetSide(s string) Side

func (Side) IsBuy added in v0.3.4

func (s Side) IsBuy() bool

func (Side) IsSell added in v0.3.4

func (s Side) IsSell() bool

func (Side) Log added in v0.3.4

func (s Side) Log() string

func (Side) LogPosition added in v0.3.4

func (s Side) LogPosition() string

func (Side) Position added in v0.3.4

func (s Side) Position() string

func (Side) PositionSide added in v0.3.5

func (s Side) PositionSide() int

func (Side) String added in v0.3.4

func (s Side) String() string

type State added in v0.3.4

type State int

func GetState added in v0.3.4

func GetState(s string) State

func (State) Log added in v0.3.4

func (s State) Log() string

func (State) String added in v0.3.4

func (s State) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL