1
0
Fork 0
forked from e187038/SP_GVA1
SP_GVA1/SP_Pedro1/Homework1/SP_Pedro_Chapter09_v3.mq5

81 lines
6.1 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 16:25:41 +02:00
<EFBFBD><EFBFBD> //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<EFBFBD>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<EFBFBD>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<EFBFBD>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<EFBFBD>mbolo
request.type_filling=ORDER_FILLING_IOC;L=__LINE__;Print (" L: ",L); //poniendo esto me sale market closed en US500
request.magic = 1001; // N<EFBFBD>mero m<EFBFBD>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 <preciomaximo) {
comprahecha=OrderSend(request,result);L=__LINE__;Print (" L: ",L);
if (comprahecha) {
Print("Compra hecha con precio = ",precio);
// Print ("compra realizada");L=__LINE__;Print (" L: ",L);
preciocomprafinal=request.price;L=__LINE__;Print (" L: ",L);
}
else {
int error_code = GetLastError();L=__LINE__;Print (" L: ",L);
Print("Error al enviar la orden: ", error_code);
}
}
// imprimeResult (result);
}
//+------------------------------------------------------------------+