0% found this document useful (0 votes)
4 views

deepseek_mql5_20250502_d5c8aa

This document outlines an Expert Advisor (EA) for trading, which includes parameters for lot size, candle checks, and order types based on market conditions. The EA evaluates the last four candles to determine if they are bullish or bearish and places pending orders accordingly. It also includes functionality for setting stop loss and take profit levels, along with error handling for order placement.

Uploaded by

9406cfv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

deepseek_mql5_20250502_d5c8aa

This document outlines an Expert Advisor (EA) for trading, which includes parameters for lot size, candle checks, and order types based on market conditions. The EA evaluates the last four candles to determine if they are bullish or bearish and places pending orders accordingly. It also includes functionality for setting stop loss and take profit levels, along with error handling for order placement.

Uploaded by

9406cfv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

//+------------------------------------------------------------------+

//| Expert initialization function |


//+------------------------------------------------------------------+
input double LotSize = 0.01; // Tamanho do lote (padrão 0.01)
input int CandlesToCheck = 4; // Número de velas para verificar
input int PipsAway = 50; // Distância em pips para ordens pendentes
input bool UseBuyLimitGreen = true; // Usar Buy Limit para velas verdes
input bool UseBuyStopGreen = false; // Usar Buy Stop para velas verdes
input bool UseSellLimitGreen = false; // Usar Sell Limit para velas verdes
input bool UseSellStopGreen = false; // Usar Sell Stop para velas verdes
input bool UseBuyLimitRed = false; // Usar Buy Limit para velas vermelhas
input bool UseBuyStopRed = false; // Usar Buy Stop para velas vermelhas
input bool UseSellLimitRed = true; // Usar Sell Limit para velas vermelhas
input bool UseSellStopRed = false; // Usar Sell Stop para velas vermelhas
input int MagicNumber = 12345; // Número mágico para identificação
input int Slippage = 3; // Slippage permitido
input double TakeProfit = 0; // Take profit em pips (0 = desativado)
input double StopLoss = 0; // Stop loss em pips (0 = desativado)

//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// Verificar se já temos ordens abertas para não duplicar
if(OrdersTotal() > 0) return;

// Verificar as últimas 4 velas


bool allBullish = true;
bool allBearish = true;

for(int i = 1; i <= CandlesToCheck; i++)


{
double close = iClose(_Symbol, PERIOD_CURRENT, i);
double open = iOpen(_Symbol, PERIOD_CURRENT, i);

if(close <= open) allBullish = false;


if(close >= open) allBearish = false;

// Se já sabemos que não são todas iguais, podemos sair mais cedo
if(!allBullish && !allBearish) break;
}

// Se todas as velas são verdes (bullish)


if(allBullish)
{
if(UseBuyLimitGreen)
{
double entryPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK) - PipsAway *
_Point;
PlacePendingOrder(ORDER_TYPE_BUY_LIMIT, entryPrice);
}

if(UseBuyStopGreen)
{
double entryPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK) + PipsAway *
_Point;
PlacePendingOrder(ORDER_TYPE_BUY_STOP, entryPrice);
}
if(UseSellLimitGreen)
{
double entryPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID) + PipsAway *
_Point;
PlacePendingOrder(ORDER_TYPE_SELL_LIMIT, entryPrice);
}

if(UseSellStopGreen)
{
double entryPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID) - PipsAway *
_Point;
PlacePendingOrder(ORDER_TYPE_SELL_STOP, entryPrice);
}
}
// Se todas as velas são vermelhas (bearish)
else if(allBearish)
{
if(UseBuyLimitRed)
{
double entryPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK) - PipsAway *
_Point;
PlacePendingOrder(ORDER_TYPE_BUY_LIMIT, entryPrice);
}

if(UseBuyStopRed)
{
double entryPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK) + PipsAway *
_Point;
PlacePendingOrder(ORDER_TYPE_BUY_STOP, entryPrice);
}

if(UseSellLimitRed)
{
double entryPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID) + PipsAway *
_Point;
PlacePendingOrder(ORDER_TYPE_SELL_LIMIT, entryPrice);
}

if(UseSellStopRed)
{
double entryPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID) - PipsAway *
_Point;
PlacePendingOrder(ORDER_TYPE_SELL_STOP, entryPrice);
}
}
}

//+------------------------------------------------------------------+
//| Função para colocar ordens pendentes |
//+------------------------------------------------------------------+
void PlacePendingOrder(ENUM_ORDER_TYPE orderType, double entryPrice)
{
MqlTradeRequest request = {};
MqlTradeResult result = {};

request.action = TRADE_ACTION_PENDING;
request.symbol = _Symbol;
request.volume = LotSize;
request.type = orderType;
request.price = NormalizeDouble(entryPrice, _Digits);
request.deviation = Slippage;
request.magic = MagicNumber;

// Configurar Stop Loss se diferente de zero


if(StopLoss != 0)
{
request.sl = (orderType == ORDER_TYPE_BUY_LIMIT || orderType ==
ORDER_TYPE_BUY_STOP) ?
NormalizeDouble(entryPrice - StopLoss * _Point, _Digits) :
NormalizeDouble(entryPrice + StopLoss * _Point, _Digits);
}

// Configurar Take Profit se diferente de zero


if(TakeProfit != 0)
{
request.tp = (orderType == ORDER_TYPE_BUY_LIMIT || orderType ==
ORDER_TYPE_BUY_STOP) ?
NormalizeDouble(entryPrice + TakeProfit * _Point, _Digits) :
NormalizeDouble(entryPrice - TakeProfit * _Point, _Digits);
}

if(!OrderSend(request, result))
{
Print("Falha ao enviar ordem. Código de erro: ", GetLastError());
}
else
{
Print("Ordem enviada com sucesso. Ticket: ", result.order);
}
}

You might also like