This repository has been archived on 2026-01-19. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
robo-InsideOutsideBarFibo/robo-outsideBarFibo/robo-outsideBarFibo.mq5
2026-01-19 20:09:07 -03:00

142 lines
5.6 KiB
MQL5

//+------------------------------------------------------------------+
//| robo-outsideBarFibo.mq5 |
//| Copyright 2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
#include <Trade\Trade.mqh>
CTrade trade;
MqlRates rates[];
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() {
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,
tp = 0.00;
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;
if(maxAtual > maxPrev && minAtual < minPrev) {
//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));
tp = (entrada + (amplitudeCandle + pontoFiboProfit) * _Point);
trade.BuyStop(tamanhoLote, entrada, Symbol(), minAtual, tp, 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));
tp = (entrada - (amplitudeCandle + pontoFiboProfit) * _Point);
trade.SellStop(tamanhoLote, entrada, Symbol(), maxAtual, tp, 0, 0, NULL);
}
}
}
}
//+------------------------------------------------------------------+
//| 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) { }