Connect/CONNECT.mq5

1011 行
59 KiB
MQL5

2025-05-30 14:47:12 +02:00
<EFBFBD><EFBFBD>
#property copyright "Copyright <00> 2022, %""
#property link "https://t.me/mo_elnoby"
//#property version "3.4.2" // "0:0O 25@A8O =5A>2<5AB8<0 A MQL-<0@:5B><
#property description "CONNECT EA"
#property description "MAKE SURE YOU HAVE BROKER WITH LOWER SPREAD TO WORK WELL"
#property description "PAIRS: GBPUSD,USDCHF,USDCAD,USDJPY"
#property description "TF: M5"
#property description "UNL"
//#property strict
//#property icon "\\Images\\CONNECT.ico"
#define BANDS_PERIOD 20
#define BANDS_MA_SHIFT 0
#define BANDS_DEVIATION 2.0
#define BANDS_APPLIED_PRICE PRICE_MEDIAN
#define MA_PERIOD 20
#define ATR_PERIOD 14
#include <Indicators\Trend.mqh> // :;NG05<K9 D09;, =5>1E>48< 4;O 8=48:0B>@0 iBands
#include <Indicators\Oscilators.mqh> // :;NG05<K9 D09;, =5>1E>48< 4;O 8=48:0B>@0 iAtr
#include <Indicators\Trend.mqh> // :;NG05<K9 D09;, =5>1E>48< 4;O 8=48:0B>@0 iMA
#include <Trade\Trade.mqh> // :;NG05<K9 D09;, =5>1E>48< 4;O B>@3>2>3> ?@>F5AA>@0.
//------------------
input string FULL = "UNL"; // FULL
input string SETTINGS = "CONNECT EA";
input string TF = "M5";
input string CURRENCY = "GBPUSD,USDCHF,USDCAD,USDJPY";
input uint uiIBandsPeriod = BANDS_PERIOD; // B.Bands Period
input int iIBandsMaShift = BANDS_MA_SHIFT; // B.Bands MA Shift
input double dIBandsDeviation = BANDS_DEVIATION; // B.Bands Deviation
input ENUM_APPLIED_PRICE apIBandsPrice = BANDS_APPLIED_PRICE; // B.Bands Applied Price
input bool bIUseATR = true; // A?>;L7>20BL ;8 ATR(14) 4;O D8;LB@0
input bool bIUseMA = true; // A?>;L7>20BL ;8 MA(20) 4;O D8;LB@0
input double Lots=0.01 ; // FIXED LOT
input bool UseRisk=true ; // USE RISK
input double MaxRisk=2 ; //RISK
input int StopLoss=65 ; // SL
input int TakeProfit=20 ; // TP
input double MaxSpread=5 ; // MAX SPREAD
input int MaxSlippage=1 ; // MAX SLIPPAGE (int)
input uint HourStart=22 ;
input uint HourEnd=1 ;
input int Magic = 1;
int Magic2 = Magic ;
string DATA_1_st = "CONNECT EA";
double d45QuotesRatio = 1.0; // A;8 :>B8@>2:8 G5BK@QE7=0G=K5, B> >AB0QBAO 1, 5A;8 :>B8@>2:8 ?OB87=0G=K5 - AB028BAO 10.
string DATA_4_st = "\n";
int iDigits = 4;
int DATA_6_in = 0;
int DATA_7_in = 0;
double dMaxRisk = 1.0;
int DATA_9_in = 0;
int DATA_10_in = 0;
int DATA_11_in = 0;
datetime DATA_12_da = 0;
string Ai_1 = "2022.07.07";
static const int MIN_AVAILIBLE_BARS = 10;
string ErrorDescription( int mu_0_in)
{
return(" " + IntegerToString(mu_0_in));
};
// G5@54=>9 B8:
MqlTick mtLastTick;
// K1@0==K9 B8:5B ?>78F88 MT5
ulong ulSelectedPosTicket;
ulong ulSelectedHistoryPosTicket;
// =48:0B>@K, 8A?>;L7C5<K5 2 M:A?5@B5.
CiBands ibBands;
CiATR iaATR;
CiMA imMA;
// ">@3>2K9 ?@>F5AA>@
CTrade tTradeProcessor;
// ><5=B 2K7>20 DC=:F88 HistorySelect
datetime dtHistorySelectMoment;
// $C=:F8O ?@5>1@07>20=8O 25;8G8=K long 2 25;8G8=C int A ?@>25@:>9 480?07>=0 8 C40;5=8O M:A?5@B0 A 3@0D8:0, 2 A;CG05 53> ?@52KH5=8O
int _Long2Int(long lValue)
{
if(lValue < INT_MIN || lValue > INT_MAX)
{
Print("52>7<>6=> ?@5>1@07>20BL long-7=0G5=85 " + IntegerToString(lValue) + " : ?@54AB02;5=8N int. -:A?5@B >AB0=>2;5=.");
ExpertRemove();
};
return((int)lValue);
}
// $C=:F8O, ?@OGCI0O 2A5 8=48:0B>@K
// =0;>3 HideTestIndicators() "4
void _HideTestIndicators(bool bFlag)
{
#ifdef __MQL5__
// Print(" "5 8=48:0B>@K ?>:0 =5 A:@K20NBAO. TODO: =0?8A0BL DC=:F8N _HideTestIndicators(bool bFlag)" );
#else // __MQL5__
_HideTestIndicators(bFlag);
#endif // __MQL5__
};
// $C=:F8O, 2>72@0I0NI0O G8A;> 10@>2 =0 B5:CI5< 3@0D8:5
// =0;>3 Bars "4
int _Bars()
{
#ifdef __MQL5__
int iRes = Bars(Symbol(),Period());
if(iRes <= NULL || iRes >= INT_MAX)
{
Print("H81:0 DC=:F88 Bars(), ?@8 70?@>A5 :>;8G5AB20 10@>2 =0 G0@B5, 25@=C;>AL:" + IntegerToString(iRes));
Print("GetLastError() = " + IntegerToString(GetLastError()));
};
return(iRes);
#else // __MQL5__
return(Bars);
#endif // __MQL5__
};
// $C=:F88 2>72@0I0NI85 Bid 8 Ask ?>A;54=59 :>B8@>2:8
// =0;>3 ?5@5<5==KE 2 "4
double _Bid()
{
#ifdef __MQL5__
return(mtLastTick.bid);
#else // __MQL5__
return(Bid);
#endif // __MQL5__
};
double _Ask()
{
#ifdef __MQL5__
return(mtLastTick.ask);
#else // __MQL5__
return(Ask);
#endif // __MQL5__
};
#define MODE_LOTSIZE 15
#define MODE_MINLOT 23
#define MODE_MAXLOT 25
// =0;>3 DC=:F88 _MarketInfo
double _MarketInfo(string strSymbol,int iInfoID)
{
switch(iInfoID)
{
case MODE_LOTSIZE: return(SymbolInfoDouble(strSymbol,SYMBOL_TRADE_CONTRACT_SIZE));
case MODE_MINLOT: return(SymbolInfoDouble(strSymbol,SYMBOL_VOLUME_MIN));
case MODE_MAXLOT: return(SymbolInfoDouble(strSymbol,SYMBOL_VOLUME_MAX));
default:
break;
};
return(EMPTY_VALUE);
};
// =0;>3 DC=:F88 AccountFreeMargin()
double _AccountFreeMargin()
{
return(AccountInfoDouble(ACCOUNT_MARGIN_FREE));
};
// $C=:F8O 2>72@0I05B 40==K5 8=48:0B>@0 ?> C:070==><C 1CDD5@C (=C;52>9 8=45:A)
double _iBands(int iBuffer)
{
// ><5@0 1CDD5@>2 ;5=B >;;8=465@0:
// 1 - 25@E=OO
// 2 - =86=OO
double dRes = ibBands.GetData(iBuffer,0);
return(dRes);
};
// $C=:F8O 2>72@0I0NI0O 40==K5 8=48:0B>@0 ATR
double _iATR()
{
double dRes = iaATR.GetData(0,0);
if(bIUseATR == false)
dRes = NULL;
return(dRes);
};
// $C=:F8O 2>72@0I0NI0O 40==K5 8=48:0B>@0 MA
double _iMA()
{
double dRes = imMA.GetData(0,0);
return(dRes);
}
// $C=:F8O 2>72@0I05B G0A 87 C:070==>9 40BK
uint _TimeHour(datetime dtFrom)
{
MqlDateTime mdtTime;
if(TimeToStruct(dtFrom,mdtTime)!=true)
return(UINT_MAX);
return(mdtTime.hour);
};
// $C=:F8O-0=0;>3 DC=:F88 OrdersTotal() 87 MT4 4;O >B:@KBKE >@45@>2
int _OrdersTotal()
{
return(PositionsTotal());
};
// $C=:F8O-0=0;>3 DC=:F88 OrderSelect(SELECT_BY_POS) 87 MT4
// 0 2E>4 ?5@5405BAO 8=45:A >B:@KB>9 ?>78F88 MT5 2 A?8A:5. @8 CA?5E5 2>72@0I05BAO true
bool _OrderSelectByPos(uint uiPosIdx)
{
ulSelectedPosTicket = PositionGetTicket(uiPosIdx);
if(ulSelectedPosTicket == NULL)
return(false);
return(true);
};
// $C=:F8O-0=0;>3 DC=:F88 OrderSelect(SELECT_BY_TICKET) 87 MT4 4;O >B:@KBKE >@45@>2.
// 0 2E>4 ?5@5405BAO 8=45:A >B:@KB>9 ?>78F88 MT5 2 A?8A:5. @8 CA?5E5 2>72@0I05BAO true
bool _OrderSelectByTicket(uint uiTicket)
{
if(PositionSelectByTicket(uiTicket)==true)
{
ulSelectedPosTicket = uiTicket;
return(true);
};
ulSelectedPosTicket = NULL;
return(false);
};
// $C=:F8O-0=0;>3 DC=:F88 OrderSymbol 87 MT4
// >72@0I05B AB@>:C-A8<2>; 2K1@0==>3> >@45@0
string _OrderSymbol()
{
string strRes = PositionGetString(POSITION_SYMBOL);
return(strRes);
};
// $C=:F8O-0=0;>3 DC=:F88 OrderMagicNumber 87 MT4
long _OrderMagicNumber()
{
long lRes = PositionGetInteger(POSITION_MAGIC);
return(lRes);
};
// $C=:F8O-0=0;>3 DC=:F88 OrderOpenPrice 87 MT4
double _OrderOpenPrice()
{
return(PositionGetDouble(POSITION_PRICE_OPEN));
};
// $C=:F8O-0=0;>3 DC=:F88 OrderLots 87 MT4
double _OrderLots()
{
return(PositionGetDouble(POSITION_VOLUME));
};
// $C=:F8O-0=0;>3 DC=:F88 OrdersTotal() 87 MT4 4;O 8AB>@8G5A:8E >@45@>2
int _OrdersHistoryTotal()
{
return(HistoryDealsTotal());
};
#define OT_BUY 0
#define OT_SELL 1
// $C=:F8O-0=0;>3 DC=:F88 OrderType 87 MT4
int _OrderType()
{
ENUM_POSITION_TYPE ptType = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
switch(ptType)
{
case POSITION_TYPE_BUY: return(0);
case POSITION_TYPE_SELL: return(1);
default:
break;
};
return(WRONG_VALUE);
};
// $C=:F8O-0=0;>3 DC=:F88 OrderOpenTime 87 MT4
datetime _OrderOpenTime()
{
return((datetime)PositionGetInteger(POSITION_TIME));
};
// $C=:F8O-0=0;>3 DC=:F88 OrderTicket 87 MT4
ulong _OrderTicket()
{
return(ulSelectedPosTicket);
};
// $C=:F8O, ?>4<5=ONI0O (=5 0=0;>3!) DC=:F8N _OrderClosePrice 87 MT4
// 0==0O DC=:F8O ?@54=07=0G5=0 4;O >?@545;5=8O F5=K 70:@KB8O 8AB>@8G5A:8E >@45@>2.
// 4=0:>, 2 40==>< A;CG05 >?@545;O5BAO F5=0 70:@KB8O >B:@KB>3> >@45@0 - GB> =5 5ABL 4>:C<5=B8@>20==0O 2>7<>6=>ABL.
// A?>;L7C5< Bid 8;8 Ask 4;O >B:@KB>3> >@45@0
double _OrderClosePrice()
{
if(_OrderType() == 1)
return(_Ask());
return(_Bid());
};
// $C=:F8O ?>;CG05B B8:5B >B:@KB>9 ?>78F88 ?> 5Q 845=B8D8:0B>@C
long _GetOpenedComponentTicket(ulong ulDealID)
{
long lPosID = WRONG_VALUE;
// K15@5< A45;:C 2 8AB>@88 ?> 845=B8D8:0B>@C
if(HistoryDealSelect(ulDealID)!=true)
{
Print("ERROR !!! 5 C40;>AL 2K1@0BL 2 8AB>@88 A45;:C, DealID = " + IntegerToString(ulDealID));
return(WRONG_VALUE);
};
// K18@05< PosID B>;L:> GB> >B:@KB>9 A45;:8
if(HistoryDealGetInteger(ulDealID,DEAL_POSITION_ID,lPosID)!=true)
{
Print("ERROR !!! 5 C40;>AL ?>;CG8BL PosID A45;:8! GetLastError: " + IntegerToString(GetLastError()));
return(WRONG_VALUE);
};
int iPosNum = PositionsTotal();
ulong ulCurTicket = 0;
// 5@518@05< 2A5 ?>78F88
for(int iI=0; iI<iPosNum; ++iI)
{
// K18@05< >G5@54=CN ?>78F8N, 8 ?>;CG05< 55 B8:5B
ulCurTicket = PositionGetTicket(iI);
if(ulCurTicket == NULL)
continue;
// @>25@O5< PosID
if(PositionGetInteger(POSITION_IDENTIFIER)!= lPosID)
continue;
// C6=0O ?>78F8O =0945=0 !
return((long)ulCurTicket);
};
Print("ERROR !!! A5 A45;:8 ?5@51@0;8, => =5 =0H;8 =C6=CN! GetLastError: " + IntegerToString(GetLastError()));
return(WRONG_VALUE);
};
#define OP_BUY 0
#define OP_SELL 1
// =0;>3 DC=:F88 OrderSend MT4
int _OrderSend(string strSymbol,int iOrderType,double dVolume,double dPrice,int iSlippage,double dSL,double dTP,string strComment = NULL,int iMagic = NULL,datetime dtExpiration = NULL,color clrColor = clrNONE)
{
// >65< 2KAB02;OBL B>;L:> >@45@0 =0 ?>:C?:C 8;8 ?@>406C. @>25@8< MB>
switch(iOrderType)
{
case OP_BUY:
if(tTradeProcessor.Buy(dVolume,strSymbol,dPrice,dSL,dTP,strComment)!=true)
return(WRONG_VALUE);
break;
case OP_SELL:
if(tTradeProcessor.Sell(dVolume,strSymbol,dPrice,dSL,dTP,strComment)!=true)
return(WRONG_VALUE);
break;
default:
return(WRONG_VALUE);
};
if(tTradeProcessor.ResultRetcode()!= TRADE_RETCODE_DONE)
return(WRONG_VALUE);
Print(">78F8O >B:@KB0. ResultDeal()= " + IntegerToString(tTradeProcessor.ResultDeal()));
return((int)_GetOpenedComponentTicket(tTradeProcessor.ResultDeal()));
};
// $C=:F8O-0=0;>3 OrderModify() 2 "4
bool _OrderModify(int iTicket,double dOpenPrice,double dSL,double dTP,datetime dtExpiration,color clrColor)
{
return(tTradeProcessor.PositionModify(iTicket,dSL,dTP));
};
// $C=:F8O 70:@K205B >@45@ ?> C:070==><C B8:5BC
bool _OrderClose(ulong ulTicket,double dLots,double dPrice, int iSlippage,color clrColor)
{
if(_OrderSelectByTicket((uint)ulTicket)!=true)
return(false);
double dUseLots = _OrderLots();
if(dLots >= dUseLots )
return(tTradeProcessor.PositionClose(ulTicket,iSlippage));
return(tTradeProcessor.PositionClosePartial(ulTicket,dLots,iSlippage));
};
// $C=:F8O-0=0;>3 DC=:F88 OrderSelect(SELECT_BY_TICKET) 87 MT4 4;O 8AB>@8G5A:8E >@45@>2.
// 0 2E>4 ?5@5405BAO 8=45:A >B:@KB>9 ?>78F88 MT5 2 A?8A:5. @8 CA?5E5 2>72@0I05BAO true
bool _HstOrderSelectByPos(uint uiPosIdx)
{
ulSelectedHistoryPosTicket = HistoryDealGetTicket(uiPosIdx);
if(ulSelectedHistoryPosTicket == NULL)
return(false);
ENUM_DEAL_ENTRY deDealEntry = (ENUM_DEAL_ENTRY)HistoryDealGetInteger(ulSelectedHistoryPosTicket,DEAL_ENTRY);
if(deDealEntry != DEAL_ENTRY_OUT)
{
ulSelectedHistoryPosTicket = NULL;
return(false);
};
return(true);
};
string _HstOrderSymbol()
{
return(HistoryDealGetString(ulSelectedHistoryPosTicket,DEAL_SYMBOL));
};
long _HstOrderMagicNumber()
{
return(HistoryDealGetInteger(ulSelectedHistoryPosTicket,DEAL_MAGIC));
};
double _HstOrderProfit()
{
return(HistoryDealGetDouble(ulSelectedHistoryPosTicket,DEAL_PROFIT));
};
datetime _HstOrderCloseTime()
{
return((datetime)HistoryDealGetInteger(ulSelectedHistoryPosTicket,DEAL_TIME));
};
// $C=:F8O, ?@54=07=0G5==0O 4;O >1=>2;5=8O 8=48:0B>@>2
bool _Refresh()
{
SymbolInfoTick(Symbol(),mtLastTick);
ibBands.Refresh();
iaATR.Refresh();
imMA.Refresh();
if(HistorySelect(NULL,TimeCurrent())!=true)
return(false);
dtHistorySelectMoment = TimeCurrent();
return(true);
};
int OnInit()
{
// #AB0=2;8205< G8A;> 7=0:>2 8 :>@@5:F8N 4;O :>B8@>2>:
// > C<>;G0=8N d45QuotesRatio = 1
iDigits = Digits() ;
if (iDigits == 3 || iDigits == 5)
d45QuotesRatio = 10.0 ;
dMaxRisk = MaxRisk ;
_HideTestIndicators(true);
// !>74048< 8=48:0B>@K
if(ibBands.Create(Symbol(),PERIOD_CURRENT,uiIBandsPeriod,iIBandsMaShift,dIBandsDeviation,apIBandsPrice)!=true)
{
Print("5 C40;>AL A>740BL 8=48:0B>@ iBands! 01>B0 =52>7<>6=0.");
return(WRONG_VALUE);
};
if(iaATR.Create(Symbol(),PERIOD_CURRENT,ATR_PERIOD)!=true)
{
Print("5 C40;>AL A>740BL 8=48:0B>@ iATR! 01>B0 =52>7<>6=0.");
return(WRONG_VALUE);
};
if(imMA.Create(Symbol(),PERIOD_CURRENT,MA_PERIOD,0,MODE_SMA,PRICE_MEDIAN)!=true)
{
Print("5 C40;>AL A>740BL 8=48:0B>@ iMA! 01>B0 =52>7<>6=0.");
return(WRONG_VALUE);
};
// =8F80;878@C5< B>@3>2K9 ?@>F5AA>@
tTradeProcessor.LogLevel(LOG_LEVEL_ALL);
tTradeProcessor.SetExpertMagicNumber(Magic);
tTradeProcessor.SetDeviationInPoints(MaxSlippage);
tTradeProcessor.SetMarginMode();
// >:0 ?>78F8O =5 2K1@0=0
ulSelectedPosTicket = NULL;
// >:0 8AB>@8O =5 2K18@0;0AL.
dtHistorySelectMoment = NULL;
return(0);
}
//init <<==-------- --------
void OnTick()
{
// 1=>28< 40==K5
_Refresh();
int iTotalOpenedOrders;
int iCurOrderIdx;
ChartSetInteger(ChartID(),CHART_SHOW_GRID,0);
ChartSetInteger(ChartID(),CHART_MODE,CHART_CANDLES);
_HideTestIndicators(true);
// @>25@8<, GB>1K G8A;> 4>ABC?=KE 10@>2 1K;> 1>;LH5 45AOB8.
if ( _Bars() < MIN_AVAILIBLE_BARS )
{
Comment("Not enough bars");
return;
};
// A;8 Ask =5 2KH5 25@E=59 ?>;>AK >;;8=465@0 8 ATR =5 1>;55 150 ?C=:B>2 =0 ?OB87=0:5
if ( !(_Ask()>=_iBands(2)) && !(_iATR() >=d45QuotesRatio * 15.0 * Point()))
{
// A;8 B5:CI89 G0A 2E>48B 2 ?@545;K G0A0 =0G0;0 8 G0A0 :>=F0.
if ((HourStart < HourEnd && _TimeHour(TimeCurrent()) >= HourStart && _TimeHour(TimeCurrent()) < HourEnd )||(HourStart > HourEnd && (_TimeHour(TimeCurrent()) < HourEnd || _TimeHour(TimeCurrent()) >= HourStart)))
{
// >AG8B05< >B:@KBK5 >@45@0
iTotalOpenedOrders = 0;
for (iCurOrderIdx = _OrdersTotal() - 1 ; iCurOrderIdx >= 0 ; --iCurOrderIdx)
{
if ( _OrderSelectByPos(iCurOrderIdx) == true )
{
if ( _OrderSymbol() == Symbol() && _OrderMagicNumber() == Magic )
++iTotalOpenedOrders;
}
else
{
Print("_OrderSelectByPos() error - ",ErrorDescription(GetLastError()));
};
}; // F8:; ?5@5AGQB0 >B:@KBKE >@45@>2
if ( iTotalOpenedOrders < 1 )
{
if ( UseRisk == false )
liDATA_11();
if ( UseRisk == true )
liDATA_9();
};
}; // 5A;8 B5:CI89 G0A 2E>48B 2 ?@545;K G0A0 =0G0;0 8 :>=F0
}; // A;8 Ask =5 2KH5 25@E=59 ?>;>AK >;;8=465@0 8 ATR =5 1>;55 150 ?C=:B>2 =0 ?OB87=0:5
// A;8 Bid =5 =865 =86=59 ?>;>AK >;;8=465@0 8 ATR =5 1>;55 150 ?C=:B>2 =0 ?OB87=0:5
if ( !(_Bid()<=_iBands(1)) && !(_iATR()>=d45QuotesRatio * 15.0 * Point()) )
{
// A;8 B5:CI89 G0A 2E>48B 2 ?@545;K G0A0 =0G0;0 8 G0A0 :>=F0.
if((HourStart < HourEnd && _TimeHour(TimeCurrent()) >= HourStart && _TimeHour(TimeCurrent()) < HourEnd ) || (HourStart > HourEnd && (_TimeHour(TimeCurrent()) < HourEnd || _TimeHour(TimeCurrent()) >= HourStart)))
{
iTotalOpenedOrders = 0;
for (iCurOrderIdx = _OrdersTotal() - 1 ; iCurOrderIdx >= 0 ; --iCurOrderIdx)
{
if (_OrderSelectByPos(iCurOrderIdx))
{
if ( _OrderSymbol() == Symbol() && _OrderMagicNumber() == Magic )
++iTotalOpenedOrders;
}
else
Print("OrderSend() error - ",ErrorDescription(GetLastError()));
}; // F8:; ?5@5AGQB0 >B:@KBKE >@45@>2
if ( iTotalOpenedOrders < 1 )
{
if ( UseRisk == false )
liDATA_12();
if ( UseRisk == true )
liDATA_10();
};
}; // 5A;8 B5:CI89 G0A 2E>48B 2 ?@545;K G0A0 =0G0;0 8 :>=F0
}; // A;8 Bid =5 =865 =86=59 ?>;>AK >;;8=465@0 8 ATR =5 1>;55 150 ?C=:B>2 =0 ?OB87=0:5
liDATA_7();
liDATA_8();
return;
}
//start <<==-------- --------
void OnDeinit(const int reason)
{
};
//deinit <<==-------- --------
void liDATA_7()
{
int REPUTK_1_in_si30si2[30][2];
int iTotalPos;
int REPUTK_3_in;
int iCurPos;
//----- -----
ArrayInitialize(REPUTK_1_in_si30si2,NULL); // 0?>;=O5< <0AA82 =C;O<8, 8=0G5 2KE>48B ?@54C?@5645=85
if (bIUseMA == true && _Ask()>=_iMA() )
{
return;
}
if ( _Ask() - _Bid() <=MaxSpread * d45QuotesRatio * Point() )
{
iTotalPos = _OrdersTotal() ;
REPUTK_3_in = 0 ;
for (iCurPos = 0 ; iCurPos < iTotalPos ; ++iCurPos)
{
if ( ( _OrderSelectByPos(iCurPos) && (_OrderType() != OT_SELL || _OrderSymbol() != Symbol() || _OrderMagicNumber() != Magic2) ) ) continue;
REPUTK_1_in_si30si2[REPUTK_3_in][0] = _Long2Int(_OrderOpenTime());
REPUTK_1_in_si30si2[REPUTK_3_in][1] = (int)_OrderTicket();
REPUTK_3_in = REPUTK_3_in + 1;
}
if ( REPUTK_3_in > 1 )
{
//  ! 0:><<5=B0@5=> 87<5=5=85 @07<5@0 <0AA820.
// 0AA82 AB0B8G5A:8 >?@545;Q=, =52>7<>6=> <5=OBL 53> @07<5@, 2 "4 MB0 >H81:0 =5 >B>1@060;0AL.
// 07<5@ <0AA820 2 ?5@2>< 87<5@5=88 30, 8, ?>E>65, GB> MB> <0:A8<0;L=>5 G8A;> ?>78F89.
// >;6=> E20B8BL - =5 87<5=O5< @07<5@ AB0B8G5A:>3> <0AA820.
// ArrayResize(REPUTK_1_in_si30si2,REPUTK_3_in,0);
//ArraySort(REPUTK_1_in_si30si2,0,0,1); // "0: 1K;> 2 MT4
ArraySort(REPUTK_1_in_si30si2);
}
for (iCurPos = 0 ; iCurPos < REPUTK_3_in ; ++iCurPos)
{
if (_OrderSelectByTicket(REPUTK_1_in_si30si2[iCurPos][1]) != true || _OrderClose(_OrderTicket(),_OrderLots(),_OrderClosePrice(),MaxSlippage,Red) != false ) continue;
Print("OrderClose() error - ",ErrorDescription(GetLastError()));
}
} // if ( Ask - Bid<=MaxSpread * DATA_2_do * Point() )
} // void liDATA_7()
void liDATA_8()
{
int REPUTK_1_in_si30si2[30][2];
int REPUTK_2_in;
int REPUTK_3_in;
int REPUTK_4_in;
//----- -----
ArrayInitialize(REPUTK_1_in_si30si2,NULL);
if (bIUseMA == true && _Bid()<=_iMA() )
{
return;
}
if ( _Ask() - _Bid()<=MaxSpread * d45QuotesRatio * Point() )
{
REPUTK_2_in = _OrdersTotal() ;
REPUTK_3_in = 0 ;
for (REPUTK_4_in = 0 ; REPUTK_4_in < REPUTK_2_in ; REPUTK_4_in = REPUTK_4_in + 1)
{
if ( ( _OrderSelectByPos(REPUTK_4_in) && (_OrderType() != 0 || _OrderSymbol() != Symbol() || _OrderMagicNumber() != Magic) ) ) continue;
REPUTK_1_in_si30si2[REPUTK_3_in][0] = _Long2Int(_OrderOpenTime());
REPUTK_1_in_si30si2[REPUTK_3_in][1] = (int)_OrderTicket();
REPUTK_3_in = REPUTK_3_in + 1;
}
if ( REPUTK_3_in > 1 )
{
//  ! 0:><<5=B0@5=> 87<5=5=85 @07<5@0 <0AA820.
// 0AA82 AB0B8G5A:8 >?@545;Q=, =52>7<>6=> <5=OBL 53> @07<5@, 2 "4 MB0 >H81:0 =5 >B>1@060;0AL.
// 07<5@ <0AA820 2 ?5@2>< 87<5@5=88 30, 8, ?>E>65, GB> MB> <0:A8<0;L=>5 G8A;> ?>78F89.
// >;6=> E20B8BL - =5 87<5=O5< @07<5@ AB0B8G5A:>3> <0AA820.
// ArrayResize(REPUTK_1_in_si30si2,REPUTK_3_in,0);
// ArraySort(REPUTK_1_in_si30si2,0,0,1); "0: 1K;> 2 "4
ArraySort(REPUTK_1_in_si30si2);
}
for (REPUTK_4_in = 0 ; REPUTK_4_in < REPUTK_3_in ; REPUTK_4_in = REPUTK_4_in + 1)
{
if ( _OrderSelectByTicket(REPUTK_1_in_si30si2[REPUTK_4_in][1]) != true || _OrderClose(_OrderTicket(),_OrderLots(),_OrderClosePrice(),MaxSlippage,Red) != false ) continue;
Print("OrderClose() error - ",ErrorDescription(GetLastError()));
}
}
}
//liDATA_8 <<==-------- --------
void liDATA_9()
{
double REPUTK_1_do;
double REPUTK_2_do;
double REPUTK_3_do;
double REPUTK_4_do;
double REPUTK_5_do;
double REPUTK_6_do;
int REPUTK_7_in;
double REPUTK_8_do;
double REPUTK_9_do;
int REPUTK_10_in;
bool REPUTK_11_bo = false;
//----- -----
datetime REPUT_da_1;
datetime REPUT_da_2;
int REPUT_in_3;
REPUT_da_1 = TimeCurrent();
REPUT_da_2 = 0;
if ( _OrdersHistoryTotal() > 0 )
{
for (REPUT_in_3 = _OrdersHistoryTotal() - 1 ; REPUT_in_3 >= 0 ; REPUT_in_3=REPUT_in_3 - 1)
{
if ( _HstOrderSelectByPos(REPUT_in_3) == true && _HstOrderSymbol() == Symbol() && ( _HstOrderMagicNumber() == Magic || _HstOrderMagicNumber() == Magic2 ) )
{
if ( !(_HstOrderProfit()<0.0) ) break;
REPUT_da_2 = _HstOrderCloseTime();
break;
}
}
}
else
{
REPUT_da_2 = -3600;
}
if ( REPUT_da_1 < REPUT_da_2 + 3600 || _Ask() - _Bid()>MaxSpread * d45QuotesRatio * Point() ) return;
REPUTK_1_do = _MarketInfo(Symbol(),MODE_LOTSIZE) ;
REPUTK_2_do = 1000.0 ;
REPUTK_3_do = _AccountFreeMargin() / 100.0 * dMaxRisk ;
if ( StopLoss == 0 )
{
Print("OrderSend() error - stoploss can not be zero");
}
REPUTK_4_do = REPUTK_3_do / StopLoss / d45QuotesRatio ;
REPUTK_5_do = 0.001 ;
REPUTK_6_do = _MarketInfo(Symbol(),MODE_MINLOT) ;
REPUTK_7_in = 0 ;
while (REPUTK_6_do<1.0)
{
REPUTK_6_do = REPUTK_6_do * MathPow(10.0,REPUTK_7_in) ;
REPUTK_7_in = REPUTK_7_in + 1;
}
REPUTK_5_do = NormalizeDouble(REPUTK_4_do,REPUTK_7_in - 1) ;
if ( REPUTK_5_do<_MarketInfo(Symbol(),MODE_MINLOT) )
{
REPUTK_5_do = _MarketInfo(Symbol(),MODE_MINLOT) ;
}
if ( REPUTK_5_do>_MarketInfo(Symbol(),MODE_MAXLOT) )
{
REPUTK_5_do = _MarketInfo(Symbol(),MODE_MAXLOT) ;
}
REPUTK_8_do = _Ask() - StopLoss * d45QuotesRatio * Point() ;
if ( StopLoss == 0 )
{
REPUTK_8_do = 0.0 ;
}
REPUTK_9_do = TakeProfit * d45QuotesRatio * Point() + _Ask();
if ( TakeProfit == 0 )
{
REPUTK_9_do = 0.0 ;
}
REPUTK_10_in = -1 ;
REPUTK_10_in = _OrderSend(Symbol(),OP_BUY,REPUTK_5_do,_Ask(),MaxSlippage,0.0,0.0,DATA_1_st,Magic,0,Blue);
if ( REPUTK_10_in > -1 )
{
if ( _OrderSelectByTicket(REPUTK_10_in) )
{
REPUTK_11_bo = _OrderModify((int)_OrderTicket(),_OrderOpenPrice(),REPUTK_8_do,REPUTK_9_do,0,Blue) ;
}
if ( REPUTK_11_bo != false ) return;
Print("OrderModify() error - ",ErrorDescription(GetLastError()));
return;
}
Print("OrderSend() error - ",ErrorDescription(GetLastError()));
}
//liDATA_9 <<==-------- --------
void liDATA_10()
{
double dTradeContractSize;
double REPUTK_2_do;
double REPUTK_3_do;
double REPUTK_4_do;
double REPUTK_5_do;
double REPUTK_6_do;
int REPUTK_7_in;
double REPUTK_8_do;
double REPUTK_9_do;
int REPUTK_10_in;
bool REPUTK_11_bo = false;
//----- -----
datetime REPUT_da_2;
int REPUT_in_3;
datetime dTimeCurrent = TimeCurrent();
REPUT_da_2 = 0;
if ( _OrdersHistoryTotal() > 0 )
{
for (REPUT_in_3 = _OrdersHistoryTotal() - 1 ; REPUT_in_3 >= 0 ; REPUT_in_3=REPUT_in_3 - 1)
{
if ( _HstOrderSelectByPos(REPUT_in_3) == true && _HstOrderSymbol() == Symbol() && ( _HstOrderMagicNumber() == Magic || _HstOrderMagicNumber() == Magic2 ) )
{
if ( !(_HstOrderProfit()<0.0) ) break;
REPUT_da_2 = _HstOrderCloseTime();
break;
}
}
}
else
{
REPUT_da_2 = -3600;
}
if ( dTimeCurrent < REPUT_da_2 + 3600 || _Ask() - _Bid()>MaxSpread * d45QuotesRatio * Point() ) return;
dTradeContractSize = _MarketInfo(Symbol(),MODE_LOTSIZE);
REPUTK_2_do = 1000.0 ;
REPUTK_3_do = _AccountFreeMargin() / 100.0 * dMaxRisk ;
if ( StopLoss == 0 )
{
Print("OrderSend() error - stoploss can not be zero");
}
REPUTK_4_do = REPUTK_3_do / StopLoss / d45QuotesRatio ;
REPUTK_5_do = 0.001 ;
REPUTK_6_do = _MarketInfo(Symbol(),MODE_MINLOT) ;
REPUTK_7_in = 0 ;
while (REPUTK_6_do<1.0)
{
REPUTK_6_do = REPUTK_6_do * MathPow(10.0,REPUTK_7_in) ;
REPUTK_7_in = REPUTK_7_in + 1;
}
REPUTK_5_do = NormalizeDouble(REPUTK_4_do,REPUTK_7_in - 1) ;
if ( REPUTK_5_do<_MarketInfo(Symbol(),MODE_MINLOT) )
{
REPUTK_5_do = _MarketInfo(Symbol(),MODE_MINLOT) ;
}
if ( REPUTK_5_do>_MarketInfo(Symbol(),MODE_MAXLOT) )
{
REPUTK_5_do = _MarketInfo(Symbol(),MODE_MAXLOT) ;
}
REPUTK_8_do = StopLoss * d45QuotesRatio * Point() + _Bid() ;
if ( StopLoss == 0 )
{
REPUTK_8_do = 0.0 ;
}
REPUTK_9_do = _Bid() - TakeProfit * d45QuotesRatio * Point() ;
if ( TakeProfit == 0 )
{
REPUTK_9_do = 0.0 ;
}
REPUTK_10_in = -1 ;
REPUTK_10_in = _OrderSend(Symbol(),OP_SELL,REPUTK_5_do,_Bid(),MaxSlippage,0.0,0.0,DATA_1_st,Magic2,0,Red) ;
if ( REPUTK_10_in > -1 )
{
if ( _OrderSelectByTicket(REPUTK_10_in) )
{
REPUTK_11_bo = _OrderModify((int)_OrderTicket(),_OrderOpenPrice(),REPUTK_8_do,REPUTK_9_do,0,Red) ;
}
if ( REPUTK_11_bo != false ) return;
Print("OrderModify() error - ",ErrorDescription(GetLastError()));
return;
}
Print("OrderSend() error - ",ErrorDescription(GetLastError()));
}
//liDATA_10 <<==-------- --------
void liDATA_11()
{
double REPUTK_1_do;
double REPUTK_2_do;
int REPUTK_3_in;
bool REPUTK_4_bo = false;
//----- -----
datetime REPUT_da_1;
datetime REPUT_da_2;
int REPUT_in_3;
REPUT_da_1 = TimeCurrent();
REPUT_da_2 = 0;
if ( _OrdersHistoryTotal() > 0 )
{
for (REPUT_in_3 = _OrdersHistoryTotal() - 1 ; REPUT_in_3 >= 0 ; REPUT_in_3=REPUT_in_3 - 1)
{
if ( _HstOrderSelectByPos(REPUT_in_3) == true && _HstOrderSymbol() == Symbol() && ( _HstOrderMagicNumber() == Magic || _HstOrderMagicNumber() == Magic2 ) )
{
if ( !(_HstOrderProfit()<0.0) ) break;
REPUT_da_2 = _HstOrderCloseTime();
break;
}
}
}
else
{
REPUT_da_2 = -3600;
}
if ( REPUT_da_1 < REPUT_da_2 + 3600 || _Ask() - _Bid()>MaxSpread * d45QuotesRatio * Point() ) return;
REPUTK_1_do = _Ask() - StopLoss * d45QuotesRatio * Point() ;
if ( StopLoss == 0 )
{
REPUTK_1_do = 0.0 ;
}
REPUTK_2_do = TakeProfit * d45QuotesRatio * Point() + _Ask();
if ( TakeProfit == 0 )
{
REPUTK_2_do = 0.0 ;
}
REPUTK_3_in = -1 ;
REPUTK_3_in = _OrderSend(Symbol(),OP_BUY,Lots,_Ask(),MaxSlippage,0.0,0.0,DATA_1_st,Magic,0,Blue) ;
if ( REPUTK_3_in > -1 )
{
if ( _OrderSelectByTicket(REPUTK_3_in) )
{
REPUTK_4_bo = _OrderModify((int)_OrderTicket(),_OrderOpenPrice(),REPUTK_1_do,REPUTK_2_do,0,Blue) ;
}
if ( REPUTK_4_bo != false ) return;
Print("OrderModify() error - ",ErrorDescription(GetLastError()));
return;
}
Print("OrderSend() error - ",ErrorDescription(GetLastError()));
}
//liDATA_11 <<==-------- --------
void liDATA_12()
{
double REPUTK_1_do;
double REPUTK_2_do;
int REPUTK_3_in;
bool REPUTK_4_bo = false;
//----- -----
datetime REPUT_da_1;
datetime REPUT_da_2;
int REPUT_in_3;
REPUT_da_1 = TimeCurrent();
REPUT_da_2 = 0;
if ( _OrdersHistoryTotal() > 0 )
{
for (REPUT_in_3 = _OrdersHistoryTotal() - 1 ; REPUT_in_3 >= 0 ; REPUT_in_3=REPUT_in_3 - 1)
{
if ( _HstOrderSelectByPos(REPUT_in_3) == true && _HstOrderSymbol() == Symbol() && ( _HstOrderMagicNumber() == Magic || _HstOrderMagicNumber() == Magic2 ) )
{
if ( !(_HstOrderProfit()<0.0) ) break;
REPUT_da_2 = _HstOrderCloseTime();
break;
}
}
}
else
{
REPUT_da_2 = -3600;
}
if ( REPUT_da_1 < REPUT_da_2 + 3600 || _Ask() - _Bid()>MaxSpread * d45QuotesRatio * Point() ) return;
REPUTK_1_do = StopLoss * d45QuotesRatio * Point() + _Bid() ;
if ( StopLoss == 0 )
{
REPUTK_1_do = 0.0 ;
}
REPUTK_2_do = _Bid() - TakeProfit * d45QuotesRatio * Point() ;
if ( TakeProfit == 0 )
{
REPUTK_2_do = 0.0 ;
}
REPUTK_3_in = -1 ;
REPUTK_3_in = _OrderSend(Symbol(),OP_SELL,Lots,_Bid(),MaxSlippage,0.0,0.0,DATA_1_st,Magic2,0,Red) ;
if ( REPUTK_3_in > -1 )
{
if ( _OrderSelectByTicket(REPUTK_3_in) )
{
REPUTK_4_bo = _OrderModify((int)_OrderTicket(),_OrderOpenPrice(),REPUTK_1_do,REPUTK_2_do,0,Red) ;
}
if ( REPUTK_4_bo != false ) return;
Print("OrderModify() error - ",ErrorDescription(GetLastError()));
return;
}
Print("OrderSend() error - ",ErrorDescription(GetLastError()));
}