今日分享的範例是去年寬大分享於 COCO研究院 中的一篇熱門文章,小弟當時參考寬大分享之概念及程式碼做了些許微調再回饋於該文中。為豐富版內 AmiBroker 的內容,經取得寬大的同意後,將此程式碼轉載至本版,與各位 AmiBroker 同好分享,參考看看囉 ~

↓ 圖例

 

原文出處 [小分享]一次給您滿滿的無大師 有興趣更深入了解討論歷程的網友可以前往拜讀,小弟此範例原分享於 #93 樓中。

若對這個指標有興趣,想更深入的了解其應用方式可以至 COCO研究院 中爬爬無前輩分享的 程式交易首步曲---統計機率 討論列,應該會有不少收穫。

 

↓ 程式碼

//
// 圖形標題設定
//
SetChartOptions( 0, chartShowArrows | chartShowDates | chartWrapTitle );
_N(  Title = StrFormat( "{{NAME}} - {{DATE}}   開 %g,   高 %g,   低 %g,   收 %g,  帳跌幅(%.1f%%)", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Title = Title + "    [ C.A.B.E. 程式範例 - _CABE_Demo_002(滿滿的無大師) ]\n{{VALUES}}";
//
// 計算日K週期的基準線
//
TimeFrameSet( inDaily );
_Equator      = round( ( ( High + Low ) / 2 ) + ( Ref( Open, 1 ) - Close ) );
_ToDayHighest = Ref( High, 1 );
_ToDayLowest  = Ref( Low, 1 );
TimeFrameRestore();
// 計算日K當日基準線
_DailyEquator      = TimeFrameExpand( _Equator, inDaily );
// 計算日K當日高
_DailyToDayHighest = TimeFrameExpand( _ToDayHighest, inDaily );
// 計算日K當日低
_DailyToDayLowest  = TimeFrameExpand( _ToDayLowest, inDaily );
//
// 計算90日標轉差
//
// 計算日K當日高低差
_DailyHighLowDiff = TimeFrameGetPrice( "H", inDaily, 1 ) - TimeFrameGetPrice( "L", inDaily, 1 );
// 計算90日標轉差
_DailyStDev       = IIf( TimeNum() == 84600, round( StDev( _DailyHighLowDiff, 27000 ) ) , Null );
_FixDailyStDev    = Null;
for ( i = 1; i < BarCount; i ++ )
    _FixDailyStDev[ i ] = IIf( IsNull( _DailyStDev[ i ] ), _FixDailyStDev[ i - 1 ], _DailyStDev[ i ] );
//
// 計算日K標準差通道
//
_DailyStdDevM1 = round( _FixDailyStDev * 0.382 );
_DailyStdDevM2 = round( _FixDailyStDev * 1 );
_DailyStdDevM3 = round( _FixDailyStDev * 1.382 );
_DailyStdDevM4 = round( _FixDailyStDev * 2 );
_DailyNorthTropicM1 = _DailyEquator + _DailyStdDevM1;
_DailyNorthTropicM2 = _DailyEquator + _DailyStdDevM2;
_DailyNorthTropicM3 = _DailyEquator + _DailyStdDevM3;
_DailyNorthTropicM4 = _DailyEquator + _DailyStdDevM4;
_DailySouthTropicM1 = _DailyEquator - _DailyStdDevM1;
_DailySouthTropicM2 = _DailyEquator - _DailyStdDevM2;
_DailySouthTropicM3 = _DailyEquator - _DailyStdDevM3;
_DailySouthTropicM4 = _DailyEquator - _DailyStdDevM4;
//
//
//
_SECTION_BEGIN( "關卡線參數" );
Plot( IIf( TimeNum() == 134500, Null, _DailyEquator )
      , "基準線"
      , ParamColor( "基準線顏色", colorYellow )
      , ParamStyle( "基準線樣式", styleDashed ) );
Plot( IIf( TimeNum() == 134500, Null, _DailyNorthTropicM1 )
      , "多關卡1"
      , ParamColor( "多關卡1顏色", ColorRGB( 255, 200, 200 ) )
      , ParamStyle( "多關卡1樣式", styleDashed ) );
Plot( IIf( TimeNum() == 134500, Null, _DailyNorthTropicM2 )
      , "多關卡2"
      , ParamColor( "多關卡2顏色", ColorRGB( 255, 153, 153 ) )
      , ParamStyle( "多關卡2樣式", styleDashed ) );
Plot( IIf( High > _DailyNorthTropicM3, _DailyNorthTropicM3, Null )
      , "多關卡3"
      , ParamColor( "多關卡3顏色", ColorRGB( 255, 89, 89 ) )
      , ParamStyle( "多關卡3樣式", styleDashed ) );
Plot( IIf( High > _DailyNorthTropicM4, _DailyNorthTropicM4, Null )
      , "多關卡4"
      , ParamColor( "多關卡4顏色", ColorRGB( 255, 0, 0 ) )
      , ParamStyle( "多關卡4樣式", styleDashed ) );
Plot( IIf( TimeNum() == 134500, Null, _DailySouthTropicM1 )
      , "空關卡1"
      , ParamColor( "空關卡1顏色", ColorRGB( 0, 200, 255 ) )
      , ParamStyle( "空關卡1樣式", styleDashed ) );
Plot( IIf( TimeNum() == 134500, Null, _DailySouthTropicM2 )
      , "空關卡2"
      , ParamColor( "空關卡2顏色", ColorRGB( 0, 153, 255 ) )
      , ParamStyle( "空關卡2樣式", styleDashed ) );
Plot( IIf( Low < _DailySouthTropicM3, _DailySouthTropicM3, Null )
      , "空關卡3"
      , ParamColor( "空關卡3顏色", ColorRGB( 0, 89, 255 ) )
      , ParamStyle( "空關卡3樣式", styleDashed ) );
Plot( IIf( Low < _DailySouthTropicM4, _DailySouthTropicM4, Null )
      , "空關卡4"
      , ParamColor( "空關卡4顏色", ColorRGB( 0, 0, 255 ) )
      , ParamStyle( "空關卡4樣式", styleDashed ) );
PlotText( "Base"
          , LastValue( BarIndex() ) + 3
          , LastValue( _DailyEquator ) - 1
          , colorYellow  );
PlotText( "0.3S"
          , LastValue( BarIndex() ) + 3
          , LastValue( _DailyNorthTropicM1 ) - 1
          , ColorRGB( 255, 200, 200 ) );
PlotText( "1S"
          , LastValue( BarIndex() ) + 3
          , LastValue( _DailyNorthTropicM2 ) - 1
          , ColorRGB( 255, 153, 153 ) );
PlotText( "1.3S"
          , LastValue( BarIndex() ) + 3
          , LastValue( _DailyNorthTropicM3 ) - 1
          , ColorRGB( 255, 89, 89 ) );
PlotText( "2S"
          , LastValue( BarIndex() ) + 3
          , LastValue( _DailyNorthTropicM4 ) - 1
          , ColorRGB( 255, 0, 0 ) );
PlotText( "0.3S"
          , LastValue( BarIndex() ) + 3
          , LastValue( _DailySouthTropicM1 ) - 1
          , ColorRGB( 0, 200, 255 ) );
PlotText( "1S"
          , LastValue( BarIndex() ) + 3
          , LastValue( _DailySouthTropicM2 ) - 1
          , ColorRGB( 0, 153, 255 ) );
PlotText( "1.3S"
          , LastValue( BarIndex() ) + 3
          , LastValue( _DailySouthTropicM3 ) - 1
          , ColorRGB( 0, 89, 255 ) );
PlotText( "2S"
          , LastValue( BarIndex() ) + 3
          , LastValue( _DailySouthTropicM4 ) - 1
          , ColorRGB( 0, 0, 255 ) );
_SECTION_END();
//
// compute bar color
//
_SECTION_BEGIN( "K線" );
SetChartOptions( 0, chartShowArrows | chartShowDates | chartWrapTitle );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} 開 %g, 高 %g, 低 %g, 收 %g", O, H, L, C ) );
_BarColor = IIf( Low >= _DailyNorthTropicM1
                 , colorRed
                 , IIf( High <= _DailySouthTropicM1
                        , colorBlue
                        , IIf( ( High < _DailyNorthTropicM1 ) AND ( Low > _DailySouthTropicM1 )
                               , colorWhite
                               , IIf( ( High > _DailyNorthTropicM1 ) AND ( Low > _DailySouthTropicM1 )
                                      , colorBrown
                                      , IIf( ( High < _DailyNorthTropicM1 ) AND ( Low < _DailySouthTropicM1 )
                                             , colorGold
                                             , ColorRGB( 100, 100, 100 )
                                           )
                                    )
                             )
                      )
               );
PlotOHLC( Open
          , High
          , Low
          , Close
          , "Price"
          , _BarColor
          , styleBar
        );
_SECTION_END();
//
//
//
_SECTION_BEGIN( "車線" );
_nbar1   = Param( "長K數", 30, 2, 50, 1 );
_nbar2   = Param( "短K數", 2, 2, 10, 1 );
_Oma     = TSF( O, _nbar1 );
_Hma     = TSF( H, _nbar1 );
_Lma     = TSF( L, _nbar1 );
_Cma     = TSF( C, _nbar1 );
_maClose = ( _Oma + _Hma + _Lma + _Cma ) / 4;
_maOpen  = AMA( Ref( _maClose,  -1 ),  0.5 );
_maHigh  = Max( _Hma,  Max( _maClose,  _maOpen ) );
_maLow   = Min( _Lma,  Min( _maClose,  _maOpen ) );
_of      = MA( _maOpen, _nbar2 );
_cf      = MA( _maClose, _nbar2 );
_lf      = IIf( _maOpen < _maClose, MA( _maLow, _nbar2 ), MA( _maHigh, _nbar2 ) );
_hf      = IIf( _maOpen < _maClose, MA( _maHigh, _nbar2 ), MA( _maLow, _nbar2 ) );
Plot( _of, "", 2, 1 + 4096        );
Plot( _of - 2.5, "", 17, 32 + 4096 );
Plot( _of + 2.5, "", 17, 32 + 4096 );
_TurnUp = ( _of > Ref( _of, - 1 ) ) AND ( Ref( _of, - 1 ) < Ref( _of, - 2 ) );
_TurnDown = ( _of < Ref( _of, - 1 ) ) AND ( Ref( _of, - 1 ) > Ref( _of, - 2 ) );
_Shape = _TurnUp * shapeUpArrow + _TurnDown * shapeDownArrow;
PlotShapes( _Shape, IIf( _TurnUp, ColorRGB( 210, 0, 210 ), colorPink ), 0, _of  );

_Value = Null;
for ( i = 1; i < BarCount; i ++ )
{
    if ( ( _TurnUp[ i ] ) OR ( _TurnDown[ i ] ) )
    {
        _Value[ i ] = _of[ i ];
        //_Value[ i ] = Open[ i ];
        _Value[ i - 1 ] = Null;
    }
    else
    {
        _Value[ i ] = _Value[ i - 1 ];
    }
}
Plot(  _Value, "", 10, styleDots | styleNoLine );
_SECTION_END();

 

此範例原始碼可至 B1.交易策略範例原始碼 下載。

 


arrow
arrow
    全站熱搜

    隱弄客 發表在 痞客邦 留言(1) 人氣()