204 lines
14 KiB
MQL5
204 lines
14 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| robo-InsideOutsideBarFibo.mq5 |
|
|
//| Copyright 2024, MetaQuotes Ltd. |
|
|
//| httakeProfits://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2024, MetaQuotes Ltd."
|
|
#property link "httakeProfits://www.mql5.com"
|
|
#property version "1.00"
|
|
|
|
#include <Trade\Trade.mqh>
|
|
|
|
CTrade trade;
|
|
MqlRates rates[];
|
|
|
|
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 = 0.02,
|
|
pontoFiboProfit = 1.618,
|
|
takeProfit = 0.00;
|
|
|
|
int OnInit() {
|
|
//--- create timer
|
|
EventSetTimer(60);
|
|
ArraySetAsSeries(rates, true);
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Expert deinitialization function |
|
|
//+------------------------------------------------------------------+
|
|
void OnDeinit(const int reason) { EventKillTimer(); }
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Expert tick function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTick() {
|
|
|
|
/**
|
|
* obtem dados de rates do grafico para que a partir dele
|
|
* agente tenha condicoes de saber se esta acontecendo um
|
|
* insideBar ou outsideBar
|
|
*/
|
|
getRatesBar();
|
|
}
|
|
|
|
|
|
/***********************
|
|
* function getRatesBar *
|
|
************************/
|
|
void getRatesBar() {
|
|
CopyRates(Symbol(), Period(), 0, 3, rates);
|
|
maxAtual = rates[1].high;
|
|
minAtual = rates[1].low;
|
|
maxPrev = rates[2].high;
|
|
minPrev = rates[2].low;
|
|
openAtual = rates[1].open;
|
|
closeAtual = rates[1].close;
|
|
|
|
/**
|
|
* estrutura de boletagem para insideBar
|
|
*/
|
|
if(maxPrev > maxAtual && minPrev < minAtual) {
|
|
insideBar();
|
|
}
|
|
/**
|
|
* estrutura de boletagem para outsideBar
|
|
*/
|
|
if(maxAtual > maxPrev && minAtual < minPrev) {
|
|
outsideBar();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*********************
|
|
* function insideBar *
|
|
**********************/
|
|
void insideBar() {
|
|
|
|
//obtendo a amplitude do candle
|
|
amplitudeCandle = ((MathAbs(minAtual - maxAtual) / _Point));
|
|
|
|
//operacao de compra
|
|
if(closeAtual > openAtual) {
|
|
ObjectCreate(0, "insideBar=>"+IntegerToString(rates[1].time), OBJ_ARROW_BUY, 0, rates[1].time, rates[1].low);
|
|
if(PositionsTotal() == 0 && OrdersTotal() == 0 ) {
|
|
entrada = (maxAtual + (10 * _Point));
|
|
takeProfit = (entrada + (amplitudeCandle + pontoFiboProfit) * _Point);
|
|
trade.BuyStop(tamanhoLote, entrada, Symbol(), minAtual, takeProfit, 0, 0, NULL);
|
|
}
|
|
}
|
|
|
|
//operacao de venda
|
|
if(closeAtual < openAtual) {
|
|
ObjectCreate(0, "insideBar=>"+IntegerToString(rates[1].time), OBJ_ARROW_DOWN, 0, rates[1].time, rates[1].high);
|
|
if(PositionsTotal() == 0 && OrdersTotal() == 0 ) {
|
|
entrada = (minAtual - (10 * _Point));
|
|
takeProfit = (entrada - (amplitudeCandle + pontoFiboProfit) * _Point);
|
|
trade.SellStop(tamanhoLote, entrada, Symbol(), maxAtual, takeProfit, 0, 0, NULL);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*********************
|
|
* function outsideBar *
|
|
**********************/
|
|
void outsideBar() {
|
|
|
|
//obtendo a amplitude do candle
|
|
amplitudeCandle = ((MathAbs(minAtual - maxAtual) / _Point));
|
|
|
|
//operacao de compra
|
|
if(closeAtual > openAtual) {
|
|
ObjectCreate(0, "outside"+IntegerToString(rates[1].time), OBJ_ARROW_BUY, 0, rates[1].time, rates[1].low);
|
|
if(PositionsTotal() == 0 && OrdersTotal() == 0 ) {
|
|
entrada = (maxAtual + (10 * _Point));
|
|
takeProfit = (entrada + (amplitudeCandle + pontoFiboProfit) * _Point);
|
|
trade.BuyStop(tamanhoLote, entrada, Symbol(), minAtual, takeProfit, 0, 0, NULL);
|
|
}
|
|
}
|
|
|
|
//operacao de venda
|
|
if(closeAtual < openAtual) {
|
|
ObjectCreate(0, "outside"+IntegerToString(rates[1].time), OBJ_ARROW_DOWN, 0, rates[1].time, rates[1].high);
|
|
if(PositionsTotal() == 0 && OrdersTotal() == 0 ) {
|
|
entrada = (minAtual - (10 * _Point));
|
|
takeProfit = (entrada - (amplitudeCandle + pontoFiboProfit) * _Point);
|
|
trade.SellStop(tamanhoLote, entrada, Symbol(), maxAtual, takeProfit, 0, 0, NULL);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* function para mostrar painel exibindo todas as informações em modo
|
|
* debugger igual ja existe no robo adxpsar_v4;
|
|
*/
|
|
void showDisplay() { }
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Timer function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTimer() {}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Trade function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTrade() {}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| TradeTransaction function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTradeTransaction(const MqlTradeTransaction& trans, const MqlTradeRequest& request, const MqlTradeResult& result) {}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Tester function |
|
|
//+------------------------------------------------------------------+
|
|
double OnTester() { double ret=0.0; return(ret); }
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| TesterInit function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTesterInit() {}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| TesterPass function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTesterPass() {}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| TesterDeinit function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTesterDeinit() {}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| ChartEvent function |
|
|
//+------------------------------------------------------------------+
|
|
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) {}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| BookEvent function |
|
|
//+------------------------------------------------------------------+
|
|
void OnBookEvent(const string &symbol) {}
|
|
|
|
|