The script will analyze the Forex market during the Asia session to detect the lowest point and the highest point. Then, in the New York session, if these points are broken and the price re-enters with a bullish (for the lowest point) or bearish (for the highest point) candle in the one-hour timeframe, you will open a long position or short respectively.
`//+------------------------------------------------------------------+
//| TradeScript.mq4 |
//| Copyright 2024, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property strict
// Definir variables globales
double asianLow = 0;
double asianHigh = 0;
datetime asianSessionStart = D'02:00'; // Ajustar según el broker
datetime asianSessionEnd = D'10:00'; // Ajustar según el broker
datetime newYorkSessionStart = D'14:00'; // Ajustar según el broker
datetime newYorkSessionEnd = D'22:00'; // Ajustar según el broker
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Inicializar variables
asianLow = High[0];
asianHigh = Low[0];
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
datetime currentTime = TimeCurrent();
// Detectar la sesión de Asia
if(currentTime >= asianSessionStart && currentTime <= asianSessionEnd)
{
// Actualizar el punto más bajo y más alto
for(int i = 0; i < Bars; i++)
{
datetime barTime = Time[i];
if(barTime >= asianSessionStart && barTime <= asianSessionEnd)
{
if(Low[i] < asianLow) asianLow = Low[i];
if(High[i] > asianHigh) asianHigh = High[i];
}
}
}
// Detectar la sesión de Nueva York
if(currentTime >= newYorkSessionStart && currentTime <= newYorkSessionEnd)
{
// Buscar reingreso con vela alcista (para largos)
if(Bid < asianLow)
{
if(Open[1] < asianLow && Close[1] > asianLow)
{
double stopLoss = asianLow - 3 * Point;
double takeProfit = asianLow + 3 * (asianLow - stopLoss);
OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, stopLoss, takeProfit, "Buy Order", 0, 0, Green);
}
}
// Buscar reingreso con vela bajista (para cortos)
if(Ask > asianHigh)
{
if(Open[1] > asianHigh && Close[1] < asianHigh)
{
double stopLoss = asianHigh + 3 * Point;
double takeProfit = asianHigh - 3 * (stopLoss - asianHigh);
OrderSend(Symbol(), OP_SELL, 0.1, Bid, 3, stopLoss, takeProfit, "Sell Order", 0, 0, Red);
}
}
}
}
//+------------------------------------------------------------------+`
My code do not open any trade yet
New contributor
Kevin Malagon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.