1
Views
0
Downloads
0
Favorites
Exp_NRTR_Duplex
ÿþ//+------------------------------------------------------------------+
//| Exp_NRTR_Duplex.mq5 |
//| Copyright © 2018, Nikolay Kositsin |
//| Khabarovsk, farria@mail.redcom.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2018, Nikolay Kositsin"
#property link "farria@mail.redcom.ru"
#property version "1.00"
//+----------------------------------------------+
// ">@3>2K5 0;3>@8B<K |
//+----------------------------------------------+
#include <TradeAlgorithms.mqh>
//+----------------------------------------------+
//| 5@5G8A;5=85 4;O 20@80=B>2 @0AGQB0 ;>B0 |
//+----------------------------------------------+
/*enum MarginMode - ?5@5G8A;5=85 >1JO2;5=> 2 D09;5 TradeAlgorithms.mqh
{
FREEMARGIN=0, //MM >B A2>1>4=KE A@54AB2 =0 AGQB5
BALANCE, //MM >B 10;0=A0 A@54AB2 =0 AGQB5
LOSSFREEMARGIN, //MM ?> C1KB:0< >B A2>1>4=KE A@54AB2 =0 AGQB5
LOSSBALANCE, //MM ?> C1KB:0< >B 10;0=A0 A@54AB2 =0 AGQB5
LOT //>B 157 87<5=5=8O
}; */
//+----------------------------------------------+
//| E>4=K5 ?0@0<5B@K M:A?5@B0 4;O ;>=3>2 |
//+----------------------------------------------+
input uint L_Magic=777; //L <038: =><5@
input double L_MM=0.1; //L >;O D8=0=A>2KE @5AC@A>2 >B 45?>78B0 2 A45;:5
input MarginMode L_MMMode=LOT; //L A?>A>1 >?@545;5=8O @07<5@0 ;>B0
input uint L_StopLoss_=1000; //L AB>?;>AA 2 ?C=:B0E
input uint L_TakeProfit_=2000; //L B59:?@>D8B 2 ?C=:B0E
input uint L_Deviation_=10; //L <0:A. >B:;>=5=85 F5=K 2 ?C=:B0E
input bool L_PosOpen=true; //L 07@5H5=85 4;O 2E>40 2 ;>=3
input bool L_PosClose=true; //L 07@5H5=85 4;O 2KE>40 87 ;>=3>2
//+----------------------------------------------+
//| E>4=K5 ?0@0<5B@K 8=48:0B>@0 4;O ;>=3>2 |
//+----------------------------------------------+
input ENUM_TIMEFRAMES L_InpInd_Timeframe=PERIOD_H4; //L B09<D@59< 8=48:0B>@0
input uint L_iPeriod=10; //?5@8>4 8=48:0B>@0
input int L_iDig=0; //@07@O4
input uint L_SignalBar=1; //L =><5@ 10@0 4;O ?>;CG5=8O A83=0;0 2E>40
//+----------------------------------------------+
//| E>4=K5 ?0@0<5B@K M:A?5@B0 4;O H>@B>2 |
//+----------------------------------------------+
input uint S_Magic=555; //S <038: =><5@
input double S_MM=0.1; //S >;O D8=0=A>2KE @5AC@A>2 >B 45?>78B0 2 A45;:5
input MarginMode S_MMMode=LOT; //S A?>A>1 >?@545;5=8O @07<5@0 ;>B0
input uint S_StopLoss_=1000; //S AB>?;>AA 2 ?C=:B0E
input uint S_TakeProfit_=2000; //S B59:?@>D8B 2 ?C=:B0E
input uint S_Deviation_=10; //S <0:A. >B:;>=5=85 F5=K 2 ?C=:B0E
input bool S_PosOpen=true; //S 07@5H5=85 4;O 2E>40 2 ;>=3
input bool S_PosClose=true; //S 07@5H5=85 4;O 2KE>40 87 ;>=3>2
//+----------------------------------------------+
//| E>4=K5 ?0@0<5B@K 8=48:0B>@0 4;O H>@B>2 |
//+----------------------------------------------+
input ENUM_TIMEFRAMES S_InpInd_Timeframe=PERIOD_H4; //S B09<D@59< 8=48:0B>@0
input uint S_iPeriod=10; //?5@8>4 8=48:0B>@0
input int S_iDig=0; //@07@O4
input uint S_SignalBar=1; //S =><5@ 10@0 4;O ?>;CG5=8O A83=0;0 2E>40
//+----------------------------------------------+
//---- 1JO2;5=85 F5;KE ?5@5<5==KE 4;O E@0=5=8O ?5@8>40 3@0D8:0 2 A5:C=40E
int L_TimeShiftSec,S_TimeShiftSec;
//---- 1JO2;5=85 F5;KE ?5@5<5==KE 4;O E5=4;>2 8=48:0B>@>2
int L_InpInd_Handle,S_InpInd_Handle;
//---- >1JO2;5=85 F5;KE ?5@5<5==KE =0G0;0 >BAG5B0 40==KE
int L_min_rates_total,S_min_rates_total;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---- ?>;CG5=85 E5=4;0 8=48:0B>@0 NRTR L
L_InpInd_Handle=iCustom(Symbol(),L_InpInd_Timeframe,"NRTR",L_iPeriod,L_iDig);
if(L_InpInd_Handle==INVALID_HANDLE)
{
Print(" 5 C40;>AL ?>;CG8BL E5=4; 8=48:0B>@0 NRTR L");
return(INIT_FAILED);
}
//---- ?>;CG5=85 E5=4;0 8=48:0B>@0 NRTR S
S_InpInd_Handle=iCustom(Symbol(),S_InpInd_Timeframe,"NRTR",S_iPeriod,S_iDig);
if(S_InpInd_Handle==INVALID_HANDLE)
{
Print(" 5 C40;>AL ?>;CG8BL E5=4; 8=48:0B>@0 NRTR S");
return(INIT_FAILED);
}
//---- 8=8F80;870F8O ?5@5<5==>9 4;O E@0=5=8O ?5@8>40 3@0D8:0 2 A5:C=40E
L_TimeShiftSec=PeriodSeconds(L_InpInd_Timeframe);
S_TimeShiftSec=PeriodSeconds(S_InpInd_Timeframe);
//---- =8F80;870F8O ?5@5<5==KE =0G0;0 >BAGQB0 40==KE
L_min_rates_total=int(L_iPeriod)+2;
L_min_rates_total+=int(L_SignalBar);
S_min_rates_total=int(S_iPeriod)+2;
S_min_rates_total+=int(S_SignalBar);
//----
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//----
GlobalVariableDel_(Symbol());
//----
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---- ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O @0AGQB0
if(BarsCalculated(L_InpInd_Handle)<L_min_rates_total) return;
if(BarsCalculated(S_InpInd_Handle)<S_min_rates_total) return;
//---- ?>43@C7:0 8AB>@88 4;O =>@<0;L=>9 @01>BK DC=:F89 IsNewBar() 8 SeriesInfoInteger()
LoadHistory(TimeCurrent()-L_TimeShiftSec-1,Symbol(),L_InpInd_Timeframe);
LoadHistory(TimeCurrent()-S_TimeShiftSec-1,Symbol(),S_InpInd_Timeframe);
LoadHistory(TimeCurrent()-L_TimeShiftSec-1,"EURUSD",L_InpInd_Timeframe);
LoadHistory(TimeCurrent()-S_TimeShiftSec-1,"EURUSD",S_InpInd_Timeframe);
//---- 1JO2;5=85 ;>:0;L=KE ?5@5<5==KE
double DnValue[1],UpValue[1];
//---- 1JO2;5=85 AB0B8G5A:8E ?5@5<5==KE
static bool L_Recount=true,S_Recount=true;
static bool BUY_Open=false,BUY_Close=false;
static bool SELL_Open=false,SELL_Close=false;
static datetime UpSignalTime,DnSignalTime;
static CIsNewBar L_NB,S_NB;
//+----------------------------------------------+
//| ?@545;5=85 A83=0;>2 4;O 4;8==KE ?>78F89 |
//+----------------------------------------------+
if(!L_SignalBar || L_NB.IsNewBar(Symbol(),L_InpInd_Timeframe) || L_Recount) // ?@>25@:0 =0 ?>O2;5=85 =>2>3> 10@0
{
//---- >1=C;8< B>@3>2K5 A83=0;K
BUY_Open=false;
BUY_Close=false;
L_Recount=false;
//---- :>?8@C5< 2=>2L ?>O282H85AO 40==K5 2 <0AA82K
if(CopyBuffer(L_InpInd_Handle,2,L_SignalBar,1,UpValue)<=0) {L_Recount=true; return;}
if(CopyBuffer(L_InpInd_Handle,1,L_SignalBar,1,DnValue)<=0) {L_Recount=true; return;}
//---- >;CG8< A83=0;K 4;O ?>:C?:8
if(UpValue[0] && UpValue[0]!=EMPTY_VALUE)
{
if(L_PosOpen) BUY_Open=true;
UpSignalTime=datetime(SeriesInfoInteger(Symbol(),L_InpInd_Timeframe,SERIES_LASTBAR_DATE))+L_TimeShiftSec;
}
//---- >;CG8< A83=0;K 4;O ?@>4068
if(DnValue[0] && DnValue[0]!=EMPTY_VALUE)
{
if(L_PosClose) BUY_Close=true;
}
}
//+----------------------------------------------+
//| ?@545;5=85 A83=0;>2 4;O :>@>B:8E ?>78F89 |
//+----------------------------------------------+
if(!S_SignalBar || S_NB.IsNewBar(Symbol(),S_InpInd_Timeframe) || S_Recount) // ?@>25@:0 =0 ?>O2;5=85 =>2>3> 10@0
{
//---- >1=C;8< B>@3>2K5 A83=0;K
SELL_Open=false;
SELL_Close=false;
S_Recount=false;
//---- :>?8@C5< 2=>2L ?>O282H85AO 40==K5 2 <0AA82K
if(CopyBuffer(S_InpInd_Handle,0,S_SignalBar,1,UpValue)<=0) {S_Recount=true; return;}
if(CopyBuffer(S_InpInd_Handle,3,S_SignalBar,1,DnValue)<=0) {S_Recount=true; return;}
//---- >;CG8< A83=0;K 4;O ?@>4068
if(DnValue[0] && DnValue[0]!=EMPTY_VALUE)
{
if(S_PosOpen) SELL_Open=true;
DnSignalTime=datetime(SeriesInfoInteger(Symbol(),S_InpInd_Timeframe,SERIES_LASTBAR_DATE))+S_TimeShiftSec;
}
//---- >;CG8< A83=0;K 4;O ?>:C?:8
if(UpValue[0] && UpValue[0]!=EMPTY_VALUE)
{
if(S_PosClose) SELL_Close=true;
}
}
//+----------------------------------------------+
//| !>25@H5=85 A45;>: |
//+----------------------------------------------+
//---- 0:@K205< ;>=3
BuyPositionClose_M(BUY_Close,Symbol(),L_Deviation_,L_Magic);
//---- 0:@K205< H>@B
SellPositionClose_M(SELL_Close,Symbol(),S_Deviation_,S_Magic);
//---- B:@K205< ;>=3
BuyPositionOpen_M1(BUY_Open,Symbol(),UpSignalTime,L_MM,L_MMMode,L_Deviation_,L_StopLoss_,L_TakeProfit_,L_Magic);
//---- B:@K205< H>@B
SellPositionOpen_M1(SELL_Open,Symbol(),DnSignalTime,S_MM,S_MMMode,S_Deviation_,S_StopLoss_,S_TakeProfit_,S_Magic);
//----
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---