
input int ma1p=12;//период ма1
input int ma2p=12;//период ма2
input int ma1s=0;//сдвиг ма1
input int ma2s=12;//сдвиг ма2
input int ma1m=0;//метод ма1
input int ma2m=0;//метод ма2
input int ma1pr=0;//цены ма1
input int ma2pr=0;//цены ма2
//+------------------------------------------------------------------+
//| Info.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
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2
input int ma1p=12;//период ма1
input int ma2p=12;//период ма2
input int ma1s=0;//сдвиг ма1
input int ma2s=12;//сдвиг ма2
input int ma1m=0;//метод ма1
input int ma2m=0;//метод ма2
input int ma1pr=0;//цены ма1
input int ma2pr=0;//цены ма2
//--- buffers
double up[];
double dn[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(0,up);
SetIndexBuffer(1,dn);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Горизонтальная линия |
//+------------------------------------------------------------------+
void PutHLine(string name,double p)
{
ObjectDelete(0,name);
ObjectCreate(0,name,OBJ_HLINE,0,0,p);
//--- установим цвет линии
ObjectSetInteger(0,name,OBJPROP_COLOR,Red);
//--- установим толщину линии
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DOT);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutLabel(string text)
{
ObjectDelete(0,"L");
//--- создадим текстовую метку
ObjectCreate(0,"L",OBJ_LABEL,0,0,0);
//--- установим координаты метки
ObjectSetInteger(0,"L",OBJPROP_XDISTANCE,48);
ObjectSetInteger(0,"L",OBJPROP_YDISTANCE,24);
//--- установим угол графика, относительно которого будут определяться координаты точки
ObjectSetInteger(0,"L",OBJPROP_CORNER,1);
//--- установим текст
ObjectSetString(0,"L",OBJPROP_TEXT,text);
//--- установим шрифт текста
ObjectSetString(0,"L",OBJPROP_FONT,"Arial Bold");
//--- установим размер шрифта
ObjectSetInteger(0,"L",OBJPROP_FONTSIZE,12);
//--- установим цвет
ObjectSetInteger(0,"L",OBJPROP_COLOR,Red);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutRectLabel()
{
ObjectDelete(0,"R");
ObjectCreate(0,"R",OBJ_RECTANGLE_LABEL,0,0,0);
//--- установим координаты метки
ObjectSetInteger(0,"R",OBJPROP_XDISTANCE,55);
ObjectSetInteger(0,"R",OBJPROP_YDISTANCE,22);
//--- установим размеры метки
ObjectSetInteger(0,"R",OBJPROP_XSIZE,44);
ObjectSetInteger(0,"R",OBJPROP_YSIZE,22);
//--- установим цвет фона
ObjectSetInteger(0,"R",OBJPROP_BGCOLOR,Gray);
//--- установим угол графика, относительно которого будут определяться координаты точки
ObjectSetInteger(0,"R",OBJPROP_CORNER,1);
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
for(int i=0; i<rates_total; i++)
{
up[i]=iMA(NULL,0,ma1p,ma1s,ma1m,ma1pr,i);
dn[i]=iMA(NULL,0,ma2p,ma2s,ma2m,ma2pr,i);
}
PutHLine("upl",up[0]);
PutHLine("dnl",dn[0]);
double d=(up[0]-dn[0])/Point;
PutRectLabel();
PutLabel((string)(int)d);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Info.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
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2
input int ma1p=12;
input int ma2p=12;
input int ma1s=0;
input int ma2s=12;
input int ma1m=0;
input int ma2m=0;
input int ma1pr=0;
input int ma2pr=0;
//--- buffers
double up[];
double dn[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(0,up);
SetIndexBuffer(1,dn);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Горизонтальная линия |
//+------------------------------------------------------------------+
void PutHLine(string name,double p)
{
ObjectDelete(0,name);
ObjectCreate(0,name,OBJ_HLINE,0,0,p);
//--- установим цвет линии
ObjectSetInteger(0,name,OBJPROP_COLOR,Red);
//--- установим толщину линии
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DOT);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutLabel(string text)
{
ObjectDelete(0,"L");
//--- создадим текстовую метку
ObjectCreate(0,"L",OBJ_LABEL,0,0,0);
//--- установим координаты метки
ObjectSetInteger(0,"L",OBJPROP_XDISTANCE,48);
ObjectSetInteger(0,"L",OBJPROP_YDISTANCE,24);
//--- установим угол графика, относительно которого будут определяться координаты точки
ObjectSetInteger(0,"L",OBJPROP_CORNER,1);
//--- установим текст
ObjectSetString(0,"L",OBJPROP_TEXT,text);
//--- установим шрифт текста
ObjectSetString(0,"L",OBJPROP_FONT,"Arial Bold");
//--- установим размер шрифта
ObjectSetInteger(0,"L",OBJPROP_FONTSIZE,12);
//--- установим цвет
ObjectSetInteger(0,"L",OBJPROP_COLOR,Red);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutRectLabel()
{
ObjectDelete(0,"R");
ObjectCreate(0,"R",OBJ_RECTANGLE_LABEL,0,0,0);
//--- установим координаты метки
ObjectSetInteger(0,"R",OBJPROP_XDISTANCE,55);
ObjectSetInteger(0,"R",OBJPROP_YDISTANCE,22);
//--- установим размеры метки
ObjectSetInteger(0,"R",OBJPROP_XSIZE,44);
ObjectSetInteger(0,"R",OBJPROP_YSIZE,22);
//--- установим цвет фона
ObjectSetInteger(0,"R",OBJPROP_BGCOLOR,Gray);
//--- установим угол графика, относительно которого будут определяться координаты точки
ObjectSetInteger(0,"R",OBJPROP_CORNER,1);
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
for(int i=0; i<rates_total; i++)
{
up[i]=iMA(NULL,0,ma1p,ma1s,ma1m,ma1pr,i);
dn[i]=iMA(NULL,0,ma2p,ma2s,ma2m,ma2pr,i);
}
PutHLine("upl",up[0]);
PutHLine("dnl",dn[0]);
double d=(up[0]-dn[0])/Point;
PutRectLabel();
PutLabel((string)(int)d);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Chess.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
//--- 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 BuySell = 1; // 1-первая бай 2-селл
extern int Losses = 3; // лосей
extern int Magic = 123; // магик
bool b=1,s=1;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
if(BuySell==2)b=0;
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| Считает количество убыточных сделок в истории |
//+------------------------------------------------------------------+
int Loss()
{
int losses=0;
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==0)
{
if(OrderOpenPrice()-OrderClosePrice()>0) losses++;
if(OrderOpenPrice()-OrderClosePrice()<0) break;
}
if(OrderType()==1)
{
if(OrderOpenPrice()-OrderClosePrice()<0) losses++;
if(OrderOpenPrice()-OrderClosePrice()>0) break;
}
}
}
}
return(losses);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(Delta()>0) lot=Lots;
if(Loss()>=Losses)
{
lot=OrderLots()*KLot;
break;
}
}
}
}
if(lot>MaxLot)lot=MaxLot;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int Delta()
{
int plus=0;
int minus=0;
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()>0) plus++;
if(OrderProfit()<0) minus++;
}
}
}
return(plus-minus);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(CountTrades()<1 && b)
{
PutOrder(0,Ask);
b=0;s=1;
}
if(CountTrades()<1 && s)
{
PutOrder(1,Bid);
s=0;b=1;
}
Comment("\n Losses: ",Loss(),"\n Delta: ",Delta());
}
//+------------------------------------------------------------------+
AM2