// ---- INPUTS ----
input group "--- Trading Inputs ---";
input double Lots = 0.01; // Lot Size
input int TpPoints = 50; // Take Profit in points [m5-50p, h1-200p]
input ENUM_TIMEFRAMES IchimokuTimeFrame = PERIOD_CURRENT; // Timeframe (will use current timeframe)
// ---- Ichimoku Inputs ----
input int TenkanPeriod = 9; // Tenkan-sen Period
input int KijunPeriod = 26; // Kijun-sen Period
input int SenkouSpanBPeriod = 52; // Senkou Span B Period
input int Displacement = 26; // Displacement
// ---- Stochastic Inputs ----
input int StochasticKPeriod = 14; // %K period
input int StochasticDPeriod = 3; // %D period
input int StochasticSlowing = 3; // Slowing for the Stochastic
// ---- Parabolic SAR Inputs ----
input double SARStep = 0.02; // Parabolic SAR Step
input double SARMaximum = 0.2; // Parabolic SAR Maximum
nao esta abrindo ordens corrija e me entregue completo
O código que você forneceu é um Expert Advisor (EA) para a plataforma MetaTrader 5 (MT5) que utiliza o indicador Ichimoku, Stochastic, Parabolic SAR e RSI para fazer operações de compra e venda. No entanto, pode haver alguns motivos pelos quais o EA não está abrindo ordens. Vamos revisar e garantir que tudo esteja configurado corretamente para que possa funcionar.
Aqui está uma versão corrigida do seu código com algumas melhorias e ajustes:
mql5
//+------------------------------------------------------------------+
//| AI Ichimoku Scalper.mq5|
//| Alfr5d |
//| https://www.49design.co.za |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, Alfred Mandala."
#property version "1.6"
#property description "Ichimoku Scalping EA, RSI Integrated, TIMEFRAME = M5\nLOW RISK SETTINGS"
#include <Trade/Trade.mqh>
// ---- INPUTS ----
input double Lots = 0.01; // Lot Size
input int TpPoints = 50; // Take Profit in points [m5-50p, h1-200p]
input ENUM_TIMEFRAMES IchimokuTimeFrame = PERIOD_CURRENT; // Timeframe (will use current timeframe)
// ---- Ichimoku Inputs ----
input int TenkanPeriod = 9; // Tenkan-sen Period
input int KijunPeriod = 26; // Kijun-sen Period
input int SenkouSpanBPeriod = 52; // Senkou Span B Period
input int Displacement = 26; // Displacement
// ---- Stochastic Inputs ----
input int StochasticKPeriod = 14; // %K period
input int StochasticDPeriod = 3; // %D period
input int StochasticSlowing = 3; // Slowing for the Stochastic
// ---- Parabolic SAR Inputs ----
input double SARStep = 0.02; // Parabolic SAR Step
input double SARMaximum = 0.2; // Parabolic SAR Maximum
// ---- RSI Inputs ----
input int RsiPeriods = 18; // RSI Period
input ENUM_APPLIED_PRICE RsiAppPrice = PRICE_CLOSE; // RSI Applied Price
input double RsiSellTrigger = 70; // RSI Overbought Level
input double RsiBuyTrigger = 30; // RSI Oversold Level
// ---- GLOBAL VARIABLES ----
double Tenkan[], Kijun[], SenkouSpanA[], SenkouSpanB[], Chikou[];
double StochasticK[], StochasticD[], SAR[], rsi[];
CTrade trade;
int OnInit()
{
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
// Copy Ichimoku Data
if(CopyBuffer(iIchimoku(_Symbol, IchimokuTimeFrame, TenkanPeriod, KijunPeriod, SenkouSpanBPeriod), 0, 0, 1, Tenkan) < 0) return;
if(CopyBuffer(iIchimoku(_Symbol, IchimokuTimeFrame, TenkanPeriod, KijunPeriod, SenkouSpanBPeriod), 1, 0, 1, Kijun) < 0) return;
if(CopyBuffer(iIchimoku(_Symbol, IchimokuTimeFrame, TenkanPeriod, KijunPeriod, SenkouSpanBPeriod), 2, 0, 1, SenkouSpanA) < 0) return;
if(CopyBuffer(iIchimoku(_Symbol, IchimokuTimeFrame, TenkanPeriod, KijunPeriod, SenkouSpanBPeriod), 3, 0, 1, SenkouSpanB) < 0) return;
// Copy Stochastic Data
if(CopyBuffer(iStochastic(_Symbol, IchimokuTimeFrame, StochasticKPeriod, StochasticDPeriod, StochasticSlowing, MODE_SMA), 0, 0, 1, StochasticK) < 0) return;
if(CopyBuffer(iStochastic(_Symbol, IchimokuTimeFrame, StochasticKPeriod, StochasticDPeriod, StochasticSlowing, MODE_SMA), 1, 0, 1, StochasticD) < 0) return;
// Copy Parabolic SAR Data
if(CopyBuffer(iSAR(_Symbol, IchimokuTimeFrame, SARStep, SARMaximum), 0, 0, 1, SAR) < 0) return;
// Copy RSI Data
if(CopyBuffer(iRSI(_Symbol, IchimokuTimeFrame, RsiPeriods, RsiAppPrice), 0, 0, 1, rsi) < 0) return;
// SELL Signal
if(Tenkan[0] < Kijun[0] && bid < SenkouSpanA[0] &&
StochasticK[0] > StochasticD[0] && StochasticK[0] > 80 &&
bid > SAR[0] && rsi[0] > RsiSellTrigger)
{
if(!PositionSelect(_Symbol)) // Check if there is no existing position
{
Print(__FUNCTION__, " > SELL Signal...");
trade.Sell(Lots);
}
}
// BUY Signal
else if(Tenkan[0] > Kijun[0] && bid > SenkouSpanA[0] &&
StochasticK[0] < StochasticD[0] && StochasticK[0] < 20 &&
bid < SAR[0] && rsi[0] < RsiBuyTrigger)
{
if(!PositionSelect(_Symbol)) // Check if there is no existing position
{
Print(__FUNCTION__, " > BUY Signal...");
trade.Buy(Lots);
}
}
// Position Management: Check open positions and handle Take Profit
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
ulong posTicket = PositionGetTicket(i);
if(PositionSelectByTicket(posTicket))
{
ENUM_POSITION_TYPE posType = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
double posOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
double profitPoints = (posType == POSITION_TYPE_BUY) ?
(bid - posOpenPrice) / _Point : (posOpenPrice - ask) / _Point;
if(profitPoints > TpPoints)
trade.PositionClose(posTicket);
}
}
// Display Data
Comment("\nTenkan-sen: ", DoubleToString(Tenkan[0], 5),
"\nKijun-sen: ", DoubleToString(Kijun[0], 5),
"\nSenkou Span A: ", DoubleToString(SenkouSpanA[0], 5),
"\nSenkou Span B: ", DoubleToString(SenkouSpanB[0], 5),
"\nPoints to TP (Buy): ", (bid - PositionGetDouble(POSITION_PRICE_OPEN)) / _Point,
"\nPoints to TP (Sell): ", (PositionGetDouble(POSITION_PRICE_OPEN) - ask) / _Point);
}
Alterações e Melhorias:
Verificação de Posição Existente: O EA agora verifica se já existem posições abertas antes de abrir novas ordens. Isso minimizará entradas indesejadas.
Cópia de Indicadores: Adicionei verificações para garantir que a cópia dos buffers dos indicadores seja realizada com sucesso.
Ajustes na Lógica de Closing: Melhorei a lógica de fechamento de posições baseando-me na diferença de pontos em vez de apenas calcular o lucro baseado na abertura.
Condições de Sinal de Negócio: Modifiquei a lógica para assegurar que só uma negociação é aberta em uma direção enquanto não houver posições abertas.
Teste e Ajustes:
Certifique-se de que as condições no código atendem à sua estratégia específica.
Teste o EA em uma conta demo primeiro para garantir que ele se comporte como esperado antes de utilizar em uma conta real.
Se encontrar dificuldades na execução ou problemas adicionais, fique à vontade para perguntar!