Exp_BlauTVI_Tm

Author: Copyright © 2018, Nikolay Kositsin
0 Views
0 Downloads
0 Favorites
Exp_BlauTVI_Tm
ÿþ//+------------------------------------------------------------------+

//|                                               Exp_BlauTVI_Tm.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.10"

//---- :;NG5=85 8=48:0B>@0 2 :>4 M:A?5@B0 :0: @5AC@A0

#resource "\\Indicators\\BlauTVI.ex5"

//+----------------------------------------------+

//|  ?8A0=85 :;0AA>2 CA@54=5=89                 |

//+----------------------------------------------+

#include <SmoothAlgorithms.mqh> 

//+----------------------------------------------+

//|  ">@3>2K5 0;3>@8B<K                          | 

//+----------------------------------------------+

#include <TradeAlgorithms.mqh>

//+----------------------------------------------+

//| E>4=K5 ?0@0<5B@K 8=48:0B>@0 M:A?5@B0        |

//+----------------------------------------------+

input double MM=0.1;               //>;O D8=0=A>2KE @5AC@A>2 >B 45?>78B0 2 A45;:5

input MarginMode MMMode=LOT;       //!?>A>1 >?@545;5=8O @07<5@0 ;>B0

input int    StopLoss_=1000;       //AB>?;>AA 2 ?C=:B0E

input int    TakeProfit_=2000;     //B59:?@>D8B 2 ?C=:B0E

input int    Deviation_=10;        //<0:A. >B:;>=5=85 F5=K 2 ?C=:B0E

input bool   BuyPosOpen=true;      // 07@5H5=85 4;O 2E>40 2 ;>=3

input bool   SellPosOpen=true;     // 07@5H5=85 4;O 2E>40 2 H>@B

input bool   BuyPosClose=true;     // 07@5H5=85 4;O 2KE>40 87 ;>=3>2

input bool   SellPosClose=true;    // 07@5H5=85 4;O 2KE>40 87 H>@B>2

input bool   TimeTrade=true;       //  07@5H5=85 4;O B>@3>2;8 ?> 8=B5@20;0< 2@5<5=8

input HOURS  StartH=ENUM_HOUR_0;   // !B0@B B>@3>2;8 ('0AK)

input MINUTS StartM=ENUM_MINUT_0;  // !B0@B B>@3>2;8 (8=CBK)

input HOURS  EndH=ENUM_HOUR_23;    // :>=G0=85 B>@3>2;8 ('0AK)

input MINUTS EndM=ENUM_MINUT_59;   // :>=G0=85 B>@3>2;8 (8=CBK)

//+----------------------------------------------+

//| E>4=K5 ?0@0<5B@K 8=48:0B>@0                 |

//+----------------------------------------------+

input ENUM_TIMEFRAMES InpInd_Timeframe=PERIOD_H4;  // B09<D@59< 8=48:0B>@0



input Smooth_Method XMA_Method=MODE_EMA_;          // <5B>4 CA@54=5=8O

input uint XLength1=12;                            // 3;C18=0 ?5@2>3> CA@54=5=8O

input uint XLength2=12;                            // 3;C18=0 2B>@>3> CA@54=5=8O

input uint XLength3=5;                             // 3;C18=0 B@5BL53> CA@54=5=8O

input int XPhase=15;                               // ?0@0<5B@ A3;06820=8O,

//---- 4;O JJMA 87<5=ONI89AO 2 ?@545;0E -100 ... +100, 2;8O5B =0 :0G5AB2> ?5@5E>4=>3> ?@>F5AA0;

//---- ;O VIDIA MB> ?5@8>4 CMO, 4;O AMA MB> ?5@8>4 <54;5==>9 A:>;L7OI59

input ENUM_APPLIED_VOLUME VolumeType=VOLUME_TICK;  // >1JQ<



input uint SignalBar=1;//=><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 TimeShiftSec;

//---- 1JO2;5=85 F5;KE ?5@5<5==KE 4;O E5=4;>2 8=48:0B>@>2

int InpInd_Handle;

//---- >1JO2;5=85 F5;KE ?5@5<5==KE =0G0;0 >BAG5B0 40==KE

int min_rates_total;

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

