Exp_Skyscraper_Fix_Duplex

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

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

  }; */

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

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

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

enum Method

  {

   MODE_HighLow,  //High/Low

   MODE_Close     //Close

  };

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

//| 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_Length=10;             //L 5@8>4 ATR

input double  L_Kv=0.9;                //L $0:B>@ GC2AB28B5;L=>AB8 8=48:0B>@0

input double  L_Percentage=0;          //L @81;865=85 A@54=59 ;8=88 : ;8=8O< M:AB@5<C<>2

input Method  L_HighLow=MODE_HighLow;  //L  0AGQB 8=48:0B>@0 ?> High/Low 8;8 Close

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_Length=10;             //S 5@8>4 ATR

input double  S_Kv=0.9;                //S $0:B>@ GC2AB28B5;L=>AB8 8=48:0B>@0

input double  S_Percentage=0;          //S @81;865=85 A@54=59 ;8=88 : ;8=8O< M:AB@5<C<>2

input Method  S_HighLow=MODE_HighLow;  //S  0AGQB 8=48:0B>@0 ?> High/Low 8;8 Close

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

   L_InpInd_Handle=iCustom(Symbol(),L_InpInd_Timeframe,"Skyscraper_Fix",L_Length,L_Kv,L_Percentage,L_HighLow);

   if(L_InpInd_Handle==INVALID_HANDLE)

     {

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

      return(INIT_FAILED);

     }

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

   S_InpInd_Handle=iCustom(Symbol(),S_InpInd_Timeframe,"Skyscraper_Fix",S_Length,S_Kv,S_Percentage,S_HighLow);

   if(S_InpInd_Handle==INVALID_HANDLE)

     {

      Print(" 5 C40;>AL ?>;CG8BL E5=4; 8=48:0B>@0 Skyscraper_Fix 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=15;

   L_min_rates_total+=int(L_Length+1);

   L_min_rates_total+=int(L_SignalBar);

   S_min_rates_total=15;

   S_min_rates_total+=int(S_Length+1);

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



//---- 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])

        {

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

        {

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

        {

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

        {

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