Para adaptar o código do robô de scalping que você forneceu, garantindo que ele funcione bem com o par de moedas Bitcoin (BTC), algumas modificações são necessárias. Os pares de criptomoedas, como BTC, geralmente exigem uma configuração diferente, especialmente em relação ao tamanho do lote, pontos de lucro, e gerenciamento de risco.
Aqui estão as alterações que você deve considerar:
-
Adaptar a taxa de pontos (Pip) para criptomoeda: O BTC normalmente é cotado até 2 casas decimais em muitos pares, então você deve garantir que suas configurações de preços estejam em conformidade.
-
Verificar a precisão do ponto: A precisão do símbolo para BTC pode diferir do padrão. É importante usar a função SymbolInfoInteger para definir o número correto de dígitos.
-
Modificar a configuração de stop loss e take profit: A forma como o stop loss (SL) e o take profit (TP) são definidos pode precisar de ajustes baseados na volatilidade do BTC.
Aqui está o código atualizado, incorporando essas modificações. Verifique se as entradas estão adequadas para o seu estilo de trading e ajuste as porcentagens conforme necessário:
//+------------------------------------------------------------------+
//| Scalping Robot |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#include <Trade/Trade.mqh>
CTrade trade;
CPositionInfo pos;
COrderInfo ord;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
input group "*** Trading Inputs ***"
input double LotSize = 0.01; // Lot size for trading
input double Tppoints = 600.0; // Take Profit (600.0 = 600 pontos em BTC)
input double Slpoints = 300.0; // Stoploss Points (300.0 = 300 pontos em BTC)
input double TslTriggerPoints = 35.0; // Points in profit before Trailing SL is activated (35.0 = 35 pontos em BTC)
input double TslPoints = 10.0; // Trailing Stoploss (10.0 = 10 pontos em BTC)
input ENUM_TIMEFRAMES Timeframe = PERIOD_CURRENT; // Time frame to run
input int InpMagic = 891245; // EA identification no
input string TradeComment = "Wendel Cassiano";
input double MaxSpread = 100.0; // Maximum spread allowed (100.0 = 100 pontos)
input double Slippage = 5.0; // Slippage in points
input int MaxOrders = 2; // Maximum simultaneous open orders
enum StarHour { Inactive=0, _0100=1, _0200=2, _0300=3, _0400=4, _0500=5, _0600=6, _0700=7, _0800=8, _0900=9, _1000=10, _1100=11, _1200=12, _1300=13, _1400=14, _1500=15, _1600=16, _1700=17, _1800=18, _1900=19, _2000=20, _2100=21, _2200=22, _2300=23 };
input StarHour SHInput = 0; // Start Hour
enum EndHour { Inactive=0, _0100=1, _0200=2, _0300=3, _0400=4, _0500=5, _0600=6, _0700=7, _0800=8, _0900=9, _1000=10, _1100=11, _1200=12, _1300=13, _1400=14, _1500=15, _1600=16, _1700=17, _1800=18, _1900=19, _2000=20, _2100=21, _2200=22, _2300=23 };
input EndHour EHInput = 0; // End Hour
int SHChoice;
int EHChoice;
int BarsN = 5;
int ExpirationBars = 100;
double OrderDistPoints = 100; // 100 pontos
int OnInit()
{
//---
trade.SetExpertMagicNumber(InpMagic);
ChartSetInteger(0, CHART_SHOW_GRID, false);
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
TrailStop();
if (!IsNewBar()) return;
MqlDateTime time;
TimeToStruct(TimeCurrent(), time);
int Hournow = time.hour;
SHChoice = SHInput;
EHChoice = EHInput;
if (Hournow < SHChoice) { CloseAllOrders(); return; }
if (Hournow >= EHChoice && EHChoice != 0) { CloseAllOrders(); return; }
double spread = (SymbolInfoDouble(_Symbol, SYMBOL_ASK) - SymbolInfoDouble(_Symbol, SYMBOL_BID)) / _Point;
if (spread > MaxSpread) return;
int BuyTotal = 0;
int SellTotal = 0;
for (int i = PositionsTotal() - 1; i >= 0; i--)
{
pos.SelectByIndex(i);
if (pos.PositionType() == POSITION_TYPE_BUY && pos.Symbol() == _Symbol && pos.Magic() == InpMagic) BuyTotal++;
if (pos.PositionType() == POSITION_TYPE_SELL && pos.Symbol() == _Symbol && pos.Magic() == InpMagic) SellTotal++;
}
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
ord.SelectByIndex(i);
if (ord.OrderType() == ORDER_TYPE_BUY_STOP && ord.Symbol() == _Symbol && ord.Magic() == InpMagic) BuyTotal++;
if (ord.OrderType() == ORDER_TYPE_SELL_STOP && ord.Symbol() == _Symbol && ord.Magic() == InpMagic) SellTotal++;
}
int TotalOrders = BuyTotal + SellTotal;
if (TotalOrders >= MaxOrders) return;
if (BuyTotal <= 0)
{
double high = findHigh();
if (high > 0)
{
SendBuyOrder(high);
}
}
if (SellTotal <= 0)
{
double low = findLow();
if (low > 0)
{
SendSellOrder(low);
}
}
}
//+------------------------------------------------------------------+
double findHigh()
{
double highestHigh = 0;
for (int i = 0; i < 200; i++)
{
double high = iHigh(_Symbol, Timeframe, i);
if (i > BarsN && iHighest(_Symbol, Timeframe, MODE_HIGH, BarsN * 2 + 1, i - BarsN) == i)
{
if (high > highestHigh)
{
return high;
}
}
highestHigh = MathMax(high, highestHigh);
}
return -1;
}
double findLow()
{
double LowestLow = DBL_MAX;
for (int i = 0; i < 200; i++)
{
double Low = iLow(_Symbol, Timeframe, i);
if (i > BarsN && iLowest(_Symbol, Timeframe, MODE_LOW, BarsN * 2 + 1, i - BarsN) == i)
{
if (Low < LowestLow)
{
return Low;
}
}
LowestLow = MathMin(Low, LowestLow);
}
return -1;
}
bool IsNewBar()
{
static datetime previousTime = 0;
datetime currentTime = iTime(_Symbol, Timeframe, 0);
if (previousTime != currentTime)
{
previousTime = currentTime;
return true;
}
return false;
}
void SendBuyOrder(double entry)
{
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
if (ask > entry - OrderDistPoints * _Point) return;
double tp = entry + Tppoints * _Point;
double sl = entry - Slpoints * _Point;
// Use configured lot size
double lots = LotSize;
datetime expiration = iTime(_Symbol, Timeframe, 0) + ExpirationBars * PeriodSeconds(Timeframe);
trade.BuyStop(lots, entry, _Symbol, sl, tp, ORDER_TIME_SPECIFIED, expiration, Slippage);
}
void SendSellOrder(double entry)
{
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
if (bid < entry + OrderDistPoints * _Point) return;
double tp = entry - Tppoints * _Point;
double sl = entry + Slpoints * _Point;
// Use configured lot size
double lots = LotSize;
datetime expiration = iTime(_Symbol, Timeframe, 0) + ExpirationBars * PeriodSeconds(Timeframe);
trade.SellStop(lots, entry, _Symbol, sl, tp, ORDER_TIME_SPECIFIED, expiration, Slippage);
}
double calcLots(double slPoints)
{
// Return the configured lot size
return LotSize;
}
void CloseAllOrders()
{
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
ord.SelectByIndex(i);
ulong ticket = ord.Ticket();
if (ord.Symbol() == _Symbol && ord.Magic() == InpMagic)
{
trade.OrderDelete(ticket);
}
}
}
void TrailStop()
{
double sl = 0;
double tp = 0;
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
for (int i = PositionsTotal() - 1; i >= 0; i--)
{
if (pos.SelectByIndex(i))
{
ulong ticket = pos.Ticket();
if (pos.Magic() == InpMagic && pos.Symbol() == _Symbol)
{
if (pos.PositionType() == POSITION_TYPE_BUY)
{
if (bid - pos.PriceOpen() > TslTriggerPoints * _Point)
{
tp = pos.TakeProfit();
sl = bid - (TslPoints * _Point);
if (sl > pos.StopLoss() && sl != 0)
{
trade.PositionModify(ticket, sl, tp);
}
}
}
else if (pos.PositionType() == POSITION_TYPE_SELL)
{
if (ask + (TslTriggerPoints * _Point) < pos.PriceOpen())
{
tp = pos.TakeProfit();
sl = ask + (TslPoints * _Point);
if (sl < pos.StopLoss() && sl != 0)
{
trade.PositionModify(ticket, sl, tp);
}
}
}
}
}
}
}
O que mudou
- Tppoints e Slpoints: Agora são definidos em valores de ponto, que precisam ser ajustados conforme a volatilidade do BTC.
- OrderDistPoints: A utilização também foi mudada para que funcione bem com BTC. O valor padrão é mantido em 100 pontos, mas você pode ajustar conforme necessário.
SymbolInfoDouble: Usado para garantir que os preços para SL e TP estejam nas ordens corretas, conforme a profundidade do mercado.
Certifique-se de testar o sistema em um ambiente de demonstração antes de aplicá-lo em conta real, e faça ajustes conforme necessário para otimizar seu desempenho.