2026-01-19 20:11:05 -03:00
//+------------------------------------------------------------------+
//| robo-parcialInvertida.mq5 |
2026-01-19 20:13:59 -03:00
//| Copyright 2024, MetaQuotes Ltd. |
2026-01-19 20:11:05 -03:00
//| https://www.mql5.com |
//+------------------------------------------------------------------+
2026-01-19 20:13:59 -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 [ ] ;
bool fezParcialInvertida = false ;
2026-01-19 20:11:05 -03:00
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
2026-01-19 20:13:59 -03:00
int OnInit ( ) {
//--- create timer
EventSetTimer ( 60 ) ;
ArraySetAsSeries ( rates , true ) ;
return ( INIT_SUCCEEDED ) ;
}
2026-01-19 20:11:05 -03:00
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
2026-01-19 20:13:59 -03:00
void OnDeinit ( const int reason ) {
//--- destroy timer
EventKillTimer ( ) ;
2026-01-19 20:11:05 -03:00
2026-01-19 20:13:59 -03:00
}
2026-01-19 20:11:05 -03:00
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
2026-01-19 20:13:59 -03:00
void OnTick ( ) {
CopyRates ( Symbol ( ) , Period ( ) , 0 , 3 , rates ) ;
if ( PositionsTotal ( ) = = 0 & & OrdersTotal ( ) = = 0 ) {
trade . Sell ( 1000.00 , Symbol ( ) , 0 , 50 , 0 , " parcial invertida " ) ;
}
if ( PositionsTotal ( ) = = 0 & & ! fezParcialInvertida ) {
fezParcialInvertida = realizaParcialInvertida ( rates [ 0 ] . close ) ;
}
}
bool realizaParcialInvertida ( double preco ) {
for ( int i = ( PositionsTotal ( ) -1 ) ; i > = 0 ; i - - ) {
string symbol = PositionGetSymbol ( i ) ;
if ( Symbol ( ) = = symbol ) {
ulong ticket = PositionGetTicket ( i ) ;
double precoEntrada = PositionGetDouble ( POSITION_PRICE_OPEN ) ,
p = MathAbs ( precoEntrada - preco ) ,
p2 = NormalizeDouble ( ( ( precoEntrada - preco ) / _Point ) , Digits ) ,
pontos = NormalizeDouble ( ( MathAbs ( precoEntrada - preco ) / _Point ) , Digits ) ;
Comment ( p + " \n " + pontos + " \n " + p2 ) ;
if ( pontos > = 40 ) {
return trade . PositionClosePartial ( ticket , 500 , 0 ) ;
}
}
}
return false ;
}
//+------------------------------------------------------------------+
//| 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 ) { }
2026-01-19 20:11:05 -03:00
//+------------------------------------------------------------------+