//+------------------------------------------------------------------+
//| AI RSI BB SCALPER.mq5 |
//| Alfr5d |
//| https://www.49design.co.za |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, Alfred Mandala."
#property description "www.billionairebulls.co.za\n"
#property version "1.7"
#property description "RSI GRID SCALPING EA with Stochastic Confirmation"
#include <Trade\Trade.mqh> // Inclua a biblioteca de Trade
// ---- INPUTS ----
input group "--- Trading Inputs ---";
input double Lots = 0.01; // Tamanho do lote
input int TpPoints = 50; // Take Profit em pontos
input ENUM_TIMEFRAMES RsiTimeFrame = PERIOD_CURRENT; // Timeframe
input group "--- RSI Inputs ---";
input int RsiPeriods = 18; // Período do RSI
input ENUM_APPLIED_PRICE RsiAppPrice = PRICE_CLOSE; // Preço aplicado para RSI
input double RsiSellTrigger = 70; // Zona de Venda do RSI
input double RsiBuyTrigger = 30; // Zona de Compra do RSI
input group "--- Stochastic Inputs ---";
input int StochKPeriod = 14; // Período %K
input int StochDPeriod = 3; // Período %D
input int StochSlowing = 3; // Atraso
input double StochOverbought = 80; // Estocástico sobrecomprado
input double StochOversold = 20; // Estocástico sobrevendido
input group "--- Bollinger Bands Inputs ---";
input int BbPeriods = 23; // Período das Bandas de Bollinger
input double BbDeviation = 2.0; // Desvio padrão
input double BbShift = 0; // Deslocamento
// ---- GLOBAL VARIABLES ----
int handleRsi;
int handleStoch;
int handleBb;
double rsi[];
double stochMain[];
double stochSignal[];
CTrade trade; // Declarando a variável trade
int barsTotal;
// ---- EXPERT INIT ----
int OnInit()
{
handleRsi = iRSI(_Symbol, RsiTimeFrame, RsiPeriods, RsiAppPrice);
handleStoch = iStochastic(_Symbol, RsiTimeFrame, StochKPeriod, StochDPeriod, StochSlowing, MODE_SMA, PRICE_CLOSE); // Correção do tipo de preço
handleBb = iBands(_Symbol, PERIOD_CURRENT, BbPeriods, 0, BbDeviation, PRICE_CLOSE);
return(INIT_SUCCEEDED);
}
// ---- EXPERT DEINIT ----
void OnDeinit(const int reason)
{
IndicatorRelease(handleBb);
IndicatorRelease(handleStoch);
IndicatorRelease(handleRsi);
}
// ---- ON TICK FUNCTION ----
void OnTick()
{
int bars = iBars(_Symbol, RsiTimeFrame);
if (barsTotal != bars)
{
barsTotal = bars;
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double bbUpper[], bbLower[];
CopyBuffer(handleBb, 1, 0, 1, bbUpper);
CopyBuffer(handleBb, 2, 0, 1, bbLower);
CopyBuffer(handleRsi, 0, 1, 2, rsi);
CopyBuffer(handleStoch, 0, 1, 2, stochMain);
CopyBuffer(handleStoch, 1, 1, 2, stochSignal);
// Verificação de sinal de venda
if (rsi[1] > RsiSellTrigger && rsi[0] < RsiSellTrigger &&
stochMain[0] > StochOverbought && stochMain[1] <= StochOverbought)
{
if (bid >= bbUpper[0])
{
Print(__FUNCTION__, " > Sinal de VENDA...");
trade.Sell(Lots);
}
}
// Verificação de sinal de compra
else if (rsi[1] < RsiBuyTrigger && rsi[0] > RsiBuyTrigger &&
stochMain[0] < StochOversold && stochMain[1] >= StochOversold)
{
if (bid <= bbLower[0])
{
Print(__FUNCTION__, " > Sinal de COMPRA...");
trade.Buy(Lots);
}
}
}
// Loop para posições abertas e aplicação de stop loss dinâmico
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 stopLossLevel = 0;
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
// Cálculo de stop loss dinâmico para posições de COMPRA
if (posType == POSITION_TYPE_BUY)
{
stopLossLevel = posOpenPrice - (TpPoints * _Point);
if (bid <= stopLossLevel)
{
Print("A posição de compra atingiu o stop loss dinâmico. Fechando...");
trade.PositionClose(posTicket);
}
}
// Cálculo de stop loss dinâmico para posições de VENDA
else if (posType == POSITION_TYPE_SELL)
{
stopLossLevel = posOpenPrice + (TpPoints * _Point);
if (ask >= stopLossLevel)
{
Print("A posição de venda atingiu o stop loss dinâmico. Fechando...");
trade.PositionClose(posTicket);
}
}
}
}
// Lógica adicional para fechar posições quando a meta de pontos é atingida
int pointsBuy = 0;
int pointsSell = 0;
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 bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
if (posType == POSITION_TYPE_BUY)
{
pointsBuy += (int)((bid - posOpenPrice) / _Point);
}
else if (posType == POSITION_TYPE_SELL)
{
pointsSell += (int)((posOpenPrice - ask) / _Point);
}
}
}
// Fechar posições quando excederem a meta de pontos
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);
if (pointsBuy > TpPoints)
{
if (posType == POSITION_TYPE_BUY)
{
trade.PositionClose(posTicket);
}
}
if (pointsSell > TpPoints)
{
if (posType == POSITION_TYPE_SELL)
{
trade.PositionClose(posTicket);
}
}
}
}
// Exibir os valores atuais do RSI e do Estocástico
Comment("\nRSI[0]: ", DoubleToString(rsi[0], 5),
"\nRSI[1]: ", DoubleToString(rsi[1], 5),
"\nStoch Main: ", DoubleToString(stochMain[0], 5),
"\nStoch Signal: ", DoubleToString(stochSignal[0], 5),
"\nPontos de Compra: ", pointsBuy,
"\nPontos de Venda: ", pointsSell);
}
//+------------------------------------------------------------------+
erro:
'AI RSI BB SCALPER_MESA_PRO_FIRM_V4.mq5' 1
Trade.mqh
Object.mqh
StdLibErr.mqh
OrderInfo.mqh
HistoryOrderInfo.mqh
PositionInfo.mqh
DealInfo.mqh
'PRICE_CLOSE' - cannot convert enum AI RSI BB SCALPER_MESA_PRO_FIRM_V4.mq5 53 107
built-in: int iStochastic(const string,ENUM_TIMEFRAMES,int,int,int,ENUM_MA_METHOD,ENUM_STO_PRICE) AI RSI BB SCALPER_MESA_PRO_FIRM_V4.mq5 53 107
1 errors, 0 warnings 2 1