Ordenes automáticas con AMI
Publicado: 10 Ene 2006 14:08
Hola
Como los ateriores daban problemas de conttrol sobre las órenes los he cambiado.
Este es un pequeño sistema que lleva añadido la automatización de órdenes en AMIB. Es un reverse que siempre está en mercado con un contrato; para utilizar MoneyM habrá que aprender a programar algo más. Por ahora espero que esto os sea de alguna utilidad.
Podeis probarlo en gráficos de un minuto para que cambie de posición rápidamente, en el Paper de IB con Eur Fut.
Solo hay que copiarlo y pegarlo:
(si veis algún fallo por favor comentarlo)
////Para probar IBController ////
Ind=Ref(MACD(12,17),-1);
Ind2=MA(Ind,2);
Buy=Cross(Ind,Ind2);
Short=Cross(Ind2,Ind);
Cover=Buy;
Sell=Short;
SellPrice=O;
BuyPrice = O;
Plot(Ind,"Ind",colorRed);
Plot(Ind2,"Ind2",colorBlue);
PlotShapes(IIf (Buy,shapeUpArrow,shapeNone),colorGreen,0,Graph0,-12);
PlotShapes(IIf(Short,shapeDownArrow,shapeNone),colorRed,0,Graph0,-12);
//// IBController //////
ibc = GetTradingInterface("IB");
if( LastValue( Buy ) )
{
// check if we are connected OK
if( ibc.IsConnected() )
{
// check if we do not have already open position on this stock
OrderID = StaticVarGetText("OrderID"+"6EH6-GLOBEX-FUT");
if(( ibc.GetPositionSize( "6EH6-GLOBEX-FUT" ) <= 0 )AND (ibc.IsOrderPending(OrderId ) == False) )
{
// transmit order
OrderID = ibc.PlaceOrder( "6EH6-GLOBEX-FUT", "Buy", 1, "MKT", 0, 0.02, "Day", True,1 );
// store orderID for next run so we know which order to modify
StaticVarSetText("OrderID"+"6EH6-GLOBEX-FUT" , OrderID);
}
}
}
if( LastValue( Short) )
{
// check if we are connected OK
if( ibc.IsConnected() )
{
// check if we do not have already open position on this stock
OrderID = StaticVarGetText("OrderID"+"6EH6-GLOBEX-FUT");
if(( ibc.GetPositionSize( "6EH6-GLOBEX-FUT" ) >=0 )AND (ibc.IsOrderPending(OrderId) == False) )
{
// transmit order
OrderID = ibc.PlaceOrder("6EH6-GLOBEX-FUT", "sell", 1, "MKT", 0, 0.02, "Day", True,1 );
// store orderID for next run so we know which order to modify
StaticVarSetText("OrderID"+"6EH6-GLOBEX-FUT" , OrderID);
}
}
}
Como los ateriores daban problemas de conttrol sobre las órenes los he cambiado.
Este es un pequeño sistema que lleva añadido la automatización de órdenes en AMIB. Es un reverse que siempre está en mercado con un contrato; para utilizar MoneyM habrá que aprender a programar algo más. Por ahora espero que esto os sea de alguna utilidad.
Podeis probarlo en gráficos de un minuto para que cambie de posición rápidamente, en el Paper de IB con Eur Fut.
Solo hay que copiarlo y pegarlo:
(si veis algún fallo por favor comentarlo)
////Para probar IBController ////
Ind=Ref(MACD(12,17),-1);
Ind2=MA(Ind,2);
Buy=Cross(Ind,Ind2);
Short=Cross(Ind2,Ind);
Cover=Buy;
Sell=Short;
SellPrice=O;
BuyPrice = O;
Plot(Ind,"Ind",colorRed);
Plot(Ind2,"Ind2",colorBlue);
PlotShapes(IIf (Buy,shapeUpArrow,shapeNone),colorGreen,0,Graph0,-12);
PlotShapes(IIf(Short,shapeDownArrow,shapeNone),colorRed,0,Graph0,-12);
//// IBController //////
ibc = GetTradingInterface("IB");
if( LastValue( Buy ) )
{
// check if we are connected OK
if( ibc.IsConnected() )
{
// check if we do not have already open position on this stock
OrderID = StaticVarGetText("OrderID"+"6EH6-GLOBEX-FUT");
if(( ibc.GetPositionSize( "6EH6-GLOBEX-FUT" ) <= 0 )AND (ibc.IsOrderPending(OrderId ) == False) )
{
// transmit order
OrderID = ibc.PlaceOrder( "6EH6-GLOBEX-FUT", "Buy", 1, "MKT", 0, 0.02, "Day", True,1 );
// store orderID for next run so we know which order to modify
StaticVarSetText("OrderID"+"6EH6-GLOBEX-FUT" , OrderID);
}
}
}
if( LastValue( Short) )
{
// check if we are connected OK
if( ibc.IsConnected() )
{
// check if we do not have already open position on this stock
OrderID = StaticVarGetText("OrderID"+"6EH6-GLOBEX-FUT");
if(( ibc.GetPositionSize( "6EH6-GLOBEX-FUT" ) >=0 )AND (ibc.IsOrderPending(OrderId) == False) )
{
// transmit order
OrderID = ibc.PlaceOrder("6EH6-GLOBEX-FUT", "sell", 1, "MKT", 0, 0.02, "Day", True,1 );
// store orderID for next run so we know which order to modify
StaticVarSetText("OrderID"+"6EH6-GLOBEX-FUT" , OrderID);
}
}
}