|
本帖最後由 jacklcl 於 14-7-25 01:06 編輯
K大, 我將你們之前討論的code改寫了一下
將Short及Cover分開寫了
但發覺還是會出現不停下單的情況
不知哪裡出現問題, 希望指導一下
_SECTION_BEGIN("IB Controller");
{ ibc = GetTradingInterface("IB");
ContractMonth = "ESU4-GLOBEX-FUT";
BuyTrigger = LastValue( Buy );
SellTrigger = LastValue( Sell );
ShortTrigger = LastValue( Short );
CoverTrigger = LastValue (Cover);
Reset = ParamTrigger( "Reset All", "RESET" );
PrevTN = StaticVarGet( "TimeNumber" + Name() );
TN = LastValue( TimeNum() );
NewBar = TN != PrevTN;
StaticVarSet( "TimeNumber" + Name(), TN );
BuyOrderID = StaticVarGetText( "BuyOrderID" + Name() );
SellOrderID = StaticVarGetText( "SellOrderID" + Name() );
ShortOrderID = StaticVarGetText( "ShortID" + Name() );
CoverOrderID = StaticVarGetText( "CoverID" + Name() );
BuyPending = ibc.IsOrderPending( BuyOrderID );
SellPending = ibc.IsOrderPending( SellOrderID );
ShortPending = ibc.IsOrderPending( ShortOrderID );
CoverPending = ibc.IsOrderPending( CoverOrderID );
Shares = 1;
if ( NewBar )
{
if ( NOT BuyPending ) StaticVarSetText( "BuyOrderID" + Name(), "" );
if ( NOT SellPending ) StaticVarSetText( "SellOrderID" + Name(), "" );
if ( NOT ShortPending ) StaticVarSetText( "ShortOrderID" + Name(), "" );
if ( NOT CoverPending ) StaticVarSetText( "CoverOrderID" + Name(), "" );
}
if ( BuyTrigger AND BuyOrderID == "" )
{
BuyOrderID = ibc.PlaceOrder(ContractMonth, "BUY", Shares, "MKT", 0, 0, "DAY", True);
StaticVarSetText( "BuyOrderID" + Name(), BuyOrderID, true );
}
else if ( SellTrigger AND SellOrderID == "" )
{
ibc.CloseAllOpenPositions( ContractMonth );
StaticVarSetText( "SellOrderID" + Name(), SellOrderID, true );
}
else if ( ShortTrigger AND ShortOrderID == "" )
{
ShortORderID = ibc.PlaceOrder(ContractMonth, "SELL", Shares, "MKT", 0, 0, "DAY", True);
StaticVarSetText( "ShortOrderID" + Name(), ShortOrderID, true );
}
else if ( CoverTrigger AND CoverOrderID == "" )
{
ibc.CloseAllOpenPositions( ContractMonth );
StaticVarSetText( "CoverOrderID" + Name(), CoverOrderID, true );
}
else if ( Reset )
{
StaticVarSetText( "BuyOrderID" + Name(), "" );
if ( BuyPending ) ibc.CancelOrder( BuyOrderID );
StaticVarSetText( "SellOrderID" + Name(), "" );
if ( SellPending ) ibc.CancelOrder( SellOrderID );
StaticVarSetText( "ShortOrderID" + Name(), "" );
if ( ShortPending ) ibc.CancelOrder( ShortOrderID );
StaticVarSetText( "CoverOrderID" + Name(), "" );
if ( CoverPending ) ibc.CancelOrder( CoverOrderID );
}
_SECTION_END();
感謝!! |
|