//+------------------------------------------------------------------+
//| Indicator_TrendRiver_Artev.mq4 |
//| Oxy |
//| http://oxy.opentraders.ru/bio/ |
//+------------------------------------------------------------------+
#property copyright "Oxy"
#property link "http://oxy.opentraders.ru/bio/"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 9
#property indicator_label1 "main_MA"
#property indicator_color1 clrRed
#property indicator_label2 "up_1"
#property indicator_color2 clrGray
#property indicator_label3 "up_2"
#property indicator_color3 clrGray
#property indicator_label4 "up_3"
#property indicator_color4 clrGray
#property indicator_label5 "up_4"
#property indicator_color5 clrGray
#property indicator_label6 "dn_1"
#property indicator_color6 clrGray
#property indicator_label7 "dn_2"
#property indicator_color7 clrGray
#property indicator_label8 "dn_3"
#property indicator_color8 clrGray
#property indicator_label9 "dn_4"
#property indicator_color9 clrGray
//------- Внешние параметры -----------------------------------------+
extern int ma_period = 7; // Период MA
extern ENUM_MA_METHOD ma_method = MODE_SMMA; // Метод усреднения MA
extern int ma_shift = 0; // Сдвиг MA
extern ENUM_APPLIED_PRICE applied_price = PRICE_MEDIAN; // Тип цены MA
extern int Ma_Level_1 =230; // Уровень 1 Ма
extern int Ma_Level_2 =380; // Уровень 2 Ма
extern int Ma_Level_3 =500; // Уровень 3 Ма
extern int Ma_Level_4 =610; // Уровень 4 Ма
//------- Глобальные переменные -------------------------------------+
string Symb;
//--- indicator buffers
double Buffer_main_MA [];
double Buffer_MA_H_L1 [];
double Buffer_MA_H_L2 [];
double Buffer_MA_H_L3 [];
double Buffer_MA_H_L4 [];
double Buffer_MA_L_L1 [];
double Buffer_MA_L_L2 [];
double Buffer_MA_L_L3 [];
double Buffer_MA_L_L4 [];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0, Buffer_main_MA);
SetIndexStyle (0, DRAW_LINE, 0, 1);
SetIndexBuffer(1, Buffer_MA_H_L1);
SetIndexStyle (1, DRAW_LINE, 0, 1);
SetIndexBuffer(2, Buffer_MA_H_L2);
SetIndexStyle (2, DRAW_LINE, 0, 1);
SetIndexBuffer(3, Buffer_MA_H_L3);
SetIndexStyle (3, DRAW_LINE, 0, 1);
SetIndexBuffer(4, Buffer_MA_H_L4);
SetIndexStyle (4, DRAW_LINE, 0, 1);
SetIndexBuffer(5, Buffer_MA_L_L1);
SetIndexStyle (5, DRAW_LINE, 0, 1);
SetIndexBuffer(6, Buffer_MA_L_L2);
SetIndexStyle (6, DRAW_LINE, 0, 1);
SetIndexBuffer(7, Buffer_MA_L_L3);
SetIndexStyle (7, DRAW_LINE, 0, 1);
SetIndexBuffer(8, Buffer_MA_L_L4);
SetIndexStyle (8, DRAW_LINE, 0, 1);
Symb = Symbol();
//---
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(prev_calculated==0) {
for(int i=rates_total-ma_period; i>0; i--) {
draw_MA (i);
}
}
draw_MA (0);
return(rates_total);
}
//+------------------------------------------------------------------+
void draw_MA (int i) {
double _ima = iMA(Symb, 0, ma_period, ma_shift, ma_method, applied_price, i);
Buffer_main_MA[i] = _ima;
Buffer_MA_H_L1[i] = _ima+Ma_Level_1*Point;
Buffer_MA_H_L2[i] = _ima+Ma_Level_2*Point;
Buffer_MA_H_L3[i] = _ima+Ma_Level_3*Point;
Buffer_MA_H_L4[i] = _ima+Ma_Level_4*Point;
Buffer_MA_L_L1[i] = _ima-Ma_Level_1*Point;
Buffer_MA_L_L2[i] = _ima-Ma_Level_2*Point;
Buffer_MA_L_L3[i] = _ima-Ma_Level_3*Point;
Buffer_MA_L_L4[i] = _ima-Ma_Level_4*Point;
}
//+------------------------------------------------------------------+
balance = AccountEquity();
Пусть он у нас будет 10000.Profit = 0.04;
AccountEquity()>=balance*Profit/100+balance
Т.е. если сейчас сумма собственных средств больше или равна, чем 10000*0,04/100+10000 = 10004, то сделки должны быть закрыты/удалены.
Oxy