|
本帖最後由 enochyu 於 12-1-9 12:48 AM 編輯
程式範例分享 ~ AmiBroker 控制下單口數、使用下單大師、輸出文字檔
------
祝各位 AmiBroker 戰友順心 ...
enochyu 發表於 11-12-30 12:43 AM
來個小改版,簡化不必要之程式碼(如:for loop)達到一樣的效果,請參考囉
- //
- // 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 );
- // --- >>> 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 <<<
- // --- >>> 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 <<<
- // --- >>> 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 <<<
複製代碼
相信以各位大大功力一看就懂,小弟在此就不在贅述了
轉載至 C.A.B.E. |
|