
//+------------------------------------------------------------------+
//| ATRGod.mq4 |
//| Copyright 2018, AM2 |
//| http://www.forexsyatems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, AM2"
#property link "http://www.forexsyatems.biz"
#property version "1.00"
#property strict
#property indicator_chart_window
input int years=10;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutLabel(string nm,string text,int x,int y)
{
ObjectDelete(0,nm);
//--- создадим текстовую метку
ObjectCreate(0,nm,OBJ_LABEL,0,0,0);
//--- установим координаты метки
ObjectSetInteger(0,nm,OBJPROP_XDISTANCE,x);
ObjectSetInteger(0,nm,OBJPROP_YDISTANCE,y);
//--- установим угол графика, относительно которого будут определяться координаты точки
ObjectSetInteger(0,nm,OBJPROP_CORNER,0);
//--- установим текст
ObjectSetString(0,nm,OBJPROP_TEXT,text);
//--- установим шрифт текста
ObjectSetString(0,nm,OBJPROP_FONT,"Arial");
//--- установим размер шрифта
ObjectSetInteger(0,nm,OBJPROP_FONTSIZE,12);
//--- установим цвет
ObjectSetInteger(0,nm,OBJPROP_COLOR,Red);
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
double atr=0;
string s="";
for(int i=1;i<years+1;i++)
{
int shift=iBarShift(NULL,PERIOD_MN1,StringToTime("31"+".12."+(string(Year()-i))));
double lo=iLow(NULL,PERIOD_MN1,iLowest(NULL,PERIOD_MN1,MODE_LOW,12,shift));
double hi=iHigh(NULL,PERIOD_MN1,iHighest(NULL,PERIOD_MN1,MODE_HIGH,12,shift));
s+="\n Hi"+(string)i+": "+(string)hi+"\n Lo"+(string)i+": "+(string)lo;
atr+=(hi-lo)/_Point;
}
PutLabel("L","ATR: "+(string)(int)(atr/years),20,25);
Comment("\n","\n","\n",s);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
(hi10-lo10)/10)
extern int Candles = 1; // свечки
extern int Slip = 30; // реквот
Я думаю эти значения на Бинарках не нужны.
можно сделать не в 30, а в 3 пункта?
Открывает сделки как захочет, без всяких касаний. И уж точно больше чем в 30 пятизначных пунктов от линии.
//+------------------------------------------------------------------+
//| ATRGod.mq4 |
//| Copyright 2018, AM2 |
//| http://www.forexsyatems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, AM2"
#property link "http://www.forexsyatems.biz"
#property version "1.00"
#property strict
#property indicator_chart_window
input int years=10;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutLabel(string nm,string text,int x,int y)
{
ObjectDelete(0,nm);
//--- создадим текстовую метку
ObjectCreate(0,nm,OBJ_LABEL,0,0,0);
//--- установим координаты метки
ObjectSetInteger(0,nm,OBJPROP_XDISTANCE,x);
ObjectSetInteger(0,nm,OBJPROP_YDISTANCE,y);
//--- установим угол графика, относительно которого будут определяться координаты точки
ObjectSetInteger(0,nm,OBJPROP_CORNER,0);
//--- установим текст
ObjectSetString(0,nm,OBJPROP_TEXT,text);
//--- установим шрифт текста
ObjectSetString(0,nm,OBJPROP_FONT,"Arial");
//--- установим размер шрифта
ObjectSetInteger(0,nm,OBJPROP_FONTSIZE,12);
//--- установим цвет
ObjectSetInteger(0,nm,OBJPROP_COLOR,Red);
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
double atr=0;
for(int i=1;i<years+1;i++)
{
int shift=iBarShift(NULL,PERIOD_MN1,StringToTime("31"+".12."+(string(Year()-i))));
double lo=iLow(NULL,PERIOD_MN1,iLowest(NULL,PERIOD_MN1,MODE_LOW,12,shift));
double hi=iHigh(NULL,PERIOD_MN1,iHighest(NULL,PERIOD_MN1,MODE_HIGH,12,shift));
atr+=(hi-lo)/_Point;
}
PutLabel("L","ATR: "+(string)(int)(atr/years),20,25);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Show.mq4 |
//| Copyright 2018, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double KLot = 1; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern int StopLoss = 2000; // лось
extern int TakeProfit = 3000; // язь
extern int Slip = 30; // реквот
extern int Shift = 1; // на каком баре сигнал индикатора
extern int Magic = 123; // магик
extern string IndName = "PBF_Scalper_Show_Me2 (2)";
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+----------------------------------------------------------------------------+
//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
//| Версия : 30.04.2009 |
//| Описание : Возвращает флаг разрешения торговли по времени. |
//+----------------------------------------------------------------------------+
//| Параметры: |
//| hb - часы времени начала торговли |
//| mb - минуты времени начала торговли |
//| he - часы времени окончания торговли |
//| me - минуты времени окончания торговли |
//+----------------------------------------------------------------------------+
bool isTradeTimeInt(int hb=0,int mb=0,int he=0,int me=0)
{
datetime db, de; // Время начала и окончания работы
int hc; // Часы текущего времени торгового сервера
db=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+(string)hb+":"+(string)mb);
de=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+(string)he+":"+(string)me);
hc=TimeHour(TimeCurrent());
if(db>=de)
{
if(hc>=he) de+=24*60*60; else db-=24*60*60;
}
if(TimeCurrent()>=db && TimeCurrent()<=de) return(True);
else return(False);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=Green;
double sl=0,tp=0;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(StopLoss>0) sl=NormalizeDouble(price+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price-TakeProfit*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(StopLoss>0) sl=NormalizeDouble(price-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*Point,Digits);
}
r=OrderSend(NULL,type,Lot(),NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades()
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OpenPos()
{
double b = iCustom(NULL,0,IndName,1,Shift);
double s = iCustom(NULL,0,IndName,0,Shift);
if(b>0)
{
PutOrder(0,Ask);
}
if(s>0)
{
PutOrder(1,Bid);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ClosePos()
{
double b = iCustom(NULL,0,IndName,1,Shift);
double s = iCustom(NULL,0,IndName,0,Shift);
if(s>0)
{
CloseAll(0);
}
if(b>0)
{
CloseAll(1);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderProfit()>0) break;
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
break;
}
}
}
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseAll(int ot=-1)
{
bool cl;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==0 && (ot==0 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double b = iCustom(NULL,0,IndName,1,Shift);
double s = iCustom(NULL,0,IndName,0,Shift);
if(CountTrades()<1) OpenPos();
else ClosePos();
Comment("\n b: ",b,
"\n s: ",s);
}
//+------------------------------------------------------------------+
AM2