Exp_BrainTrend2_AbsolutelyNoLagLwma

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

//|                          Exp_BrainTrend2_AbsolutelyNoLagLwma.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

  }; */

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

//|  >1JO2;5=85 ?5@5G8A;5=89                     |

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

enum Applied_price_ //"8? :>=AB0=BK

  {

   PRICE_CLOSE_ = 1,     //Close

   PRICE_OPEN_,          //Open

   PRICE_HIGH_,          //High

   PRICE_LOW_,           //Low

   PRICE_MEDIAN_,        //Median Price (HL/2)

   PRICE_TYPICAL_,       //Typical Price (HLC/3)

   PRICE_WEIGHTED_,      //Weighted Close (HLCC/4)

   PRICE_SIMPL_,         //Simpl Price (OC/2)

   PRICE_QUARTER_,       //Quarted Price (HLOC/4) 

   PRICE_TRENDFOLLOW0_,  //TrendFollow_1 Price 

   PRICE_TRENDFOLLOW1_,  //TrendFollow_2 Price

   PRICE_DEMARK_         //Dema

  };

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

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

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

sinput string A_Trade="#?@02;5=85 B>@3>2;59 4;O BrainTrend2_V2";    //+============== #  "   4;O BrainTrend2_V2 ==============+  

input uint    A_BuyMagic=777;       //A Buy <038: =><5@

input uint    A_SellMagic=888;      //A Sell <038: =><5@

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

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

input uint    A_StopLoss_=1000;     //A AB>?;>AA 2 ?C=:B0E

input uint    A_TakeProfit_=2000;   //A B59:?@>D8B 2 ?C=:B0E

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

sinput string A_MustTrade=" 07@5H5=8O B>@3>2;8 4;O BrainTrend2_V2"; //+==============   (/ "   4;O BrainTrend2_V2 ==============+  

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

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

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

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

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

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

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

sinput string A_Input="0@0<5B@K 2E>40 4;O BrainTrend2_V2";         //+===============  " + %  4;O BrainTrend2_V2 ===============+  

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

input uint A_ATR_Period=7;

input uint A_SignalBar=1;                           //A =><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 B             |

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

sinput string B_Trade="#?@02;5=85 B>@3>2;59 4;O AbsolutelyNoLagLwma";    //+============== #  "  4;O AbsolutelyNoLagLwma ==============+  

input uint    B_BuyMagic=555;       //B Buy <038: =><5@

input uint    B_SellMagic=444;      //B Sell <038: =><5@

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

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

input uint    B_StopLoss_=1000;     //B AB>?;>AA 2 ?C=:B0E

input uint    B_TakeProfit_=2000;   //B B59:?@>D8B 2 ?C=:B0E

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

sinput string B_MustTrade=" 07@5H5=8O B>@3>2;8 4;O AbsolutelyNoLagLwma"; //+==============   (/ "  4;O AbsolutelyNoLagLwma ==============+  

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

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

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

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

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

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

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

sinput string B_Input="0@0<5B@K 2E>40 4;O AbsolutelyNoLagLwma";         //+===============  " + % 4;O AbsolutelyNoLagLwma ===============+  

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

input uint B_Length=7;                              //B 3;C18=0 A3;06820=8O                   

input Applied_price_ B_IPC=PRICE_CLOSE_;            //B F5=>20O :>=AB0=B0

input uint B_SignalBar=1;                           //B =><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 A_TimeShiftSec,B_TimeShiftSec;

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

int A_InpInd_Handle,B_InpInd_Handle;

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

int A_min_rates_total,B_min_rates_total;

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

//| Expert initialization function                                   |

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

