Андрей добрый день, а можно было бы под коректировать эту сову
//+------------------------------------------------------------------+
//| OAO.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
//--- Inputs
extern double Lots = 0.1; // лот
extern double KLot = 2; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern int StopLoss = 50; // лось
extern int TakeProfit = 70; // язь
extern int Expiration = 10; // истечение ордера
extern int CloseOn = 0; // 1-закрытие,удаление ордеров на сигналах AO
extern bool BSDel = true; // удалим байстоп после пересечения
extern bool SSDel = true; // удалим селстоп после пересечения
extern bool One = false; // только один ордер
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
bool b=true,s=true;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr;
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,TimeCurrent()+Expiration*3600,clr);
return;
}
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу |
//+------------------------------------------------------------------+
int CountOrders(int type)
{
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()==type) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DelOrder()
{
bool del;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()>1) del=OrderDelete(OrderTicket());
}
}
}
}
//+------------------------------------------------------------------+
//| Закрытие позиции по типу ордера |
//+------------------------------------------------------------------+
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())
{
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);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров по типу |
//+------------------------------------------------------------------+
void DelOrderType(int type)
{
bool del;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==type) del=OrderDelete(OrderTicket());
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CrossBars()
{
int bar=0;
for(int i=0;i<100;i++)
{
double ao1=iAO(NULL,0,i);
double ao2=iAO(NULL,0,i+1);
if((ao1>0 && ao2<0) || (ao1<0 && ao2>0))
{
bar=i;
break;
}
}
return(bar);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
}
}
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
double ao1=iAO(NULL,0,1);
double ao2=iAO(NULL,0,2);
double ao3=iAO(NULL,0,3);
double low=Low[iLowest(NULL,0,MODE_LOW,CrossBars(),1)];
double high=High[iHighest(NULL,0,MODE_HIGH,CrossBars(),1)];
if(One)
{
if(CountTrades()<1)
{
if(ao1>0 && ao2>ao1 && ao2>ao3 && CountOrders(4)<1 && Bid<high && b)
{
PutOrder(4,high);
b=false;s=true;
}
if(ao1<0 && ao2<ao1 && ao2<ao3 && CountOrders(5)<1 && Bid>low && s)
{
PutOrder(5,low);
s=false;b=true;
}
}
}
if(!One)
{
if(ao1>0 && ao2>ao1 && ao2>ao3 && CountOrders(4)<1 && Bid<high && b)
{
PutOrder(4,high);
b=false;s=true;
}
if(ao1<0 && ao2<ao1 && ao2<ao3 && CountOrders(5)<1 && Bid>low && s)
{
PutOrder(5,low);
s=false;b=true;
}
}
if((ao1>0 && ao2<0 && SSDel) || (ao1<0 && ao2>0 && BSDel)) DelOrder();
if(CloseOn>0)
{
if(ao2>0 && ao1<0)
{
CloseAll(0);
DelOrderType(2);
DelOrderType(4);
}
if(ao2<0 && ao1>0)
{
CloseAll(1);
DelOrderType(3);
DelOrderType(5);
}
}
Comment(CrossBars());
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Month.mq4 |
//| Copyright 2017, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
#property indicator_chart_window
input int Count=5;
input int Heigth=500;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
ObjectsDeleteAll(0,0,OBJ_TEXT);
ObjectsDeleteAll(0,0,OBJ_RECTANGLE);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutRect(string name,datetime t1,double p1,datetime t2,double p2,color clr)
{
ObjectDelete(0,name);
//--- создадим прямоугольник по заданным координатам
ObjectCreate(0,name,OBJ_RECTANGLE,0,t1,p1,t2,p2);
//--- установим цвет прямоугольника
ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutText(string name,const string text,double price,datetime time,const color clr)
{
ObjectDelete(0,name);
//--- create a "Text" object
ObjectCreate(0,name,OBJ_TEXT,0,time,price);
//--- set the text
ObjectSetString(0,name,OBJPROP_TEXT,text);
//--- set the font of the text
ObjectSetString(0,name,OBJPROP_FONT,"Arial");
//--- set the font size
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,11);
//--- set the method binding
ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_UPPER);
//--- set the color
ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
datetime t1=0,t2=0;
double Hi=0,Lo=0,Mid=0;
for(int i=1;i<=Count;i++)
{
t1=iTime(NULL,PERIOD_MN1,i-1);
t2=iTime(NULL,PERIOD_MN1,i);
Hi=iHigh(NULL,PERIOD_MN1,i);
Lo=iLow(NULL,PERIOD_MN1,i);
Mid+=(Hi-Lo)/_Point;
PutRect("UP"+(string)i,t1,Hi,t2,Hi+Heigth*Point,Red);
PutRect("DN"+(string)i,t1,Lo,t2,Lo-Heigth*Point,Blue);
string txt=(string)(NormalizeDouble((Hi-Lo)/_Point,0));
PutText("TXT"+(string)i,txt,Hi+Heigth*4*Point,t1,Blue);
}
t1=Time[0];
t2=iTime(NULL,PERIOD_MN1,0);
Hi=iHigh(NULL,PERIOD_MN1,0);
Lo=iLow(NULL,PERIOD_MN1,0);
PutRect("UP"+(string)0,t1,Lo+(Mid/Count)*Point,t2,Lo+(Mid/Count)*Point+Heigth*Point,Red);
PutRect("DN"+(string)0,t1,Hi-(Mid/Count)*Point,t2,Hi-(Mid/Count)*Point-Heigth*Point,Blue);
Comment("\n АТР 12 месяцев: ",(int)Mid/Count);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
индикатор предсказывает тренды 20 — 200 пипсов
с вероятностью 90 процентов
AM2