當前位置: 首頁>>代碼示例>>Python>>正文


Python talib.MA屬性代碼示例

本文整理匯總了Python中talib.MA屬性的典型用法代碼示例。如果您正苦於以下問題:Python talib.MA屬性的具體用法?Python talib.MA怎麽用?Python talib.MA使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在talib的用法示例。


在下文中一共展示了talib.MA屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: reinit

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MA [as 別名]
def reinit(self,pingzhongname,filename,dailyresultname,jsonname):
        """更換品種,重新初始化"""
        # K線界麵
        ui.loadKLineSetting(jsonname)
        ui.KLtitle.setText(pingzhongname+'   '+ui.StrategyName ,size='10pt',color='FFFF00')
        ui.loadData(pd.DataFrame.from_csv(filename))
        ui.loadData_listsig(pd.DataFrame.from_csv(dailyresultname))
        # 初始化界麵顯示
        self.SHORT_TERM_SHOW_ALL =False
        self.SHORT_TERM_SHOW_FIRST =False
        self.SHORT_TERM_SHOW_LIMIT =False
        ui.initIndicator(u'MA SHORT')
        ui.initIndicator(u'MA LONG')
        ui.initIndicator(u'KLINE')
        ui.initIndicator(u'SHORT TERM(First)')
        ui.initIndicator(u'SHORT TERM(All)')
        ui.initIndicator(u'SHORT TERM(Limit)')
        if ui.signal_show == True :
            ui.initIndicator(u'信號顯示')
        else:
            ui.initIndicator(u'信號隱藏')
        ui.refreshAll()
    #----------------------------------------------------------------------
    #  畫圖相關 
    #---------------------------------------------------------------------- 
開發者ID:rjj510,項目名稱:uiKLine,代碼行數:27,代碼來源:uiKLine.py

示例2: handle_data

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MA [as 別名]
def handle_data(context):
    if len(Close()) < p2:
        return
    
    # 使用talib計算均價
    ma1 = talib.MA(Close(), p1)
    ma2 = talib.MA(Close(), p2) 

    # 執行下單操作
    if MarketPosition() <= 0 and ma1[-1] > ma2[-1]:
        Buy(1, Close()[-1])
    if MarketPosition() >= 0 and ma1[-1] < ma2[-1]:
        SellShort(1, Close()[-1])
    
    # 繪製指標圖形
    PlotNumeric("ma1", ma1[-1], RGB_Red())
    PlotNumeric("ma2", ma2[-1], RGB_Green())    
    PlotNumeric("fit", NetProfit() + FloatProfit() - TradeCost(), RGB_Red(), False) 
開發者ID:epolestar,項目名稱:equant,代碼行數:20,代碼來源:DualMA.py

示例3: getAtrRatio

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MA [as 別名]
def getAtrRatio(df, period=14):
        """
            平均波動率:ATR(14)/MA(14)
        """
        highs = df['high']
        lows = df['low']
        closes = df['close']

        atr = talib.ATR(highs, lows, closes, timeperiod=period)
        ma = talib.MA(closes, timeperiod=period)

        volatility = atr/ma

        s = pd.Series(volatility, index=df.index, name='volatility').dropna()

        return s 
開發者ID:moyuanz,項目名稱:DevilYuan,代碼行數:18,代碼來源:DyStockDataUtility.py

示例4: _getAtrExtreme

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MA [as 別名]
def _getAtrExtreme(cls, highs, lows, closes, atrPeriod=14, slowPeriod=30, fastPeriod=3):
        """
            獲取TTI ATR Exterme通道, which is based on 《Volatility-Based Technical Analysis》
            TTI is 'Trading The Invisible'

            @return: fasts, slows
        """
        # talib 的源碼,它的 ATR 不是 N 日簡單平均,而是類似 EMA 的方法計算的指數平均
        atr = talib.ATR(highs, lows, closes, timeperiod=atrPeriod)

        highsMean = talib.EMA(highs, 5)
        lowsMean = talib.EMA(lows, 5)
        closesMean = talib.EMA(closes, 5)

        atrExtremes = np.where(closes > closesMean,
                               ((highs - highsMean)/closes * 100) * (atr/closes * 100),
                               ((lows - lowsMean)/closes * 100) * (atr/closes * 100)
                               )

        fasts = talib.MA(atrExtremes, fastPeriod)
        slows = talib.EMA(atrExtremes, slowPeriod)

        return fasts, slows, np.std(atrExtremes[-slowPeriod:]) 
