繼上篇 控制下單口數、使用下單大師、輸出文字檔 後,此次來做個小改版,簡化不必要的程式碼又可達到一樣的效果。廢話不多說直接進入正題
// // title // SetChartOptions( 0, chartShowArrows | chartShowDates | chartWrapTitle ); _N( Title = StrFormat( "{{NAME}} - {{DATE}} O %g, H %g, L %g, C %g, (%.1f%%)", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) ); Title = Title + " [ Go Order Sample ] Create by E.Y. @2012/01/08 \n{{VALUES}}"; Plot( Day() != Ref( Day(), -1 ), "", ColorRGB( 50, 50, 50 ), styleHistogram | styleOwnScale, 0, 1 );
上述程式碼,主要處理圖的表頭資訊,
line 7. 於換日時劃出一條垂直分日線,提高畫面可讀性。
// --- >>> START <<< // --------------------------------------------------------------------------- // computation buy, short, sell and cover condition // --------------------------------------------------------------------------- // // computation buy, short, sell and cover condition // _Condition1 = Ref( MA( Close, 3 ), -1 ); _Condition2 = Ref( MA( Close, 22 ), -1 ); Buy = ( _Condition1 > _Condition2 ) AND ( TimeNum() <= 132000 ); // buy condition Short = ( _Condition1 < _Condition2 ) AND ( TimeNum() <= 132000 ); // short condition Sell = Cover = ( TimeNum() > 132000 ); // sell and cover condition // // computation buyprice, shortprice, sellprice and coverprice // BuyPrice = ShortPrice = SellPrice = CoverPrice = Close; // // filter buy, short, sell and cover signal // _LongEntry = ExRem( Buy, Short ) OR ExRem( Buy, Sell ); _ShortEntry = ExRem( Short, Buy ) OR ExRem( Short, Cover ); _ClearAll = ( Sell OR Cover ) AND ( Ref( Buy, -1 ) OR Ref( Short, -1 ) ); // // --------------------------------------------------------------------------- // computation buy, short, sell and cover condition // --------------------------------------------------------------------------- // --- >>> END <<<
上述程式碼,處理策略之買賣訊號,在此我任意拿兩條均線來作範例,
line 8. 策略條件一(短均線),
line 9. 策略條件二(長均線),
line 10. 作多:當 短均線 在 長均線 之上,
line 11. 作空:當 短均線 在 長均線 之下,
line 12. 空手:每日 13:20:00 後強制平倉,
line 16. 進/出場價位,
// --- >>> START <<< // --------------------------------------------------------------------------- // computation order date, time, contracts, price // --------------------------------------------------------------------------- // // contracts per order // _TXFContractUnit = 1; // // txf order contracts // _TXFOrderContracts = IIf( Sell OR Cover // sell or cover contracts , 0 , IIf( Buy // buy contracts , _TXFContractUnit // short contracts , _TXFContractUnit * -1 ) ); _TXFOrderPrice = Close; // // --------------------------------------------------------------------------- // computation order contracts, price // --------------------------------------------------------------------------- // --- >>> END <<<
上述程式碼,處理下單口數及下單價位。
// --- >>> START <<< // --------------------------------------------------------------------------------------------- // go order // --------------------------------------------------------------------------------------------- // // prepare go order parameters // _GoOrderContracts = _TXFOrderContracts; _GoOrderPrice = _TXFOrderPrice; _GoOrderNowDate = Now( 1 ); _GoOrderNowTime = StrRight( "00" + floor( Now( 4 ) / 10000 ), 2 ) + ":" + StrRight( "00" + floor( Now( 4 ) / 100 ), 2 ) + ":" + StrRight( "00" + floor( Now( 4 ) % 100 ), 2 ); // // sned order command to [ OrderMaster API ] // _OMComAPI = CreateStaticObject( "OMSignAPI.OMCOMAPI" ); _OMComAPI.IniDllAndPosition( "EYDEMO", NumToStr( _TXFOrderContracts, 0 ) ); _OMComAPI.GoOrder( "EYDEMO" , "" , _GoOrderNowDate + " " + _GoOrderNowTime , NumToStr( _GoOrderContracts, 0 ) , NumToStr( _GoOrderPrice, 0 ) ); // // output text file for [YasserSoft] auto record // _YS_ORDER_CMD = "R:\\YS_TEMP\\EYDEMO.txt"; if ( ( Now( 4 ) % 2 ) == 0 ) { _fcsv = fopen( _YS_ORDER_CMD, "w" ); _content = _GoOrderNowDate + " " + _GoOrderNowTime + " " + StrFormat( "%g %g", _GoOrderContracts, _GoOrderPrice ) + " " + _GoOrderNowTime ; fputs( _content, _fcsv ); fclose( _fcsv ); } // --------------------------------------------------------------------------------------------- // go order // --------------------------------------------------------------------------------------------- // --- >>> END <<<
上述程式碼,
line 17~24. 調用[下單大師]進行下單,
line 28~39. 輸出文字檔給[雅策免費紀錄器]使用,
到此您已可以使用 AmiBroker 即時透過[下單大師API]或[讀文字檔下單機]進行下單囉 ^o^
後續之程式碼僅是在圖表上塗塗抹抹,若不需要忽略即可。
// --- >>> START <<< // --------------------------------------------------------------------------- // drawing // --------------------------------------------------------------------------- // // draw the ma line // Plot( _Condition1, "MA1", colorYellow, styleDashed ); Plot( _Condition2, "MA2", ColorRGB( 0, 80, 255 ), styleDots ); // // draw the buy or short signal // PlotShapes( _LongEntry * shapeUpArrow + _ShortEntry * shapeDownArrow , IIf( _LongEntry, colorYellow, ColorRGB( 0, 80, 255 ) ) , 0 , IIf( _LongEntry, Low, High ) , -30 ); // // draw the clear signal // PlotShapes( _ClearAll * shapeSmallCircle , colorLightGrey , 0 , Close , -30 ); PlotShapes( _ClearAll * shapeHollowSquare , colorLightGrey , 0 , Close , -30 ); // // draw the candle line // Plot( Close , "Close" , ParamColor( "Color", colorBlack ) , styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() ); // // // Title = Title + EncodeColor( colorGold ) + " ( " + _GoOrderContracts + ", " + _GoOrderPrice + " )"; // // --------------------------------------------------------------------------- // drawing // --------------------------------------------------------------------------- // --- >>> END <<<
歡迎各位同好取用及轉載,但請標明出處 ~ ^o^
全站熱搜