当前位置: 首页>>代码示例>>C++>>正文


C++ TA::BBANDS方法代码示例

本文整理汇总了C++中TA::BBANDS方法的典型用法代码示例。如果您正苦于以下问题:C++ TA::BBANDS方法的具体用法?C++ TA::BBANDS怎么用?C++ TA::BBANDS使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TA的用法示例。


在下文中一共展示了TA::BBANDS方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: run

void VIXTrader::run(void) throw(TraderException)
{
    TA ta;
    _invested_days = days(0);
    
    Series::EODSeries::const_iterator vix_iter(_vix_db.begin());
    advance(vix_iter, 100); // Skip first 100 bars to give enough room too BBANDS calculation
    for( ; vix_iter != _vix_db.end(); ++vix_iter ) {
        
        try {
            
            // Calculate current invested days
            if( ! _miPositions.open().empty() )
                _invested_days = _invested_days + days(1);
            
            // Calculate VIX BBANDS
            TA::BBRes resBBANDS3 = ta.BBANDS(_vix_db.close(vix_iter, 100), 100, 3, 3);
            TA::BBRes resBBANDS1 = ta.BBANDS(_vix_db.close(vix_iter, 100), 100, 1, 1);
            
            // Check buy signal
            if( _miPositions.open().empty() && vix_iter->second.close > resBBANDS3.upper_band[0] ) {
                // Buy tomorrow's close
                Series::EODSeries::const_iterator iter_entry = _spx_db.after(vix_iter->first);
                if( iter_entry == _spx_db.end() ) {
                    cerr << "Can't open position after " << vix_iter->first << endl;
                    continue;
                }
                
                buy(_spx_db.name(), iter_entry->first, Price(iter_entry->second.open));
            }
            
            // Check sell signal
            if( ! _miPositions.open().empty() && vix_iter->second.close < resBBANDS1.upper_band[0] ) {
                // Get next bar
                Series::EODSeries::const_iterator iter_exit = _spx_db.after(vix_iter->first);
                if( iter_exit == _spx_db.end() ) {
                    cerr << "Can't close position after " << vix_iter->first << endl;
                    continue;
                }
                
                // Close all open positions at tomorrow's close
                PositionSet ps = _miPositions.open();
                for( PositionSet::const_iterator pos_iter = ps.begin(); pos_iter != ps.end(); ++pos_iter ) {
                    PositionPtr pPos = (*pos_iter);
                    close(pPos->id(), iter_exit->first, Price(iter_exit->second.open));
                } // end of all open positions
            }
            
        } catch( std::exception& e ) {
            
            cerr << e.what() << endl;
            continue;
        }
        
    } // for each bar
}
开发者ID:ljw2602,项目名称:hudsonV2,代码行数:56,代码来源:VIXTrader.cpp


注:本文中的TA::BBANDS方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。