示例#1
0
def calculate_columns(indicator_client: Indicators, owned: bool, trading_symbol: str,
                      bot_account: dict):
	"""Sets buy/sell/hold signals for the conf_val strategy"""

	indicator_client.ema(period=20, column_name='ema_20').dropna(inplace=True)
	indicator_client.ema(period=200, column_name='ema_200').dropna(inplace=True)
	indicator_client.rsi(period=14).dropna(inplace=True)
	indicator_client.macd().dropna(inplace=True)  # Defaults to fast: 12, slow: 26, column_name: macd

	# Calculate the current % gap between the open and current ema_20
	#  This will be used to prevent a buy signal from happening if the open just barely
	#  goes over the ema_20.
	v1 = indicator_client.price_data_frame['open']
	v2 = indicator_client.price_data_frame['ema_20']
	v3 = indicator_client.price_data_frame['ema_200']
	indicator_client.price_data_frame['open_ema_20_percent_diff'] = \
		((v1 - v2) / abs(v2)) * 100
	indicator_client.price_data_frame['ema_20_ema_200_percent_diff'] = \
		((v2 - v3) / abs(v3)) * 100
	indicator_client.price_data_frame['signals'] = indicator_client.price_data_frame.apply(lambda row: calc_sig(row, owned), axis=1)
	print("break")
示例#2
0
indicator_client.ema(period=50)

# Add the Bollinger Bands.
indicator_client.bollinger_bands(period=20)

# Add the Rate of Change.
indicator_client.rate_of_change(period=1)

# Add the Average True Range.
indicator_client.average_true_range(period=14)

# Add the Stochastic Oscillator.
indicator_client.stochastic_oscillator()

# Add the MACD.
indicator_client.macd(fast_period=12, slow_period=26)

# Add the Mass Index.
indicator_client.mass_index(period=9)

while True:

    # Grab the latest bar.
    latest_bars = trading_robot.get_latest_bar()

    # Add to the Stock Frame.
    stock_frame.add_rows(data=latest_bars)

    # Refresh the Indicators.
    indicator_client.refresh()