thetruetrade/gotrade · linreg.go
go logo
func (ind *LinRegWithoutStorage) ReceiveTick(tickData float64, streamBarIndex int) {
	ind.periodCounter += 1

	if ind.periodCounter >= 0 {
		sumXY := 0.0
		sumY := 0.0
		i := ind.timePeriod
		var value float64 = 0.0
		for e := ind.periodHistory.Front(); e != nil; e = e.Next() {
			i--
			value = e.Value.(float64)
			sumY += value
			sumXY += (float64(i) * value)
		}
		sumY += tickData
		timePeriod := float64(ind.timePeriod)
		m := (timePeriod*sumXY - ind.sumX*sumY) / ind.divisor
		b := (sumY - m*ind.sumX) / timePeriod
		result := b + m*float64(timePeriod-1.0)

		// increment the number of results this indicator can be expected to return
		ind.IncDataLength()

		// set the streamBarIndex from which this indicator returns valid results
		ind.SetValidFromBar(streamBarIndex)

		// notify of a new result value though the value available action
		ind.valueAvailableAction(result, m, b, streamBarIndex)
	}

	ind.periodHistory.PushBack(tickData)

	if ind.periodHistory.Len() >= ind.timePeriod {
		first := ind.periodHistory.Front()
		ind.periodHistory.Remove(first)
	}

}
Similar code snippets
1.
thetruetrade/gotrade · wma.go
Match rating: 67.28% · See similar code snippets
go logo
func (ind *WmaWithoutStorage) ReceiveTick(tickData float64, streamBarIndex int) {
	ind.periodCounter += 1

	ind.periodHistory.PushBack(tickData)

	if ind.periodCounter > 0 {

	}
	if ind.periodHistory.Len() > ind.timePeriod {
		var first = ind.periodHistory.Front()
		ind.periodHistory.Remove(first)
	}

	if ind.periodCounter >= 0 {
		// calculate the ind
		var iter int = 1
		var sum float64 = 0
		for e := ind.periodHistory.Front(); e != nil; e = e.Next() {
			var localSum float64 = 0
			for i := 1; i <= iter; i++ {
				localSum += e.Value.(float64)
			}
			sum += localSum
			iter++
		}
		var result float64 = sum / float64(ind.periodWeightTotal)

		ind.UpdateIndicatorWithNewValue(result, streamBarIndex)
	}
}
2.
thetruetrade/gotrade · sma.go
Match rating: 59.86% · See similar code snippets
go logo
func (ind *SmaWithoutStorage) ReceiveTick(tickData float64, streamBarIndex int) {
	ind.periodCounter += 1
	ind.periodHistory.PushBack(tickData)

	if ind.periodCounter > 0 {
		var valueToRemove = ind.periodHistory.Front()
		ind.periodTotal -= valueToRemove.Value.(float64)
	}
	if ind.periodHistory.Len() > ind.timePeriod {
		var first = ind.periodHistory.Front()
		ind.periodHistory.Remove(first)
	}
	ind.periodTotal += tickData
	var result float64 = ind.periodTotal / float64(ind.timePeriod)
	if ind.periodCounter >= 0 {

		ind.UpdateIndicatorWithNewValue(result, streamBarIndex)
	}
}
3.
thetruetrade/gotrade · ema.go
Match rating: 59.0% · See similar code snippets
go logo
func (ind *EmaWithoutStorage) ReceiveTick(tickData float64, streamBarIndex int) {
	ind.periodCounter += 1
	if ind.periodCounter < 0 {
		ind.periodTotal += tickData
	} else if ind.periodCounter == 0 {

		ind.periodTotal += tickData
		result := ind.periodTotal / float64(ind.timePeriod)
		ind.previousEma = result

		ind.UpdateIndicatorWithNewValue(result, streamBarIndex)

	} else if ind.periodCounter > 0 {

		result := (tickData-ind.previousEma)*ind.multiplier + ind.previousEma
		ind.previousEma = result

		ind.UpdateIndicatorWithNewValue(result, streamBarIndex)
	}
}
4.
thetruetrade/gotrade · rocr.go
Match rating: 58.72% · See similar code snippets
go logo
func (ind *RocRWithoutStorage) ReceiveTick(tickData float64, streamBarIndex int) {
	ind.periodCounter += 1
	ind.periodHistory.PushBack(tickData)

	if ind.periodCounter > 0 {

		//    RocR = (price/previousPrice - 1) * 100
		previousPrice := ind.periodHistory.Front().Value.(float64)

		var result float64
		if previousPrice != 0 {
			result = (tickData / previousPrice)
		} else {
			result = 0.0
		}

		ind.UpdateIndicatorWithNewValue(result, streamBarIndex)
	}

	if ind.periodHistory.Len() > ind.timePeriod {
		first := ind.periodHistory.Front()
		ind.periodHistory.Remove(first)
	}
}
5.
thetruetrade/gotrade · var.go
Match rating: 56.54% · See similar code snippets
go logo
func (ind *VarWithoutStorage) ReceiveTick(tickData float64, streamBarIndex int) {
	ind.periodHistory.PushBack(tickData)
	firstValue := ind.periodHistory.Front().Value.(float64)

	previousMean := ind.mean
	previousVar := ind.variance

	if ind.periodCounter < ind.timePeriod {
		ind.periodCounter += 1
		delta := tickData - previousMean
		ind.mean = previousMean + delta/float64(ind.periodCounter)

		ind.variance = previousVar + delta*(tickData-ind.mean)
	} else {
		delta := tickData - firstValue
		dOld := firstValue - previousMean
		ind.mean = previousMean + delta/float64(ind.periodCounter)
		dNew := tickData - ind.mean
		ind.variance = previousVar + (dOld+dNew)*(delta)
	}

	if ind.periodHistory.Len() > ind.timePeriod {
		first := ind.periodHistory.Front()
		ind.periodHistory.Remove(first)
	}

	if ind.periodCounter >= ind.timePeriod {

		result := ind.variance / float64(ind.timePeriod)

		ind.UpdateIndicatorWithNewValue(result, streamBarIndex)
	}
}
6.
thetruetrade/gotrade · hhvbars.go
Match rating: 56.23% · See similar code snippets
go logo
func (ind *HhvBarsWithoutStorage) ReceiveTick(tickData float64, streamBarIndex int) {
	ind.periodHistory.PushBack(tickData)

	// resize the history
	if ind.periodHistory.Len() > ind.timePeriod {
		first := ind.periodHistory.Front()
		ind.periodHistory.Remove(first)

		// make sure we haven't just removed the current high
		if ind.currentHighIndex == int64(ind.timePeriod-1) {
			ind.currentHigh = math.SmallestNonzeroFloat64
			// we have we need to find the new high in the history
			var i int = ind.timePeriod - 1
			for e := ind.periodHistory.Front(); e != nil; e = e.Next() {
				value := e.Value.(float64)
				if value > ind.currentHigh {
					ind.currentHigh = value
					ind.currentHighIndex = int64(i)
				}
				i -= 1
			}
		} else {
			if tickData > ind.currentHigh {
				ind.currentHigh = tickData
				ind.currentHighIndex = 0
			} else {
				ind.currentHighIndex += 1
			}
		}

		var result = ind.currentHighIndex

		ind.UpdateIndicatorWithNewValue(result, streamBarIndex)

	} else {
		if tickData > ind.currentHigh {
			ind.currentHigh = tickData
			ind.currentHighIndex = 0
		} else {
			ind.currentHighIndex += 1
		}

		if ind.periodHistory.Len() == ind.timePeriod {
			var result = ind.currentHighIndex

			ind.UpdateIndicatorWithNewValue(result, streamBarIndex)
		}
	}

}
7.
gizak/termui · utils.go
Match rating: 53.8% · See similar code snippets
go logo
func SumFloat64Slice(data []float64) float64 {
	sum := 0.0
	for _, v := range data {
		sum += v
	}
	return sum
}
8.
thetruetrade/gotrade · minusdm.go
Match rating: 53.75% · See similar code snippets
go logo
func (ind *MinusDmWithoutStorage) ReceiveDOHLCVTick(tickData gotrade.DOHLCV, streamBarIndex int) {
	ind.periodCounter += 1
	high := tickData.H()
	low := tickData.L()
	diffP := high - ind.previousHigh
	diffM := ind.previousLow - low

	if ind.lookbackPeriod == 1 {
		if ind.periodCounter > 0 {

			var result float64
			if (diffM > 0) && (diffP < diffM) {
				result = diffM
			} else {
				result = 0
			}

			ind.UpdateIndicatorWithNewValue(result, streamBarIndex)
		}
	} else {
		if ind.periodCounter > 0 {
			if ind.periodCounter < ind.timePeriod {
				if (diffM > 0) && (diffP < diffM) {
					ind.previousMinusDm += diffM
				}

				if ind.periodCounter == ind.timePeriod-1 {

					result := ind.previousMinusDm

					ind.UpdateIndicatorWithNewValue(result, streamBarIndex)

				}
			} else {
				var result float64
				if (diffM > 0) && (diffP < diffM) {
					result = ind.previousMinusDm - (ind.previousMinusDm / float64(ind.timePeriod)) + diffM
				} else {
					result = ind.previousMinusDm - (ind.previousMinusDm / float64(ind.timePeriod))
				}

				ind.UpdateIndicatorWithNewValue(result, streamBarIndex)

				ind.previousMinusDm = result
			}
		}
	}

	ind.previousHigh = high
	ind.previousLow = low
}
9.
thetruetrade/gotrade · aroon.go
Match rating: 52.87% · See similar code snippets
go logo
func (ind *AroonWithoutStorage) ReceiveDOHLCVTick(tickData gotrade.DOHLCV, streamBarIndex int) {
	ind.periodCounter += 1
	ind.periodHighHistory.PushBack(tickData.H())
	ind.periodLowHistory.PushBack(tickData.L())

	if ind.periodHighHistory.Len() > (1 + ind.GetLookbackPeriod()) {
		var first = ind.periodHighHistory.Front()
		ind.periodHighHistory.Remove(first)
		first = ind.periodLowHistory.Front()
		ind.periodLowHistory.Remove(first)
	}

	if ind.periodCounter >= 0 {
		var aroonUp float64
		var aroonDwn float64

		var highValue float64 = math.SmallestNonzeroFloat64
		var highIdx int = -1
		var i int = (1 + ind.GetLookbackPeriod())
		for e := ind.periodHighHistory.Front(); e != nil; e = e.Next() {
			i--
			var value float64 = e.Value.(float64)
			if highValue <= value {
				highValue = value
				highIdx = i
			}
		}
		var daysSinceHigh = highIdx

		var lowValue float64 = math.MaxFloat64
		var lowIdx int = -1
		i = (1 + ind.GetLookbackPeriod())
		for e := ind.periodLowHistory.Front(); e != nil; e = e.Next() {
			i--
			var value float64 = e.Value.(float64)
			if lowValue >= value {
				lowValue = value
				lowIdx = i
			}

		}
		var daysSinceLow = lowIdx

		aroonUp = ind.aroonFactor * float64(ind.GetLookbackPeriod()-daysSinceHigh)
		aroonDwn = ind.aroonFactor * float64(ind.GetLookbackPeriod()-daysSinceLow)

		ind.UpdateIndicatorWithNewValue(aroonUp, aroonDwn, streamBarIndex)
	}
}
10.
GaryBoone/GoStats · stats.go
Match rating: 52.79% · See similar code snippets
go logo
func StatsSum(data []float64) (sum float64) {
	for _, v := range data {
		sum += v
	}
	return
}