開發者ID:moyuanz,項目名稱:DevilYuan,代碼行數:25,代碼來源:DyST_IntraDayT.py

示例5: ma30_cross

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MA [as 別名]
def ma30_cross(data):
        MA5 = talib.MA(data.close, 5)
        MA30 = talib.MA(data.close, 30)
    
        MA30_CROSS_JX = CROSS(MA5, MA30)
        MA30_CROSS_JX_Integral = Timeline_Integral_with_cross_before(MA30_CROSS_JX)
        MA30_CROSS_SX = CROSS(MA30, MA5)
        MA30_CROSS_SX_Integral = Timeline_Integral_with_cross_before(MA30_CROSS_SX)
    
        MA30_CROSS = pd.DataFrame(columns=['MA30_CROSS', 'MA30_CROSS_JX', 'MA30_CROSS_SX', 'MA30_TP_CROSS_JX', 'MA30_TP_CROSS_SX'], index=data.index)
        MA30_CROSS.loc[MA30_CROSS_JX == 1, 'MA30_CROSS'] = 1
        MA30_CROSS.loc[MA30_CROSS_SX == 1, 'MA30_CROSS'] = -1
        MA30_CROSS['MA30_CROSS_JX'] = Timeline_Integral_with_cross_before(MA30_CROSS_JX)
        MA30_CROSS['MA30_CROSS_SX'] = Timeline_Integral_with_cross_before(MA30_CROSS_SX)
    
        # MA30 前29個是 NaN,處理會拋出 Warning,使用 [29:] 則不會計算 NaN,相應的 return_index+29
        MA30_tp_min, MA30_tp_max = signal.argrelextrema(MA30.values[29:], np.less)[0] + 29, signal.argrelextrema(MA30.values[29:], np.greater)[0] + 29
        MA30_TP_CROSS = pd.DataFrame(columns=['MA30_TP_CROSS_JX', 'MA30_TP_CROSS_SX'], index=data.index)
        MA30_TP_CROSS['MA30_TP_CROSS_SX'] = MA30_TP_CROSS['MA30_TP_CROSS_JX'] = 0
        MA30_TP_CROSS.iloc[MA30_tp_min, MA30_TP_CROSS.columns.get_loc('MA30_TP_CROSS_JX')] = 1
        MA30_TP_CROSS.iloc[MA30_tp_max, MA30_TP_CROSS.columns.get_loc('MA30_TP_CROSS_SX')] = 1
        MA30_CROSS['MA30_TP_CROSS_JX'] = Timeline_Integral_with_cross_before(MA30_TP_CROSS['MA30_TP_CROSS_JX'])
        MA30_CROSS['MA30_TP_CROSS_SX'] = Timeline_Integral_with_cross_before(MA30_TP_CROSS['MA30_TP_CROSS_SX'])
        return MA30_CROSS 
開發者ID:QUANTAXIS,項目名稱:QUANTAXIS,代碼行數:26,代碼來源:QAQuery_Advance_Test.py

示例6: zscore

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MA [as 別名]
def zscore(candles: np.ndarray, period=14, matype=0, nbdev=1, source_type="close", sequential=False) -> Union[
    float, np.ndarray]:
    """
    zScore

    :param candles: np.ndarray
    :param period: int - default: 14
    :param matype: int - default: 0
    :param nbdev: int - default: 1
    :param source_type: str - default: "close"
    :param sequential: bool - default=False

    :return: float | np.ndarray
    """
    if not sequential and len(candles) > 240:
        candles = candles[-240:]

    source = get_candle_source(candles, source_type=source_type)
    means = talib.MA(source, timeperiod=period, matype=matype)
    sigmas = talib.STDDEV(source, timeperiod=period, nbdev=nbdev)
    zScores = (source - means) / sigmas

    return zScores if sequential else zScores[-1] 
開發者ID:jesse-ai,項目名稱:jesse,代碼行數:25,代碼來源:zscore.py

示例7: handle_data

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MA [as 別名]
def handle_data(context):
    if len(Close()) < p2:
        return;
        
    ma1 = talib.MA(Close(), p1)
    ma2 = talib.MA(Close(), p2)  
    
    his = BarStatus() != 2
    if his:
        his_trigger(ma1, ma2) 
    else: 
        tim_trigger(ma1, ma2) 
    
    PlotNumeric("ma1", ma1[-1], 0xFF0000)
    PlotNumeric("ma2", ma2[-1], 0x00aa00) 
    fit = NetProfit() + FloatProfit() - TradeCost() if his else A_CoverProfit() + A_ProfitLoss() - A_Cost()
    PlotNumeric("fit", fit, 0x0000FF, False) 
