Por favor, utilice esto para publicar el código . . hace que sea más fácil de leer.
Hola a todos,
Me gustaría saber si es posible cerrar una orden automáticamente después de que se alcance un periodo y/o SL...
Por ejemplo:
He abierto una operación a la 1 de la tarde y quiero que esta orden se cierre cuando la cotización haya alcanzado su StoppLoss o haya transcurrido un periodo de 2 horas.
Aquí está el código real:
// Criterio de compra
if ((TradeHour3==Hour())||(TradeHour4==Hour())||(TradeHour7==Hour())||(TradeHour10==Hour())||(TradeHour17==Hour())||(TradeHour18==Hour())||(TradeHour20==Hour()) /Señal de compra
{
int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,slb,tpb, "time trader buy order ",BuyMagicNumber,0,Blue);
if(openbuy<1){int buyfail=1;}
}
}// halt1
if((halt2!=1)&&(AllowSell==true)){// halt2
RefreshRates();
// Criterios de venta
if ((TradeHour12==Hour())||(TradeHour23==Hour()) //Señal de venta
{
int opensell=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,sls,tps, "time trader sell order ",SellMagicNumber,0,Green);
if(opensell<1){int sellfail=1;}
}
}// halt2
Gracias de antemano
Marc
// Buy criteria if ((TradeHour3==Hour())||(TradeHour4==Hour())||(TradeHour7==Hour())||(TradeHour10==Hour())||(TradeHour17==Hour())||(TradeHour18==Hour())||(TradeHour20==Hour())) //Signal Buy { int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,slb,tpb,"time trader buy order ",BuyMagicNumber,0,Blue); if(openbuy<1){int buyfail=1;} } }// halt1 if((halt2!=1)&&(AllowSell==true)){// halt2 RefreshRates(); // Sell criteria if ((TradeHour12==Hour())||(TradeHour23==Hour())) //Signal Sell { int opensell=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,sls,tps,"time trader sell order ",SellMagicNumber,0,Green); if(opensell<1){int sellfail=1;} } }// halt2
Me gustaría saber si es posible cerrar una orden automáticamente después de que se alcance un periodo y/o el SL...
- Si se alcanza el SL, se cierra solo.
- De lo contrario, sólo tienes que codificarla. ¿Dónde está tu OrderClose() y tu prueba de tiempo?
- Si se alcanza el SL, se cierra solo.
- Si no, sólo tienes que codificarla. ¿Dónde está su OrderClose() y su prueba de tiempo?
HI WHRoeder,
Creo que te refieres al código del agujero o?
//---- input parameters extern double Lots=0.01; extern int TakeProfit=200; extern int StopLoss=200; extern int Slip=50; extern int BuyMagicNumber =1; extern int SellMagicNumber =2; extern bool AllowBuy=true; extern bool AllowSell=true; extern int TradeHour3=3; extern int TradeHour4=4; extern int TradeHour7=7; extern int TradeHour10=10; extern int TradeHour17=17; extern int TradeHour18=18; extern int TradeHour20=20; extern int TradeHour12=12; extern int TradeHour23=23; //+------------------------------------------------------------------+ //| expert starts | //+------------------------------------------------------------------+ int start() { //---- int StopMultd,Sleeper=1; int digits=MarketInfo("EURUSD",MODE_DIGITS); if(digits==5){StopMultd=10;} else{StopMultd=1;} double TP=NormalizeDouble(TakeProfit*StopMultd,Digits); double SL=NormalizeDouble(StopLoss*StopMultd,Digits); double Slippage=NormalizeDouble(Slip*StopMultd,Digits); // Calculate stop loss double slb=NormalizeDouble(Ask-SL*Point,Digits); double sls=NormalizeDouble(Bid+SL*Point,Digits); // Calculate take profit double tpb=NormalizeDouble(Ask+TP*Point,Digits); double tps=NormalizeDouble(Bid-TP*Point,Digits); //-------------------------------------------------------------------+ //Check open orders //-------------------------------------------------------------------+ if(OrdersTotal()>0){ for(int i=1; i<=OrdersTotal(); i++) // Cycle searching in orders { if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available { if(OrderMagicNumber()==BuyMagicNumber) {int halt1=1;} if(OrderMagicNumber()==SellMagicNumber) {int halt2=1;} } } } //-------------------------------------------------------------------+ if((halt1!=1)&&(AllowBuy==true)){// halt1 // Buy criteria if ((TradeHour3==Hour())||(TradeHour4==Hour())||(TradeHour7==Hour())||(TradeHour10==Hour())||(TradeHour17==Hour())||(TradeHour18==Hour())||(TradeHour20==Hour())) //Signal Buy { int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,slb,tpb,"time trader buy order ",BuyMagicNumber,0,Blue); if(openbuy<1){int buyfail=1;} } }// halt1 if((halt2!=1)&&(AllowSell==true)){// halt2 RefreshRates(); // Sell criteria if ((TradeHour12==Hour())||(TradeHour23==Hour())) //Signal Sell { int opensell=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,sls,tps,"time trader sell order ",SellMagicNumber,0,Green); if(opensell<1){int sellfail=1;} } }// halt2 //-------------------------------------------------------------------+ // Error processing //-------------------------------------------------------------------+ if(buyfail==1||sellfail==1){ int Error=GetLastError(); if(Error==130){Alert("Wrong stops. Retrying."); RefreshRates();} if(Error==133){Alert("Trading prohibited.");} if(Error==2){Alert("Common error.");} if(Error==146){Alert("Trading subsystem is busy. Retrying."); Sleep(500); RefreshRates();} } // if(openbuy==true||opensell==true)Sleep(1*60*1000*Sleeper); //------------------------------------------------------------------- return(0); } //+-----------------------------------
en realidad solo hay un stopploss. Sólo quiero cerrar la orden 2 horas después de una nueva barra se abrió o el último segundo de 1:59:59...Mi problema es llenar el código en mi actual...
Recorre las órdenes abiertas comprobando cuándo se abrieron usando OrderOpenTime (no olvides usar OrderSelect primero), luego comprueba ese tiempo frente a TimeCurrent para ver si han transcurrido 2 horas... si lo han hecho cierra la orden.
Solo hay que codificar eso... realmente no es difícil.
Espero que me puedas dar pistas si fallo ;-)
AFAIK todo el mundo aquí quiere ayudar pero no ser un esclavo para nadie
Sí, por supuesto, entiendo ... No quiero tener esclavos para mi EA's.... lo único que necesito saber es cómo entender de qué manera funciona un programa ...
Si tienes un EA sencillo como SMA Cross...esto no es un gran problema...pero cuanto más quieres conseguir más difícil se hace...(al menos para mí)

