Author: Copyright � 2014, Nikolay Kositsin
3 Views
0 Downloads
0 Favorites
Exp_BnB
//+------------------------------------------------------------------+
//|                                                      Exp_BnB.mq5 |
//|                               Copyright © 2014, Nikolay Kositsin | 
//|                              Khabarovsk,   farria@mail.redcom.ru | 
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, Nikolay Kositsin"
#property link      "farria@mail.redcom.ru"
#property version   "1.00"
//+----------------------------------------------+
//| Òîðãîâûå àëãîðèòìû                           |
//+----------------------------------------------+
#include <TradeAlgorithms.mqh>
//+----------------------------------------------+
//| Ïåðå÷èñëåíèå äëÿ âàðèàíòîâ ðàñ÷¸òà ëîòà      |
//+----------------------------------------------+
/*enum MarginMode  - ïåðå÷èñëåíèå îáúÿâëåíî â ôàéëå TradeAlgorithms.mqh
  {
   FREEMARGIN=0,     //MM îò ñâîáîäíûõ ñðåäñòâ íà ñ÷¸òå
   BALANCE,          //MM îò áàëàíñà ñðåäñòâ íà ñ÷¸òå
   LOSSFREEMARGIN,   //MM ïî óáûòêàì îò ñâîáîäíûõ ñðåäñòâ íà ñ÷¸òå
   LOSSBALANCE,      //MM ïî óáûòêàì îò áàëàíñà ñðåäñòâ íà ñ÷¸òå
   LOT               //Ëîò áåç èçìåíåíèÿ
  }; */
//+----------------------------------------------+
//| Îïèñàíèå êëàññà CXMA                         |
//+----------------------------------------------+
#include <SmoothAlgorithms.mqh> 
//+----------------------------------------------+
//| îáúÿâëåíèå ïåðå÷èñëåíèé                      |
//+----------------------------------------------+
/*enum Smooth_Method - ïåðå÷èñëåíèå îáúÿâëåíî â ôàéëå SmoothAlgorithms.mqh
  {
   MODE_SMA_,  //SMA
   MODE_EMA_,  //EMA
   MODE_SMMA_, //SMMA
   MODE_LWMA_, //LWMA
   MODE_JJMA,  //JJMA
   MODE_JurX,  //JurX
   MODE_ParMA, //ParMA
   MODE_T3,    //T3
   MODE_VIDYA, //VIDYA
   MODE_AMA,   //AMA
  }; */
//+----------------------------------------------+
//| Âõîäíûå ïàðàìåòðû èíäèêàòîðà ýêñïåðòà        |
//+----------------------------------------------+
input double MM=0.1;              // Äîëÿ ôèíàíñîâûõ ðåñóðñîâ îò äåïîçèòà â ñäåëêå
input MarginMode MMMode=LOT;      // Cïîñîá îïðåäåëåíèÿ ðàçìåðà ëîòà
input int    StopLoss_=1000;      // Stop Loss â ïóíêòàõ
input int    TakeProfit_=2000;    // Take Profit â ïóíêòàõ
input int    Deviation_=10;       // Ìàêñ. îòêëîíåíèå öåíû â ïóíêòàõ
input bool   BuyPosOpen=true;     // Ðàçðåøåíèå äëÿ âõîäà â ëîíã
input bool   SellPosOpen=true;    // Ðàçðåøåíèå äëÿ âõîäà â øîðò
input bool   BuyPosClose=true;    // Ðàçðåøåíèå äëÿ âûõîäà èç ëîíãîâ
input bool   SellPosClose=true;   // Ðàçðåøåíèå äëÿ âûõîäà èç øîðòîâ
//+----------------------------------------------+
//| Âõîäíûå ïàðàìåòðû èíäèêàòîðà                 |
//+----------------------------------------------+
input ENUM_TIMEFRAMES InpInd_Timeframe=PERIOD_H4; // Òàéìôðåéì èíäèêàòîðà
//----
input Smooth_Method XMA_Method=MODE_T3;           // Ìåòîä óñðåäíåíèÿ
input uint XLength=14;                            // Ãëóáèíà óñðåäíåíèÿ
input int XPhase=15;                              // Ïàðàìåòð ñãëàæèâàíèÿ
//---- XPhase: äëÿ JJMA èçìåíÿþùèéñÿ â ïðåäåëàõ -100 ... +100, âëèÿåò íà êà÷åñòâî ïåðåõîäíîãî ïðîöåññà;
//---- XPhase: äëÿ VIDIA ýòî ïåðèîä CMO, äëÿ AMA ýòî ïåðèîä ìåäëåííîé ñêîëüçÿùåé
input ENUM_APPLIED_VOLUME VolumeType=VOLUME_TICK; // Îáú¸ì
//----
input uint SignalBar=1;                           // Íîìåð áàðà äëÿ ïîëó÷åíèÿ ñèãíàëà âõîäà
//+----------------------------------------------+
//---- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ äëÿ õðàíåíèÿ ïåðèîäà ãðàôèêà â ñåêóíäàõ 
int TimeShiftSec;
//---- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ äëÿ õåíäëîâ èíäèêàòîðîâ
int InpInd_Handle;
//---- îáúÿâëåíèå öåëûõ ïåðåìåííûõ íà÷àëà îòñ÷åòà äàííûõ
int min_rates_total;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---- ïîëó÷åíèå õåíäëà èíäèêàòîðà BnB
   InpInd_Handle=iCustom(Symbol(),InpInd_Timeframe,"BnB",XMA_Method,XLength,XPhase,VolumeType);
   if(InpInd_Handle==INVALID_HANDLE)
     {
      Print(" Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà BnB");
      return(INIT_FAILED);
     }
