2026-01-19 19:56:16 -03:00
//+------------------------------------------------------------------+
//| robo-insideBarFibo.mq5 |
2026-01-19 19:58:10 -03:00
//| Copyright 2024, MetaQuotes Ltd. |
2026-01-19 19:56:16 -03:00
//| https://www.mql5.com |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
2026-01-19 19:58:10 -03:00
# property copyright " Copyright 2024, MetaQuotes Ltd. "
# property link " https://www.mql5.com "
# property version " 1.00 "
# include <Trade\Trade.mqh>
CTrade trade ;
MqlRates rates [ ] ;
int OnInit ( ) {
//--- create timer
EventSetTimer ( 60 ) ;
ArraySetAsSeries ( rates , true ) ;
return ( INIT_SUCCEEDED ) ;
}
2026-01-19 19:56:16 -03:00
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
2026-01-19 19:58:10 -03:00
void OnDeinit ( const int reason ) { EventKillTimer ( ) ; }
2026-01-19 19:56:16 -03:00
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
2026-01-19 19:58:10 -03:00
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 ( maxPrev > maxAtual & & minPrev < minAtual ) {
//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 ) ) ;
tp = ( entrada + ( amplitudeCandle + pontoFiboProfit ) * _Point ) ;
trade . BuyStop ( tamanhoLote , entrada , Symbol ( ) , minAtual , tp , 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 ) ) ;
tp = ( entrada - ( amplitudeCandle + pontoFiboProfit ) * _Point ) ;
trade . SellStop ( tamanhoLote , entrada , Symbol ( ) , maxAtual , tp , 0 , 0 , NULL ) ;
}
}
}
}
2026-01-19 19:56:16 -03:00
//+------------------------------------------------------------------+
2026-01-19 19:58:10 -03:00
//| 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 ) { }