- Aplicaciones de trading gratuitas
- 8 000+ señales para copiar
- Noticias económicas para analizar los mercados financieros
Usted acepta la política del sitio web y las condiciones de uso
Hola a todos,
Me gustaría saber si es posible cerrar una orden automáticamente después de que se alcance un periodo y/o SL...
Por ejemplo:
He abierto una operación a la 1 de la tarde y quiero que esta orden se cierre cuando la cotización haya alcanzado su StoppLoss o haya transcurrido un periodo de 2 horas.
Aquí está el código real:
// Criterio de compra
if ((TradeHour3==Hour())||(TradeHour4==Hour())||(TradeHour7==Hour())||(TradeHour10==Hour())||(TradeHour17==Hour())||(TradeHour18==Hour())||(TradeHour20==Hour()) /Señal de compra
{
int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,slb,tpb, "time trader buy order ",BuyMagicNumber,0,Blue);
if(openbuy<1){int buyfail=1;}
}
}// halt1
if((halt2!=1)&&(AllowSell==true)){// halt2
RefreshRates();
// Criterios de venta
if ((TradeHour12==Hour())||(TradeHour23==Hour()) //Señal de venta
{
int opensell=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,sls,tps, "time trader sell order ",SellMagicNumber,0,Green);
if(opensell<1){int sellfail=1;}
}
}// halt2
Gracias de antemano
Marc