int OnInit()

  {

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

   if(A_BuyPosOpen || A_SellPosOpen)

     {

      A_InpInd_Handle=iCustom(Symbol(),A_InpInd_Timeframe,"BrainTrend2_V2",A_ATR_Period,0,false,0,false,false);

      if(A_InpInd_Handle==INVALID_HANDLE)

        {

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

         return(INIT_FAILED);

        }

     }

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

   if(B_BuyPosOpen || B_SellPosOpen)

     {

      B_InpInd_Handle=iCustom(Symbol(),B_InpInd_Timeframe,"AbsolutelyNoLagLwma",B_Length,B_IPC,0,0);

      if(B_InpInd_Handle==INVALID_HANDLE)

        {

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

         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  

   A_TimeShiftSec=PeriodSeconds(A_InpInd_Timeframe);

   B_TimeShiftSec=PeriodSeconds(B_InpInd_Timeframe);



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

   A_min_rates_total=int(A_ATR_Period)+2;

   A_min_rates_total+=int(3+A_SignalBar);

   B_min_rates_total=int(B_Length*2.0);

   B_min_rates_total+=int(3+B_SignalBar);

//----

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

//----

   GlobalVariableDel_(Symbol());

//----

  }

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

//| Expert tick function                                             |

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

void OnTick()

  {

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

//| ;>: C?@02;5=8O 4;O BrainTrend2_V2                    |

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

   if(A_BuyPosOpen || A_SellPosOpen)

     {

      //---- ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O @0AGQB0

      if(BarsCalculated(A_InpInd_Handle)<A_min_rates_total) return;

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

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

      static bool A_Recount=true;

      static bool A_BUY_Open=false,A_BUY_Close=false;

      static bool A_SELL_Open=false,A_SELL_Close=false;

      static datetime A_UpSignalTime,A_DnSignalTime;

      static CIsNewBar A_NB;



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

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

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

      if(!A_SignalBar || A_NB.IsNewBar(Symbol(),A_InpInd_Timeframe) || A_Recount) // ?@>25@:0 =0 ?>O2;5=85 =>2>3> 10@0

        {

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

         A_BUY_Open=false;

         A_BUY_Close=false;

         A_SELL_Open=false;

         A_SELL_Close=false;

         A_Recount=false;

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

         double Value[2];



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

         if(CopyBuffer(A_InpInd_Handle,4,A_SignalBar,2,Value)<=0) {A_Recount=true; return;}



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

         if(Value[1]<2)

           {

            if(A_BuyPosOpen && Value[0]>1) A_BUY_Open=true;

            A_UpSignalTime=datetime(SeriesInfoInteger(Symbol(),A_InpInd_Timeframe,SERIES_LASTBAR_DATE))+A_TimeShiftSec;

            A_SELL_Close=true;

           }



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

         if(Value[1]>2)

           {

            if(A_SellPosOpen && Value[0]<3) A_SELL_Open=true;

            A_DnSignalTime=datetime(SeriesInfoInteger(Symbol(),A_InpInd_Timeframe,SERIES_LASTBAR_DATE))+A_TimeShiftSec;

            A_BUY_Close=true;

           }

        }

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

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

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

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

      BuyPositionClose_M(A_BUY_Close,Symbol(),A_Deviation_,A_BuyMagic);



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

      SellPositionClose_M(A_SELL_Close,Symbol(),A_Deviation_,A_SellMagic);



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

      BuyPositionOpen_M1(A_BUY_Open,Symbol(),A_UpSignalTime,A_MM,A_MMMode,A_Deviation_,A_StopLoss_,A_TakeProfit_,A_BuyMagic);



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

      SellPositionOpen_M1(A_SELL_Open,Symbol(),A_DnSignalTime,A_MM,A_MMMode,A_Deviation_,A_StopLoss_,A_TakeProfit_,A_SellMagic);

     }

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

//| ;>: C?@02;5=8O 4;O AbsolutelyNoLagLwma               |

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

   if(B_BuyPosOpen || B_SellPosOpen)

     {

      if(BarsCalculated(B_InpInd_Handle)<B_min_rates_total) return;

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

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

      static bool B_Recount=true;

      static bool B_BUY_Open=false,B_BUY_Close=false;

      static bool B_SELL_Open=false,B_SELL_Close=false;

      static datetime B_UpSignalTime,B_DnSignalTime;

      static CIsNewBar B_NB;

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

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

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

      if(!B_SignalBar || B_NB.IsNewBar(Symbol(),B_InpInd_Timeframe) || B_Recount) // ?@>25@:0 =0 ?>O2;5=85 =>2>3> 10@0

        {

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

         B_BUY_Open=false;

         B_BUY_Close=false;

         B_SELL_Open=false;

         B_SELL_Close=false;

         B_Recount=false;

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

         double Value[2];



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

         if(CopyBuffer(B_InpInd_Handle,1,B_SignalBar,2,Value)<=0) {B_Recount=true; return;}



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

         if(Value[1]==2)

           {

            if(B_BuyPosOpen && Value[0]!=2) B_BUY_Open=true;

            if(B_SellPosClose) B_SELL_Close=true;

            B_UpSignalTime=datetime(SeriesInfoInteger(Symbol(),B_InpInd_Timeframe,SERIES_LASTBAR_DATE))+B_TimeShiftSec;

           }



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

         if(Value[1]==0)

           {

            if(B_SellPosOpen && Value[0]!=0) B_SELL_Open=true;

            if(B_BuyPosClose) B_BUY_Close=true;

            B_DnSignalTime=datetime(SeriesInfoInteger(Symbol(),B_InpInd_Timeframe,SERIES_LASTBAR_DATE))+B_TimeShiftSec;

           }

        }

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

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

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

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

      BuyPositionClose_M(B_BUY_Close,Symbol(),B_Deviation_,B_BuyMagic);



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

      SellPositionClose_M(B_SELL_Close,Symbol(),B_Deviation_,B_SellMagic);



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

      BuyPositionOpen_M1(B_BUY_Open,Symbol(),B_UpSignalTime,B_MM,B_MMMode,B_Deviation_,B_StopLoss_,B_TakeProfit_,B_BuyMagic);



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

      SellPositionOpen_M1(B_SELL_Open,Symbol(),B_DnSignalTime,B_MM,B_MMMode,B_Deviation_,B_StopLoss_,B_TakeProfit_,B_SellMagic);

     }

//----

  }

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

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 ---