Navigation:Home > Content >

Stop.mq4

Time: 2017-09-11 | Download file:Stop.mq4

//+------------------------------------------------------------------+
//|                                                         Stop.mq4 |
//|                                                   Copyright 2016.|
//|                                               Fedor10_10@mail.ru |
//+------------------------------------------------------------------+
#property link      "Fedor10_10@mail.ru"
#property version   "1.00"
#property description "Визуальный контроль цели по StopLoss/TakeProfit"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot Up
#property indicator_label1  "Up"
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_color1  clrGray
#property indicator_style1  STYLE_SOLID
#property indicator_width1  8
//--- plot Dn
#property indicator_label2  "Dn"
#property indicator_type2   DRAW_HISTOGRAM
#property indicator_color2  clrGray
#property indicator_style2  STYLE_SOLID
#property indicator_width2  8
//--- input parameters
input int StopLoss=0;//StopLoss/TakeProfit
//--- indicator buffers
double    SL,UpBuffer[],DnBuffer[];
datetime  Timer;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,UpBuffer);
   SetIndexBuffer(1,DnBuffer);
   SL=StopLoss*Point;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   if(Timer==time[0])
     {
      UpBuffer[0]=close[0]+SL;
      DnBuffer[0]=close[0]-SL;
        } else {
      UpBuffer[1]=EMPTY_VALUE;
      DnBuffer[1]=EMPTY_VALUE;
      Timer=time[0];
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Recommend