// ---- 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
Para corrigir o código do Expert Advisor (EA) que você forneceu, precisamos garantir que as condições de entrada e saída para as ordens estejam sendo verificados corretamente e que o EA esteja manejando posições de forma eficaz.
Aqui está uma versão revisada do seu EA, que inclui melhorias e correções. Certifique-se de que as chamadas de função, como trade.Buy() e trade.Sell(), sejam executadas apenas uma vez, sem repetição desnecessária.
mql5
//+------------------------------------------------------------------+
//| AI Ichimoku Scalper.mq5|
//| Alfr5d |
//| https://www.49design.co.za |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, Alfred Mandala."
#property description "www.billionairebulls.co.za\n"
#property version "1.6"
#property description "Ichimoku Scalping EA, RSI Integrated, TIMEFRAME = M5\nLOW RISK SETTINGS"
#include <Trade/Trade.mqh>
// ---- 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
// ---- 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 ----
int handleIchimoku, handleStochastic, handleSAR, handleRsi;
double Tenkan[], Kijun[], SenkouSpanA[], SenkouSpanB[], Chikou[];
double StochasticK[], StochasticD[], SAR[], rsi[];
CTrade trade;
int barsTotal;
// ---- EXPERT INIT ----
int OnInit()
{
handleIchimoku = iIchimoku(_Symbol, Period(), TenkanPeriod, KijunPeriod, SenkouSpanBPeriod);
handleStochastic = iStochastic(_Symbol, Period(), StochasticKPeriod, StochasticDPeriod, StochasticSlowing, MODE_SMA, STO_LOWHIGH);
handleSAR = iSAR(_Symbol, Period(), SARStep, SARMaximum);
handleRsi = iRSI(_Symbol, Period(), RsiPeriods, RsiAppPrice);
return(INIT_SUCCEEDED);
}
// ---- EXPERT DEINIT ----
void OnDeinit(const int reason)
{
IndicatorRelease(handleIchimoku);
IndicatorRelease(handleStochastic);
IndicatorRelease(handleSAR);
IndicatorRelease(handleRsi);
}
// ---- ON TICK FUNCTION ----
void OnTick()
{
int bars = iBars(_Symbol, Period());
if (barsTotal != bars)
{
barsTotal = bars;
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
// Copy Ichimoku Data
CopyBuffer(handleIchimoku, 0, 0, 1, Tenkan); // Tenkan-sen
CopyBuffer(handleIchimoku, 1, 0, 1, Kijun); // Kijun-sen
CopyBuffer(handleIchimoku, 2, 0, 1, SenkouSpanA); // Senkou Span A
CopyBuffer(handleIchimoku, 3, 0, 1, SenkouSpanB); // Senkou Span B
CopyBuffer(handleIchimoku, 4, 0, 1, Chikou); // Chikou Span
// Copy Stochastic Data
CopyBuffer(handleStochastic, 0, 0, 1, StochasticK); // %K
CopyBuffer(handleStochastic, 1, 0, 1, StochasticD); // %D
// Copy Parabolic SAR Data
CopyBuffer(handleSAR, 0, 0, 1, SAR);
// Copy RSI Data
CopyBuffer(handleRsi, 0, 0, 1, rsi);
ManageOrders(bid, ask);
}
}
void ManageOrders(double bid, double ask)
{
int buyOrders = 0;
int sellOrders = 0;
for (int i = 0; i < PositionsTotal(); i++)
{
ulong posTicket = PositionGetTicket(i);
if (PositionSelectByTicket(posTicket))
{
ENUM_POSITION_TYPE posType = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
if (posType == POSITION_TYPE_BUY)
buyOrders++;
else if (posType == POSITION_TYPE_SELL)
sellOrders++;
}
}
// SELL Signal based on Ichimoku, Stochastic, Parabolic SAR, and RSI
if (Tenkan[0] < Kijun[0] && bid < SenkouSpanA[0] &&
StochasticK[0] > StochasticD[0] && StochasticK[0] > 80 &&
bid > SAR[0] && rsi[0] > RsiSellTrigger && sellOrders == 0)
{
Print(__FUNCTION__, " > SELL Signal...");
trade.Sell(Lots);
}
// BUY Signal based on Ichimoku, Stochastic, Parabolic SAR, and RSI
else if (Tenkan[0] > Kijun[0] && bid > SenkouSpanA[0] &&
StochasticK[0] < StochasticD[0] && StochasticK[0] < 20 &&
bid < SAR[0] && rsi[0] < RsiBuyTrigger && buyOrders == 0)
{
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);
int points = (posType == POSITION_TYPE_BUY) ?
(int)((bid - posOpenPrice) / _Point) :
(int)((posOpenPrice - ask) / _Point);
if (points > 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),
"\nChikou: ", DoubleToString(Chikou[0], 5),
"\nStochastic %K: ", DoubleToString(StochasticK[0], 5),
"\nStochastic %D: ", DoubleToString(StochasticD[0], 5),
"\nParabolic SAR: ", DoubleToString(SAR[0], 5),
"\nRSI: ", DoubleToString(rsi[0], 5));
}
Principais correções e melhorias
Condições de Execução de Ordem: As condições de compra e venda agora garantem que não existam ordens abertas da mesma direção antes de abrir uma nova ordem. Isso foi feito com as variáveis buyOrders e sellOrders.
Lógica de Fechamento de Ordens: O gerenciamento da posição agora checa as ordens abertas e as fecha corretamente quando o lucro alvo (TpPoints) é alcançado.
Impressão de Dados: A função Comment exibe todas as informações relevantes durante a execução do EA.
Considerações Finais
Teste o EA em um ambiente de demonstração antes de executar em contas reais para garantir que ele se comporta conforme esperado.
Certifique-se de que seu corretor permite a execução de EAs e que as configurações de lote e risco estejam adequadas ao seu perfil de trading.