//---- èíèöèàëèçàöèÿ ïåðåìåííîé äëÿ õðàíåíèÿ ïåðèîäà ãðàôèêà â ñåêóíäàõ  
   TimeShiftSec=PeriodSeconds(InpInd_Timeframe);
//---- èíèöèàëèçàöèÿ ïåðåìåííûõ íà÷àëà îòñ÷¸òà äàííûõ
   min_rates_total=GetStartBars(XMA_Method,XLength,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()
  {
//---- ïðîâåðêà êîëè÷åñòâà áàðîâ íà äîñòàòî÷íîñòü äëÿ ðàñ÷¸òà
   if(BarsCalculated(InpInd_Handle)<min_rates_total) return;
//---- ïîäãðóçêà èñòîðèè äëÿ íîðìàëüíîé ðàáîòû ôóíêöèé IsNewBar() è SeriesInfoInteger()  
   LoadHistory(TimeCurrent()-PeriodSeconds(InpInd_Timeframe)-1,Symbol(),InpInd_Timeframe);
//---- îáúÿâëåíèå ëîêàëüíûõ ïåðåìåííûõ
   double Ind[2],Sign[2];
//---- îáúÿâëåíèå ñòàòè÷åñêèõ ïåðåìåííûõ
   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;
//--- îïðåäåëåíèå ñèãíàëîâ äëÿ ñäåëîê
   if(!SignalBar || NB.IsNewBar(Symbol(),InpInd_Timeframe) || Recount) // ïðîâåðêà íà ïîÿâëåíèå íîâîãî áàðà
     {
      //---- îáíóëèì òîðãîâûå ñèãíàëû
      BUY_Open=false;
      SELL_Open=false;
      BUY_Close=false;
      SELL_Close=false;
      Recount=false;
      //---- êîïèðóåì âíîâü ïîÿâèâøèåñÿ äàííûå â ìàññèâû
      if(CopyBuffer(InpInd_Handle,1,SignalBar,2,Ind)<=0) {Recount=true; return;}
      if(CopyBuffer(InpInd_Handle,0,SignalBar,2,Sign)<=0) {Recount=true; return;}
      //---- ïîëó÷èì ñèãíàëû äëÿ ïîêóïêè
      if(Ind[1]>Sign[1])
        {
         if(BuyPosOpen && Ind[0]<=Sign[0]) BUY_Open=true;
         if(SellPosClose) SELL_Close=true;
         UpSignalTime=datetime(SeriesInfoInteger(Symbol(),InpInd_Timeframe,SERIES_LASTBAR_DATE))+TimeShiftSec;
        }
      //---- ïîëó÷èì ñèãíàëû äëÿ ïðîäàæè
      if(Ind[1]<Sign[1])
        {
         if(SellPosOpen && Ind[0]>=Sign[0]) SELL_Open=true;
         if(BuyPosClose) BUY_Close=true;
         DnSignalTime=datetime(SeriesInfoInteger(Symbol(),InpInd_Timeframe,SERIES_LASTBAR_DATE))+TimeShiftSec;
        }
     }
//--- ñîâåðøåíèå ñäåëîê
//--- çàêðûâàåì ëîíã
   BuyPositionClose(BUY_Close,Symbol(),Deviation_);
//--- çàêðûâàåì øîðò   
   SellPositionClose(SELL_Close,Symbol(),Deviation_);
//--- îòêðûâàåì ëîíã
   BuyPositionOpen(BUY_Open,Symbol(),UpSignalTime,MM,MMMode,Deviation_,StopLoss_,TakeProfit_);
//--- îòêðûâàåì øîðò
   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 ---