//---- ?>;CG5=85 E5=4;0 8=48:0B>@0 BlauTVI

   InpInd_Handle=iCustom(Symbol(),InpInd_Timeframe,"::Indicators\\BlauTVI",XMA_Method,XLength1,XLength2,XLength3,XPhase,VolumeType);

   if(InpInd_Handle==INVALID_HANDLE)

     {

      Print(" 5 C40;>AL ?>;CG8BL E5=4; 8=48:0B>@0 BlauTVI");

      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  

   TimeShiftSec=PeriodSeconds(InpInd_Timeframe);



//---- =8F80;870F8O ?5@5<5==KE =0G0;0 >BAGQB0 40==KE

   min_rates_total+=GetStartBars(XMA_Method,XLength1,XPhase);

   min_rates_total+=GetStartBars(XMA_Method,XLength2,XPhase);

   min_rates_total+=GetStartBars(XMA_Method,XLength3,XPhase);  

   min_rates_total+=int(3+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(InpInd_Handle)<min_rates_total) return;



//---- ?>43@C7:0 8AB>@88 4;O =>@<0;L=>9 @01>BK DC=:F89 IsNewBar() 8 SeriesInfoInteger()  

   LoadHistory(TimeCurrent()-PeriodSeconds(InpInd_Timeframe)-1,Symbol(),InpInd_Timeframe);



//---- 1JO2;5=85 ;>:0;L=KE ?5@5<5==KE

   double Value[3];

//---- 1JO2;5=85 AB0B8G5A:8E ?5@5<5==KE

   static bool Recount=true;

   static bool BUY_Open=false,BUY_Close=false;

   static bool SELL_Open=false,SELL_Close=false;

   static datetime UpSignalTime,DnSignalTime;

   static CIsNewBar NB;



//+----------------------------------------------+

//| ?@545;5=85 A83=0;>2 4;O A45;>:              |

//+----------------------------------------------+

   if(!SignalBar || NB.IsNewBar(Symbol(),InpInd_Timeframe) || Recount) // ?@>25@:0 =0 ?>O2;5=85 =>2>3> 10@0

     {

      //---- >1=C;8< B>@3>2K5 A83=0;K

      BUY_Open=false;

      SELL_Open=false;

      BUY_Close=false;

      SELL_Close=false;

      Recount=false;



      //---- :>?8@C5< 2=>2L ?>O282H85AO 40==K5 2 <0AA82K

      if(CopyBuffer(InpInd_Handle,0,SignalBar,3,Value)<=0) {Recount=true; return;}



      //---- >;CG8< A83=0;K 4;O ?>:C?:8

      if(Value[1]<Value[2])

        {

         if(BuyPosOpen&&Value[0]>Value[1]) BUY_Open=true;

         if(SellPosClose) SELL_Close=true;

         UpSignalTime=datetime(SeriesInfoInteger(Symbol(),InpInd_Timeframe,SERIES_LASTBAR_DATE))+TimeShiftSec;

        }



      //---- >;CG8< A83=0;K 4;O ?@>4068

      if(Value[1]>Value[2])

        {

         if(SellPosOpen&&Value[0]<Value[1]) SELL_Open=true;

         if(BuyPosClose) BUY_Close=true;

         DnSignalTime=datetime(SeriesInfoInteger(Symbol(),InpInd_Timeframe,SERIES_LASTBAR_DATE))+TimeShiftSec;

        }

     }

//+----------------------------------------------+

//| ?@545;5=85 A83=0;>2 4;O B>@3>2;8 2 ?5@8>45  |

//+----------------------------------------------+ 

//---- 1JO2;5=85 ?5@5<5==>9 4;O @07@5H5=8O B>@3>2;8

   bool Trade=false;

   if(TimeTrade)

     {

      MqlDateTime tm;

      TimeToStruct(TimeCurrent(),tm);



      if(StartH<EndH)

        {

         if(tm.hour==StartH && tm.min>=StartM) Trade=true;

         if(tm.hour>StartH && tm.hour<EndH) Trade=true;

         if(tm.hour>StartH && tm.hour==EndH && tm.min<EndM) Trade=true;

        }



      if(StartH==EndH)

        {

         if(tm.hour==StartH && tm.min>=StartM && tm.min<EndM) Trade=true;

        }



      if(StartH>EndH)

        {

         if(tm.hour>=StartH && tm.min>=StartM) Trade=true;

         if(tm.hour<EndH) Trade=true;

         if(tm.hour==EndH && tm.min<EndM) Trade=true;

        }

     }

//+----------------------------------------------+

//| !>25@H5=85 A45;>:                            |

//+----------------------------------------------+

//---- 70:@K205< ?>78F88 2=5 B>@3>2>3> 8=B5@20;0

   if(TimeTrade && !Trade && PositionsTotal())

     {

      bool Signal=true;

      BuyPositionClose(Signal,Symbol(),Deviation_);

      Signal=true;

      SellPositionClose(Signal,Symbol(),Deviation_);

     }



//---- 0:@K205< ;>=3

   BuyPositionClose(BUY_Close,Symbol(),Deviation_);



//---- 0:@K205< H>@B   

   SellPositionClose(SELL_Close,Symbol(),Deviation_);



//---- B:@K205< ;>=3

   BuyPositionOpen(BUY_Open,Symbol(),UpSignalTime,MM,MMMode,Deviation_,StopLoss_,TakeProfit_);



//---- B:@K205< H>@B

   SellPositionOpen(SELL_Open,Symbol(),DnSignalTime,MM,MMMode,Deviation_,StopLoss_,TakeProfit_);

//----

  }

//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---