//ha funcionado la compra con request.type_filling=ORDER_FILLING_IOC en EUR/DOLAR . //deviation estaba sin asignar. //adaptar preciomaximo y preciominimo cuando se ejecute para otro SYMBOL #define POSICION 0 #define PRECIOMAXUS500 2380 #define PRECIOMINUS500 2340 #define PRECIOMAXEURDOL 1.0404 #define PRECIOMINEURDOL 1.0401 double lotSize = 0.01; // Tamaño del lote double stopLoss = 50; // Nivel de stop loss en puntos double takeProfit = 100; // Nivel de take profit en puntos bool comprahecha=false,ventahecha=false; ulong desviacion=1050; double precioanterior,preciocomprafinal; ulong serverTime,miliseconds; double preciomaximo=PRECIOMAXEURDOL; double preciominimo=PRECIOMINEURDOL; int L; int OnInit() { //--- return(INIT_SUCCEEDED); } void OnTick() { //--- //--- double precio=0; precio = SymbolInfoDouble(_Symbol, SYMBOL_BID);// L=__LINE__;Print (" L: ",L); Print ("PRECIO BUY:= ",precio);L=__LINE__;Print (" L: ",L); //Print (" volume size step:= ",SymbolInfoDouble (Symbol(), SYMBOL_VOLUME_STEP)); MqlTradeRequest request,request2; MqlTradeResult result,result2; ZeroMemory(result); ZeroMemory(request); request.action = TRADE_ACTION_DEAL;//L=__LINE__;Print (" L: ",L); // Tipo de acción: Deal (acuerdo) request.type = ORDER_TYPE_BUY;//L=__LINE__;Print (" L: ",L); // Tipo de orden: Compra request.volume = lotSize; //L=__LINE__;Print (" L: ",L); // Tamaño del lote request.price = precio; //L=__LINE__;Print (" L: ",L); // Precio de mercado actual // request.deviation=desviacion; // request.sl = precio - stopLoss * _Point; // Stop Loss //request.tp = precio + takeProfit * _Point; // Take Profit request.sl=precio *0.80; request.tp=precio*1.20; request.symbol = _Symbol;// L=__LINE__;Print (" L: ",L); // Símbolo request.type_filling=ORDER_FILLING_IOC;L=__LINE__;Print (" L: ",L); //poniendo esto me sale market closed en US500 request.magic = 1001; // Número mágico request.position=0;//L=__LINE__;Print (" L: ",L); Print ("action ",request.action," type ",request.type," volume ",request.volume," price ",request.price, " stop loss ",request.sl," take ",request.tp," symbol ",request.symbol," position: ",request.position); Print (SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL) ); //da 0, no hay restricciones de distancia entre precio y sl,tp if (precio >preciominimo && precio