開發者ID:epolestar,項目名稱:equant,代碼行數:19,代碼來源:DMA.py

示例8: _calc_ma_from_ta

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MA [as 別名]
def _calc_ma_from_ta(prices, time_period=10, from_calc=EMACalcType.E_MA_MA):
    """
    使用talib計算ma,即透傳talib.MA or talib.EMA計算結果
    :param prices: 收盤價格序列,pd.Series或者np.array
    :param time_period: 移動平均的N值,int
    :param from_calc: EMACalcType enum對象,移動移動平均使用的方法
    """

    import talib
    if isinstance(prices, pd.Series):
        prices = prices.values

    if from_calc == EMACalcType.E_MA_MA:
        ma = talib.MA(prices, timeperiod=time_period)
    else:
        ma = talib.EMA(prices, timeperiod=time_period)
    return ma 
開發者ID:bbfamily,項目名稱:abu,代碼行數:19,代碼來源:ABuNDMa.py

示例9: CCI

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MA [as 別名]
def CCI(self, period: int, bars: list):
        """
        Return CCI (Commodity Chanel Index) for n bars close price.
​
        CCI = (Typical Price − MA) / 0.015 * Mean Deviation

        where:
            Typical Price = ∑P((H + L + C) / 3))
            P = number of bars (period)
            MA = Moving Average = (∑P Typical Price) / P
            Mean Deviation=(∑P | Typical Price - MA |) / P
        """

        self.check_bars_type(bars)

        cci = ta.CCI(
            bars['high'], bars['low'], bars['close'], timeperiod=period)

        return cci 
開發者ID:s-brez,項目名稱:trading-server,代碼行數:21,代碼來源:features.py

示例10: getRuntimeMa

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MA [as 別名]
def getRuntimeMa(self, ma_num):
        """
        實時計算MA得值
        :param ma_num:第幾條均線, 1,對應inputMa1Len,,,,
        :return:
        """
        if ma_num not in [1, 2, 3]:
            return None

        ma_len = 1
        if ma_num == 1 and self.inputMa1Len > 0:
            ma_len = self.inputMa1Len
        elif ma_num == 2 and self.inputMa2Len > 0:
            ma_len = self.inputMa2Len
        elif ma_num == 3 and self.inputMa3Len > 0:
            ma_len = self.inputMa3Len
        else:
            return None
        ma_data_len = ma_len + 2

        if len(self.lineBar) < ma_data_len:
            self.debugCtaLog(u'數據未充分,當前Bar數據數量:{},計算實時MA {} 需要:{}'.
                             format(len(self.lineBar), ma_len, ma_data_len))
            return None

        # 3、獲取前InputN周期(不包含當前周期)的K線
        listClose = [x.close for x in self.lineBar[-ma_data_len:]]
        barMa = ta.MA(np.array(listClose, dtype=float), ma_len)[-1]
        barMa = round(float(barMa), self.round_n)

        return barMa

    #---------------------------------------------------------------------- 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:35,代碼來源:ctaLineBar.py

示例11: onBarRatio

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MA [as 別名]
def onBarRatio(self, bar):
        """比率線的OnBar事件"""
        # 獲取比率線的長度
        l = len(self.lineRatio.lineStateMean)
        if l > 0:
            ma = self.lineRatio.lineStateMean[-1]
        else:
            ma = bar.close

        if l > 6:
            listKf = [x for x in self.lineRatio.lineStateMean[-7:-1]]
            # MA():?
            # numpy.array(listKf, dtype = float:轉浮點型
            malist = ta.MA(numpy.array(listKf, dtype=float), 5)
            ma5 = malist[-1]
            ma5_ref1 = malist[-2]
            if ma5 <= 0 or ma5_ref1 <= 0:
                self.writeCtaLog(u'卡爾曼均線異常')
                return
            # ?
            self.m1_atan = math.atan((ma5 / ma5_ref1 - 1) * 100 * 180 / math.pi)
        # M1的切線隊列長度 > 10
        if len(self.m1_atan_list) > 10:
            del self.m1_atan_list[0]
        # m1_atan_list加入m1_atan
        self.m1_atan_list.append(self.m1_atan)
        # displayLastBar()顯示最後一個Bar的信息
        self.writeCtaLog(self.lineRatio.displayLastBar())

    # 殘差線更新 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:32,代碼來源:CrossMarketSpotArbitrageStrategy.py

