exp_leading

Author: Copyright � 2015, Nikolay Kositsin
0 Views
0 Downloads
0 Favorites
exp_leading
//+------------------------------------------------------------------+
//|                                                  Exp_Leading.mq5 |
//|                               Copyright © 2015, Nikolay Kositsin | 
//|                              Khabarovsk,   farria@mail.redcom.ru | 
//+------------------------------------------------------------------+
#property copyright "Copyright © 2015, Nikolay Kositsin"
#property link      "farria@mail.redcom.ru"
#property version   "1.00"
//+-----------------------------------------------+
//|  Òîðãîâûå àëãîðèòìû                           | 
//+-----------------------------------------------+
#include <TradeAlgorithms.mqh>
//+-----------------------------------------------+
//| Âõîäíûå ïàðàìåòðû èíäèêàòîðà ýêñïåðòà         |
//+-----------------------------------------------+
input double MM=0.1;              // Äîëÿ ôèíàíñîâûõ ðåñóðñîâ îò äåïîçèòà â ñäåëêå
input MarginMode MMMode=LOT;      // Ñïîñîá îïðåäåëåíèÿ ðàçìåðà ëîòà
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;   // Ðàçðåøåíèå äëÿ âûõîäà èç øîðòîâ
//+-----------------------------------------------+
//| Âõîäíûå ïàðàìåòðû äëÿ èíäèêàòîðà Leading      |
//+-----------------------------------------------+
input ENUM_TIMEFRAMES InpInd_Timeframe=PERIOD_H4; // Òàéìôðåéì èíäèêàòîðà
input uint SignalBar=1;                           // Íîìåð áàðà äëÿ ïîëó÷åíèÿ ñèãíàëà âõîäà
input double Alpha1 = 0.25;                       // 1 êîýôôèöèåíò èíäèêàòîðà
input double Alpha2 = 0.33;                       // 2 êîýôôèöèåíò èíäèêàòîðà 
//+----------------------------------------------+
//--- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ äëÿ õðàíåíèÿ ïåðèîäà ãðàôèêà â ñåêóíäàõ 
int TimeShiftSec;
//--- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ äëÿ õåíäëîâ èíäèêàòîðîâ
int InpInd_Handle;
//--- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ íà÷àëà îòñ÷åòà äàííûõ
int min_rates_total;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- ïîëó÷åíèå õåíäëà èíäèêàòîðà Leading_Optim
   InpInd_Handle=iCustom(Symbol(),InpInd_Timeframe,"Leading",Alpha1,Alpha2,0);
   if(InpInd_Handle==INVALID_HANDLE)
     {
      Print("Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà Leading_Optim");
      return(INIT_FAILED);
     }
//--- èíèöèàëèçàöèÿ ïåðåìåííîé äëÿ õðàíåíèÿ ïåðèîäà ãðàôèêà â ñåêóíäàõ  
   TimeShiftSec=PeriodSeconds(InpInd_Timeframe);
//--- èíèöèàëèçàöèÿ ïåðåìåííûõ íà÷àëà îòñ÷¸òà äàííûõ
   min_rates_total=int(7+1+1+2+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 Ma1[2],Ma2[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,0,SignalBar,2,Ma1)<=0) {Recount=true; return;}
      if(CopyBuffer(InpInd_Handle,1,SignalBar,2,Ma2)<=0) {Recount=true; return;}
      //--- Ïîëó÷èì ñèãíàëû äëÿ ïîêóïêè
      if(Ma1[1]>Ma2[1])
        {
         if(BuyPosOpen && Ma1[0]<Ma2[0]) BUY_Open=true;
         if(SellPosClose) SELL_Close=true;
         UpSignalTime=datetime(SeriesInfoInteger(Symbol(),InpInd_Timeframe,SERIES_LASTBAR_DATE))+TimeShiftSec;
        }
      //--- Ïîëó÷èì ñèãíàëû äëÿ ïðîäàæè
      if(Ma1[1]<Ma2[1])
        {
         if(SellPosOpen && Ma1[0]>Ma2[0]) SELL_Open=true;
         if(BuyPosClose) BUY_Close=true;
         DnSignalTime=datetime(SeriesInfoInteger(Symbol(),InpInd_Timeframe,SERIES_LASTBAR_DATE))+TimeShiftSec;
        }
     }
//--- cîâåðøåíèå ñäåëîê
//--- çàêðûâàåì ëîíã
   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 ---