Perguntas de Iniciantes MQL5 MT5 MetaTrader 5 - página 723
![MQL5 - Linguagem para estratégias de negociação inseridas no terminal do cliente MetaTrader 5](https://c.mql5.com/i/registerlandings/logo-2.png)
Você está perdendo oportunidades de negociação:
- Aplicativos de negociação gratuitos
- 8 000+ sinais para cópia
- Notícias econômicas para análise dos mercados financeiros
Registro
Login
Você concorda com a política do site e com os termos de uso
Se você não tem uma conta, por favor registre-se
As pessoas dizem-me o que estou a fazer mal, porquê dois indicadores iRSI,iCCI não causa problema, mas os muwings e BB dão um aviso (possível perda de dados devido ao indicador de conversão de tipo.mqh )
//| Indicator.mqh |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
// интерфейс к индикаторам.
class CIndicators
{
public:
double iRSI(string symbol, ENUM_TIMEFRAMES tf, int period, ENUM_APPLIED_PRICE applied, int shift);
double iCCI(string symbol, ENUM_TIMEFRAMES tf, int period, ENUM_APPLIED_PRICE applied, int shift);
double iBands(string symbol,ENUM_TIMEFRAMES tf,int BBPeriod,int shift,double BBDeviation,ENUM_APPLIED_PRICE BBPrice );
double iMA(string symbol,ENUM_TIMEFRAMES tf, int nMAPeriod,int shift, ENUM_MA_METHOD eMAMethod ,ENUM_APPLIED_PRICE MAPrice);
};
// -Создадим экземпляр индикатора iRSI
double CIndicators::iRSI(string symbol, ENUM_TIMEFRAMES tf, int period, ENUM_APPLIED_PRICE applied, int shift)
{
//---
int hRSI = iRSI(symbol, tf, period, applied);
if(hRSI == INVALID_HANDLE)
return 0.0;
double rsi[];
CopyBuffer(hRSI, 0, shift, 1, rsi);
if(ArraySize(rsi))
return rsi[0];
return 0.0;
//--Создадим экземпляр индикатора iCCI
}
//----------------------------------
double CIndicators::iCCI(string symbol, ENUM_TIMEFRAMES tf, int period, ENUM_APPLIED_PRICE applied, int shift)
{
int hCCI = iCCI(Symbol(), PERIOD_CURRENT, 55, PRICE_CLOSE);
if(hCCI == INVALID_HANDLE)return 0.0;
double cci[];
ArrayResize(cci, 1);
CopyBuffer(hCCI, 0, 0, 1, cci);
return cci[0];
}
//--------------------------------------------------
// Создадим экземпляр индикатора ВВ
double CIndicators::iBands(string symbol,ENUM_TIMEFRAMES tf,int BBPeriod,int shift,double BBDeviation,ENUM_APPLIED_PRICE BBPrice)
{
int hBands = iBands(Symbol(),tf,BBPeriod,0,BBDeviation,PRICE_CLOSE);
if(hBands==INVALID_HANDLE)return 0.0;
// Создадим массив значений верхней границы ВВ
double fBBUpper[];
ArrayResize(fBBUpper,true);
CopyBuffer(hBands,UPPER_BAND,0,3,fBBUpper);
return fBBUpper[0];
// Создадим массив значений нижней границы ВВ
double fBBLower[];
ArraySetAsSeries(fBBLower,true);
CopyBuffer(hBands,LOWER_BAND,0,3,fBBLower);
return fBBLower[0];
}
// Создадим экземпляр индикатора МА
double CIndicators::iMA(string symbol,ENUM_TIMEFRAMES tf, int nMAPeriod,int shift, ENUM_MA_METHOD eMAMethod ,ENUM_APPLIED_PRICE MAPrice)
{
// получим его хэндл
int hMA=iMA(Symbol(), PERIOD_CURRENT, nMAPeriod,0,MODE_EMA,PRICE_CLOSE);
if(hMA == INVALID_HANDLE)return 0.0;
// Создадим массив значений МА,заполним тремя последними значениями мувинга.
double fMA[];
ArraySetAsSeries(fMA,true);
CopyBuffer(hMA,0,0,3,fMA);
return fMA[0];
}
Gostaria também de perguntar: O que devo alterar no pedido comercial, o erro 10030 apareceu, no ano anterior o código do Expert Advisor funcionou sem problemas, e agora faz-me ler/pesquisar por alterações na MQL5 novamente
// функция открытия позиции с рынка
bool MarketOrder(const string sSymbol, const ENUM_POSITION_TYPE eType, const double fLot, const int nSL = 0, const int nTP = 0, const ulong nMagic = 0, const uint nSlippage = 1000)
{
bool bRetVal = false;
// запрос
MqlTradeRequest oRequest = {0};
MqlTradeResult oResult = {0};
double fPoint = SymbolInfoDouble(sSymbol, SYMBOL_POINT);
int nDigits = (int) SymbolInfoInteger(sSymbol, SYMBOL_DIGITS);
oRequest.action = TRADE_ACTION_DEAL;
oRequest.symbol = sSymbol;
oRequest.volume = fLot;
oRequest.stoplimit = 0;
oRequest.deviation = nSlippage;
if(eType == POSITION_TYPE_BUY)
{
oRequest.type = ORDER_TYPE_BUY;
oRequest.price = NormalizeDouble(SymbolInfoDouble(sSymbol, SYMBOL_ASK), nDigits);
oRequest.sl = NormalizeDouble(oRequest.price - nSL * fPoint, nDigits) * (nSL > 0);
oRequest.tp = NormalizeDouble(oRequest.price + nTP * fPoint, nDigits) * (nTP > 0);
}
if(eType == POSITION_TYPE_SELL)
{
oRequest.type = ORDER_TYPE_SELL;
oRequest.price = NormalizeDouble(SymbolInfoDouble(sSymbol, SYMBOL_BID), nDigits);
oRequest.sl = NormalizeDouble(oRequest.price + nSL * fPoint, nDigits) * (nSL > 0);
oRequest.tp = NormalizeDouble(oRequest.price - nTP * fPoint, nDigits) * (nTP > 0);
}
// определим допустимый тип заливки ордера (зависит от типа исполнения - Instant, Market, биржевое и т.д.)
switch((int) SymbolInfoInteger(sSymbol, SYMBOL_FILLING_MODE))
{
case SYMBOL_FILLING_FOK:
oRequest.type_filling = ORDER_FILLING_FOK;
break;
case SYMBOL_FILLING_IOC:
oRequest.type_filling = ORDER_FILLING_IOC;
break;
default:
oRequest.type_filling = ORDER_FILLING_RETURN;
}
oRequest.magic = nMagic;
// проверка перед отправкой
MqlTradeCheckResult oCheckResult= {0};
bool bCheck = OrderCheck(oRequest, oCheckResult);
Print("Проверка заявки MarketOrder:",
" OrderCheck = ", bCheck,
", retcode = ", oCheckResult.retcode,
", balance = ", NormalizeDouble(oCheckResult.balance, 2),
", equity = ", NormalizeDouble(oCheckResult.equity, 2),
", margin = ", NormalizeDouble(oCheckResult.margin, 2),
", margin_free = ", NormalizeDouble(oCheckResult.margin_free, 2),
", margin_level = ", NormalizeDouble(oCheckResult.margin_level, 2),
", comment = ", oCheckResult.comment);
// если проверка удачная - отправка заявки
if(bCheck == true && oCheckResult.retcode == 0)
{
bool bResult = false;
// 3 попытки выставления ордера
for(int k = 0; k < 3; k++)
{
bResult = OrderSend(oRequest, oResult);
if(bResult == true && oResult.retcode == TRADE_RETCODE_DONE)
break;
if(k == 2)
break;
Sleep(100);
}
Print("Отправка заявки:",
" OrderSend = ", bResult,
", retcode = ", oResult.retcode,
", deal = ", oResult.deal,
", order = ", oResult.order,
", volume = ", NormalizeDouble(oResult.volume, 2),
", price = ", NormalizeDouble(oResult.price, _Digits),
", bid = ", NormalizeDouble(oResult.bid, _Digits),
", ask = ", NormalizeDouble(oResult.ask, _Digits),
", comment = ", oResult.comment,
", request_id = ",oResult.request_id);
if(oResult.retcode == TRADE_RETCODE_DONE)
bRetVal = true;
}
else if(oResult.retcode == TRADE_RETCODE_NO_MONEY)
{
Print("Недостаточно денег для открытия позиции. Работа эксперта прекращена.");
ExpertRemove();
}
return(bRetVal);
}
E também queria perguntar: O que deve ser alterado no pedido comercial, há um erro 10030 , anteriormente o código do Expert Advisor funcionava sem problemas e agora obriga-me novamente a ler/pesquisar por alterações na MQL5
// функция открытия позиции с рынка
bool MarketOrder(const string sSymbol, const ENUM_POSITION_TYPE eType, const double fLot, const int nSL = 0, const int nTP = 0, const ulong nMagic = 0, const uint nSlippage = 1000)
{
bool bRetVal = false;
// запрос
MqlTradeRequest oRequest = {0};
MqlTradeResult oResult = {0};
double fPoint = SymbolInfoDouble(sSymbol, SYMBOL_POINT);
int nDigits = (int) SymbolInfoInteger(sSymbol, SYMBOL_DIGITS);
oRequest.action = TRADE_ACTION_DEAL;
oRequest.symbol = sSymbol;
oRequest.volume = fLot;
oRequest.stoplimit = 0;
oRequest.deviation = nSlippage;
if(eType == POSITION_TYPE_BUY)
{
oRequest.type = ORDER_TYPE_BUY;
oRequest.price = NormalizeDouble(SymbolInfoDouble(sSymbol, SYMBOL_ASK), nDigits);
oRequest.sl = NormalizeDouble(oRequest.price - nSL * fPoint, nDigits) * (nSL > 0);
oRequest.tp = NormalizeDouble(oRequest.price + nTP * fPoint, nDigits) * (nTP > 0);
}
if(eType == POSITION_TYPE_SELL)
{
oRequest.type = ORDER_TYPE_SELL;
oRequest.price = NormalizeDouble(SymbolInfoDouble(sSymbol, SYMBOL_BID), nDigits);
oRequest.sl = NormalizeDouble(oRequest.price + nSL * fPoint, nDigits) * (nSL > 0);
oRequest.tp = NormalizeDouble(oRequest.price - nTP * fPoint, nDigits) * (nTP > 0);
}
// определим допустимый тип заливки ордера (зависит от типа исполнения - Instant, Market, биржевое и т.д.)
switch((int) SymbolInfoInteger(sSymbol, SYMBOL_FILLING_MODE))
{
case SYMBOL_FILLING_FOK:
oRequest.type_filling = ORDER_FILLING_FOK;
break;
case SYMBOL_FILLING_IOC:
oRequest.type_filling = ORDER_FILLING_IOC;
break;
default:
oRequest.type_filling = ORDER_FILLING_RETURN;
}
oRequest.magic = nMagic;
// проверка перед отправкой
MqlTradeCheckResult oCheckResult= {0};
bool bCheck = OrderCheck(oRequest, oCheckResult);
Print("Проверка заявки MarketOrder:",
" OrderCheck = ", bCheck,
", retcode = ", oCheckResult.retcode,
", balance = ", NormalizeDouble(oCheckResult.balance, 2),
", equity = ", NormalizeDouble(oCheckResult.equity, 2),
", margin = ", NormalizeDouble(oCheckResult.margin, 2),
", margin_free = ", NormalizeDouble(oCheckResult.margin_free, 2),
", margin_level = ", NormalizeDouble(oCheckResult.margin_level, 2),
", comment = ", oCheckResult.comment);
// если проверка удачная - отправка заявки
if(bCheck == true && oCheckResult.retcode == 0)
{
bool bResult = false;
// 3 попытки выставления ордера
for(int k = 0; k < 3; k++)
{
bResult = OrderSend(oRequest, oResult);
if(bResult == true && oResult.retcode == TRADE_RETCODE_DONE)
break;
if(k == 2)
break;
Sleep(100);
}
Print("Отправка заявки:",
" OrderSend = ", bResult,
", retcode = ", oResult.retcode,
", deal = ", oResult.deal,
", order = ", oResult.order,
", volume = ", NormalizeDouble(oResult.volume, 2),
", price = ", NormalizeDouble(oResult.price, _Digits),
", bid = ", NormalizeDouble(oResult.bid, _Digits),
", ask = ", NormalizeDouble(oResult.ask, _Digits),
", comment = ", oResult.comment,
", request_id = ",oResult.request_id);
if(oResult.retcode == TRADE_RETCODE_DONE)
bRetVal = true;
}
else if(oResult.retcode == TRADE_RETCODE_NO_MONEY)
{
Print("Недостаточно денег для открытия позиции. Работа эксперта прекращена.");
ExpertRemove();
}
return(bRetVal);
}
Eu escreveria o destacado da seguinte forma:
Eu escreveria o destacado desta forma:
Do fundo do meu coração...!!! )
Funcionou, funcionou!
Obrigado Alexei!!!!!!!!!!!!!!
Bom dia. Pode sugerir um EA para MT5? Pode sugerir um EA com uma paragem de percurso? De preferênciaum SCALPER ou um que funcione com NOVIDADES ou outro . Obrigado de antemão.
Por favor explique como instalar o indicador adquirido no terminal, porque o comprei, mas não o consigo activar, não sei qual é o problema?
Esclareça: comprou no Market?
Após a compra, cliquei em "Instalar no terminal" e depois fui para o terminal comercial, mas nada aconteceu, o indicador não apareceu