示例12: ifup20_TA

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MA [as 別名]
def ifup20_TA(data):
        # TA-lib計算
        return (talib.MA(data.close, 5) - talib.MA(data.close, 20)).dropna() > 0

    # 寫個自定義指標 MAX_FACTOR TA-lib計算 
開發者ID:QUANTAXIS,項目名稱:QUANTAXIS,代碼行數:7,代碼來源:QAQuery_Advance_Test.py

示例13: boll_cross

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MA [as 別名]
def boll_cross(data):
        BBANDS = QA.TA_BBANDS(data.close, timeperiod=20, nbdevup=2)

        BOLL_CROSS = pd.DataFrame(columns=['min_peak', 'max_peak', 'BOLL_CROSS', 'BOLL_CROSS_JX', 'BOLL_CROSS_SX'], index=data.index)
        
        # 防止插針行情突然搞亂
        data['smooth_low'] = talib.MA(data.low, 2)
        data['smooth_high'] = talib.MA(data.high, 2)

        BOLL_CROSS['min_peak'] = data.apply(lambda x: min(x['open'], x['close'], x['smooth_low']), axis=1)
        BOLL_CROSS['max_peak'] = data.apply(lambda x: max(x['open'], x['close'], x['smooth_high']), axis=1)

        BOLL_CROSS_JX = CROSS(BOLL_CROSS['min_peak'], BBANDS[:,2])
        BOLL_CROSS_SX = CROSS(BBANDS[:,0], BOLL_CROSS['max_peak'])

        BOLL_CROSS.loc[BOLL_CROSS_JX == 1, 'BOLL_CROSS'] = 1
        BOLL_CROSS.loc[BOLL_CROSS_SX == 1, 'BOLL_CROSS'] = -1
        BOLL_TP_CROSS = pd.DataFrame(columns=['BOLL_TP_CROSS_JX', 'BOLL_TP_CROSS_SX'], index=data.index)
        BOLL_TP_CROSS['BOLL_TP_CROSS_SX'] = BOLL_TP_CROSS['BOLL_TP_CROSS_JX'] = 0
        BOLL_TP_CROSS.loc[BOLL_CROSS_JX == 1, 'BOLL_TP_CROSS_JX'] = 1
        BOLL_TP_CROSS.loc[BOLL_CROSS_SX == 1, 'BOLL_TP_CROSS_SX'] = 1

        BOLL_CROSS = BOLL_CROSS.assign(BOLL_UB=BBANDS[:,0])
        BOLL_CROSS = BOLL_CROSS.assign(BOLL_MA=BBANDS[:,1])
        BOLL_CROSS = BOLL_CROSS.assign(BOLL_LB=BBANDS[:,2])
        BOLL_CROSS['BOLL_CROSS_JX'] = QA.Timeline_Integral_with_cross_before(BOLL_TP_CROSS['BOLL_TP_CROSS_JX'])
        BOLL_CROSS['BOLL_CROSS_SX'] = QA.Timeline_Integral_with_cross_before(BOLL_TP_CROSS['BOLL_TP_CROSS_SX'])
        return BOLL_CROSS 
開發者ID:QUANTAXIS,項目名稱:QUANTAXIS,代碼行數:30,代碼來源:QAQuery_Advance_Test.py

