mt5-clear-wing26-scalper/WinFutLib/WinFutFiatLibs.mqh
2026-01-19 20:37:51 -03:00

266 satır
20 KiB
MQL5

//+------------------------------------------------------------------+
//| FiatLibs.mqh |
//| Copyright 2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link "https://www.mql5.com"
//+------------------------------------------------------------------+
//| defines |
//+------------------------------------------------------------------+
// #define MacrosHello "Hello, world!"
// #define MacrosYear 2010
//+------------------------------------------------------------------+
//| DLL imports |
//+------------------------------------------------------------------+
// #import "user32.dll"
// int SendMessageA(int hWnd,int Msg,int wParam,int lParam);
// #import "my_expert.dll"
// int ExpertRecalculate(int wParam,int lParam);
// #import
//+------------------------------------------------------------------+
//| EX5 imports |
//+------------------------------------------------------------------+
// #import "stdlib.ex5"
// string ErrorDescription(int error_code);
// #import
//+------------------------------------------------------------------+
//--- service objects
CTrade trade;
MqlRates rates[];
CTrade ExtTrade;
CSymbolInfo ExtSymbolInfo;
//##############################################
//#constantes definidas para uso em todo o robo#
//##############################################
#define SIGNAL_BUY 1 // Buy signal
#define SIGNAL_NOT 0 // no trading signal
#define SIGNAL_SELL -1 // Sell signal
#define CLOSE_LONG 2 // signal to close Long
#define CLOSE_SHORT -2 // signal to close Short
#define TAMANHO_LOTE 5
#define ROBO_NAME "Robo Fiat147-Oggi-WINQ24"
#define ROBO_VERSION "v1.0.0"
//##############################################################
//#variaveis globais #
//##############################################################
//--- global variables
int ExtAvgBodyPeriod, // average candlestick calculation period
ExtSignalOpen =0, // Buy/Sell signal
ExtSignalClose =0, // signal to close a position
ExtIndicatorHandle=INVALID_HANDLE,
ExtTrendMAHandle =INVALID_HANDLE;
bool ExtPatternDetected=false, // pattern detected
ExtConfirmed =false, // pattern confirmed
ExtCloseByTime =true, // requires closing by time
ExtCheckPassed =true; // status checking error
double maxAtual = 0.00,
minAtual = 0.00,
maxPrev = 0.00,
minPrev = 0.00,
openAtual = 0.00,
closeAtual = 0.00,
amplitudeCandle = 0.00,
entrada = 0.00,
tamanhoLote = 2, //WinFut
pontoFiboProfit = 1.618,
takeProfit = 0.00;
string dataIntraday = NULL,
ExtPatternInfo ="", // current pattern information
ExtDirection =""; // position opening direction
//##############################################################
//#variaveis de input de parametros para o grafico #
//##############################################################
//--- Input parameters
input int InpAverBodyPeriod = 12; // period for calculating average candlestick size
input int InpMAPeriod = 5; // Trend MA period
input int InpPeriodRSI = 37; // RSI period
input int InpPeriodCCI = 37; // CCI period
input int InpPeriodMFI = 37; // MFI period
input int InpStochK = 47; // period %K
input int InpStochD = 9; // period %D
input int InpStochSlow = 13; // smoothing period %K
input ENUM_STO_PRICE InpStochApplied = STO_LOWHIGH; // calculation type
input ENUM_MA_METHOD InpStochMA = MODE_SMA; // smoothing type
input ENUM_APPLIED_PRICE InpPrice = PRICE_CLOSE; // price type
input ENUM_APPLIED_VOLUME InpVolume = VOLUME_TICK; // volume type
//--- trade parameters
input uint InpDuration=10; // position holding time in bars
input uint InpSL =200; // Stop Loss in points
input uint InpTP =400; // Take Profit in points
input uint InpSlippage=10; // slippage in points
//--- money management parameters
input double InpLot = TAMANHO_LOTE; // lot
//--- Expert ID
input long InpMagicNumber=120700; // Magic Number
//##############################################################
//#funcao que ir centralizar todas as msg de saida para o chart#
//##############################################################
void setMsgChart(string pMsg=NULL) {
//comment imprime msg no chart
Comment(pMsg);
//print imprime msg nos logs da caixa de ferramentas
Print(pMsg);
//abre uma caixa de msgDialog
//Alert(pMsg);
}
void initMsgChart() {
string msg = ROBO_NAME + "-" + ROBO_VERSION;
Comment(msg);
Print(msg);
}
//################################################################
//#funcoes genericas ultilizadas por todas as estrategias do robo#
//################################################################
//+------------------------------------------------------------------+
//| Checks position closing time in bars |
//+------------------------------------------------------------------+
int BarsHold(datetime open_time) {
//--- first run a basic simple check
if(TimeCurrent()-open_time<PeriodSeconds(_Period))
{
//--- opening time is inside the current bar
return(0);
}
//---
MqlRates bars[];
if(CopyRates(_Symbol, _Period, open_time, TimeCurrent(), bars)==-1)
{
Print("Error. CopyRates() failed, error = ", GetLastError());
return(-1);
}
//--- check position holding time in bars
return(ArraySize(bars));
}
//+------------------------------------------------------------------+
//| Returns the open price of the specified bar |
//+------------------------------------------------------------------+
double Open(int index) {
double val=iOpen(_Symbol, _Period, index);
//--- if the current check state was successful and an error was received
if(ExtCheckPassed && val==0)
ExtCheckPassed=false; // switch the status to failed
return(val);
}
//+------------------------------------------------------------------+
//| Returns the close price of the specified bar |
//+------------------------------------------------------------------+
double Close(int index) {
double val=iClose(_Symbol, _Period, index);
//--- if the current check state was successful and an error was received
if(ExtCheckPassed && val==0)
ExtCheckPassed=false; // switch the status to failed
return(val);
}
//+------------------------------------------------------------------+
//| Returns the low price of the specified bar |
//+------------------------------------------------------------------+
double Low(int index) {
double val=iLow(_Symbol, _Period, index);
//--- if the current check state was successful and an error was received
if(ExtCheckPassed && val==0)
ExtCheckPassed=false; // switch the status to failed
return(val);
}
//+------------------------------------------------------------------+
//| Returns the high price of the specified bar |
//+------------------------------------------------------------------+
double High(int index) {
double val=iHigh(_Symbol, _Period, index);
//--- if the current check state was successful and an error was received
if(ExtCheckPassed && val==0)
ExtCheckPassed=false; // switch the status to failed
return(val);
}
//+------------------------------------------------------------------+
//| Returns the middle body price for the specified bar |
//+------------------------------------------------------------------+
double MidPoint(int index) {
return(High(index)+Low(index))/2.;
}
//+------------------------------------------------------------------+
//| Returns the middle price of the range for the specified bar |
//+------------------------------------------------------------------+
double MidOpenClose(int index) {
return((Open(index)+Close(index))/2.);
}
//+------------------------------------------------------------------+
//| Returns the average candlestick body size for the specified bar |
//+------------------------------------------------------------------+
double AvgBody(int index) {
double sum=0;
for(int i=index; i<index+ExtAvgBodyPeriod; i++) {
sum+=MathAbs(Open(i)-Close(i));
}
return(sum/ExtAvgBodyPeriod);
}
//+------------------------------------------------------------------+
//| SMA value at the specified bar |
//+------------------------------------------------------------------+
double CloseAvg(int index) {
double indicator_values[];
if(CopyBuffer(ExtTrendMAHandle, 0, index, 1, indicator_values)<0) {
//--- if the copying fails, report the error code
PrintFormat("Failed to copy data from the Simple Moving Average indicator, error code %d", GetLastError());
return(EMPTY_VALUE);
}
return(indicator_values[0]);
}
//+------------------------------------------------------------------+