示例14: boll_cross_lf

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MA [as 別名]
def boll_cross_lf(data):
        BBANDS = QA.TA_BBANDS(data.close, timeperiod=20, nbdevup=2)

        BOLL_CROSS_JX1 = CROSS(data.open, BBANDS[:,2])
        BOLL_CROSS_JX2 = CROSS(data.close, BBANDS[:,2])
        BOLL_CROSS_JX3 = CROSS(talib.MA(data.low, 2), BBANDS[:,2])
        BOLL_CROSS_SX1 = CROSS(BBANDS[:,0], data.open)
        BOLL_CROSS_SX2 = CROSS(BBANDS[:,0], data.close)
        BOLL_CROSS_SX3 = CROSS(BBANDS[:,0], talib.MA(data.high, 2))

        BOLL_CROSS = pd.DataFrame(columns=['BOLL_CROSS', 'BOLL_CROSS_JX', 'BOLL_CROSS_SX'], index=data.index)
        BOLL_CROSS.loc[BOLL_CROSS_JX1 == 1, 'BOLL_CROSS'] = 1
        BOLL_CROSS.loc[BOLL_CROSS_JX2 == 1, 'BOLL_CROSS'] = 1
        BOLL_CROSS.loc[BOLL_CROSS_JX3 == 1, 'BOLL_CROSS'] = 1
        BOLL_CROSS.loc[BOLL_CROSS_SX1 == 1, 'BOLL_CROSS'] = -1
        BOLL_CROSS.loc[BOLL_CROSS_SX2 == 1, 'BOLL_CROSS'] = -1
        BOLL_CROSS.loc[BOLL_CROSS_SX3 == 1, 'BOLL_CROSS'] = -1
        BOLL_TP_CROSS = pd.DataFrame(columns=['BOLL_TP_CROSS_JX', 'BOLL_TP_CROSS_SX'], index=data.index)
        BOLL_TP_CROSS['BOLL_TP_CROSS_SX'] = BOLL_TP_CROSS['BOLL_TP_CROSS_JX'] = 0
        BOLL_TP_CROSS.loc[(BOLL_CROSS_JX1 | BOLL_CROSS_JX2 | BOLL_CROSS_JX3) == 1, 'BOLL_TP_CROSS_JX'] = 1
        BOLL_TP_CROSS.loc[(BOLL_CROSS_SX1 | BOLL_CROSS_SX2 | BOLL_CROSS_SX3) == 1, 'BOLL_TP_CROSS_SX'] = 1

        BOLL_CROSS = BOLL_CROSS.assign(BOLL_UB=BBANDS[:,0])
        BOLL_CROSS = BOLL_CROSS.assign(BOLL_MA=BBANDS[:,1])
        BOLL_CROSS = BOLL_CROSS.assign(BOLL_LB=BBANDS[:,2])
        BOLL_CROSS['BOLL_CROSS_JX'] = QA.Timeline_Integral_with_cross_before(BOLL_TP_CROSS['BOLL_TP_CROSS_JX'])
        BOLL_CROSS['BOLL_CROSS_SX'] = QA.Timeline_Integral_with_cross_before(BOLL_TP_CROSS['BOLL_TP_CROSS_SX'])
        return BOLL_CROSS 
開發者ID:QUANTAXIS,項目名稱:QUANTAXIS,代碼行數:30,代碼來源:QAQuery_Advance_Test.py

示例15: QSDD

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MA [as 別名]
def QSDD(dataframe, SHORT=12, LONG=26, M=9):
    """
    1.line_mid向上突破line_long,買入信號參考。
    2.line_mid向下跌破line_long,賣出信號參考。
    """
    OPEN = dataframe.open
    HIGH = dataframe.high
    LOW = dataframe.low
    CLOSE = dataframe.close

    # QSDD策略
    # A = talib.MA(-100 * (talib.MAX(HIGH, 34) - CLOSE) / (talib.MAX(HIGH, 34) - talib.MIN(LOW, 34)), 19)
    # B = -100 * (talib.MAX(HIGH, 14) - CLOSE) / (talib.MAX(HIGH, 14) - talib.MIN(LOW, 14))
    # D = talib.EMA(-100 * (talib.MAX(HIGH, 34) - CLOSE) / (talib.MAX(HIGH, 34) - talib.MIN(LOW, 34)), 4)
    A = QA.MA(-100 * (QA.HHV(HIGH, 34) - CLOSE) /
              (QA.HHV(HIGH, 34) - QA.LLV(LOW, 34)), 19)
    B = -100 * (QA.HHV(HIGH, 14) - CLOSE) / \
        (QA.HHV(HIGH, 14) - QA.LLV(LOW, 14))
    D = QA.EMA(-100 * (QA.HHV(HIGH, 34) - CLOSE) /
               (QA.HHV(HIGH, 34) - QA.LLV(LOW, 34)), 4)

    line_long = A + 100
    line_short = B + 100
    line_mid = D + 100  # 信號線

    CROSS_JC = QA.CROSS(line_mid, line_long)
    CROSS_SC = QA.CROSS(line_long, line_mid)
    return pd.DataFrame({'line_mid': line_mid, 'line_long': line_long, 'CROSS_JC': CROSS_JC, 'CROSS_SC': CROSS_SC})


# create account 
開發者ID:QUANTAXIS,項目名稱:QUANTAXIS,代碼行數:33,代碼來源:strategy_qsdd.py


注:本文中的talib.MA屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。