//+------------------------------------------------------------------+
//| SLClose.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
input int Sec=15;
input int Slip=30;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
datetime OrderOpenTm()
{
datetime t=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()<2) t=OrderOpenTime();
}
}
return(t);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseAll()
{
bool cl;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==OP_SELL)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if((TimeCurrent()-OrderOpenTm())>Sec && OrderStopLoss()==0)
{
CloseAll();
}
}
}
}
//+------------------------------------------------------------------+
void OnTick()
{
if(t!=Time[0])
{
if(TrailingStop>0) Trailing();
TradeBuy(BuyMagic);
TradeSell(SellMagic);
t=Time[0];
}
}
//+------------------------------------------------------------------+
//| Date.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 string Date="01.01.2017";
input int DayCount=5;
input int WeakCount=5;
input int MonthCount=5;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutLabel(string name,int x,int y,string text)
{
ObjectDelete(0,name);
//--- создадим текстовую метку
ObjectCreate(0,name,OBJ_LABEL,0,0,0);
//--- установим координаты метки
ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
//--- установим угол графика, относительно которого будут определяться координаты точки
ObjectSetInteger(0,name,OBJPROP_CORNER,1);
//--- установим текст
ObjectSetString(0,name,OBJPROP_TEXT,text);
//--- установим шрифт текста
ObjectSetString(0,name,OBJPROP_FONT,"Arial");
//--- установим размер шрифта
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,10);
//--- установим цвет
ObjectSetInteger(0,name,OBJPROP_COLOR,Yellow);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int Vol(int count,ENUM_TIMEFRAMES tf)
{
int date=iBarShift(NULL,0,(datetime)Date);
int vol=0;
for(int i=date;i<=date+count;i++)
{
vol+=(int)(MathAbs(iOpen(NULL,tf,i)-iClose(NULL,tf,i))/_Point/count);
}
return(vol);
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
int date=iBarShift(NULL,0,(datetime)Date);
int date1=iBarShift(NULL,PERIOD_D1,(datetime)Date);
int date2=iBarShift(NULL,PERIOD_W1,(datetime)Date);
int date3=iBarShift(NULL,PERIOD_MN1,(datetime)Date);
string s="";
string s1="Дата: "+Date;
string s2="ДВ: "+(string)Vol(DayCount,PERIOD_D1)+"("+(string)DayCount+")";
string s3="НВ: "+(string)Vol(WeakCount,PERIOD_W1)+"("+(string)WeakCount+")";
string s4="МВ: "+(string)Vol(MonthCount,PERIOD_MN1)+"("+(string)MonthCount+")";
string s5="СДЦ : "+(string)MathAbs(iOpen(NULL,PERIOD_D1,date1)+iOpen(NULL,PERIOD_D1,date1)/2);
string s6="СНЦ : "+(string)MathAbs(iOpen(NULL,PERIOD_W1,date1)+iOpen(NULL,PERIOD_W1,date1)/2);
string s7="СМЦ : "+(string)MathAbs(iOpen(NULL,PERIOD_MN1,date1)+iOpen(NULL,PERIOD_MN1,date1)/2);
PutLabel("L1",125,15,s1);
PutLabel("L2",125,30,s2);
PutLabel("L3",125,45,s3);
PutLabel("L4",125,60,s4);
PutLabel("L5",125,75,s5);
PutLabel("L6",125,90,s6);
PutLabel("L7",125,105,s7);
Comment("\n Date: ",Date,
"\n Bar: ",date,
"\n Vol: ",Vol(DayCount,PERIOD_D1));
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
...
int PointsProfit = (OrderOpenPrice()-Bid)/Point;
Или с таким советником реверс не совместим?
//+------------------------------------------------------------------+
//| Perceptron.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//---- input parameters
extern double tp = 50;
extern double sl = 50;
extern int p=10;
extern int x1 = 100;
extern int x2 = 100;
extern int x3 = 100;
extern int x4 = 100;
extern int loss=3;
extern int Reverce = 0; // 1-реверс
extern double Lots = 0.1; // лот
extern double KLot = 2; // умножение лота
extern double MaxLot = 5; // максимальный лот
datetime tm=0;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=Green;
double s=0,t=0;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(sl>0) s=NormalizeDouble(price+sl*Point,Digits);
if(tp>0) t=NormalizeDouble(price-tp*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(sl>0) s=NormalizeDouble(price-sl*Point,Digits);
if(tp>0) t=NormalizeDouble(price+tp*Point,Digits);
}
r=OrderSend(NULL,type,Lot(),NormalizeDouble(price,Digits),33,s,t,"",0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double perceptron()
{
double w1 = x1 - 100;
double w2 = x2 - 100;
double w3 = x3 - 100;
double w4 = x4 - 100;
double a1 = Open[p] - Close[0];
double a2 = Open[p] - Open[p*2];
double a3 = Open[p*2] - Open[p * 3];
double a4 = Open[p*3] - Open[p * 4];
return(w1 * a1 + w2 * a2 + w3 * a3 + w4 * a4);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(OrdersTotal()<1 && tm!=Time[0])
{
if(Reverce==0)
{
if(perceptron()<0) PutOrder(0,Ask);
if(perceptron()>0) PutOrder(1,Bid);
}
if(Reverce==1)
{
if(perceptron()>0) PutOrder(0,Ask);
if(perceptron()<0) PutOrder(1,Bid);
}
tm=Time[0];
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Perceptron.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//---- input parameters
extern double tp = 50;
extern double sl = 50;
extern int p=10;
extern int x1 = 100;
extern int x2 = 100;
extern int x3 = 100;
extern int x4 = 100;
extern int loss = 3;
extern double Lots = 0.1; // лот
extern double KLot = 2; // умножение лота
extern double MaxLot = 5; // максимальный лот
datetime tm=0;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=Green;
double s=0,t=0;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(sl>0) s=NormalizeDouble(price+sl*Point,Digits);
if(tp>0) t=NormalizeDouble(price-tp*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(sl>0) s=NormalizeDouble(price-sl*Point,Digits);
if(tp>0) t=NormalizeDouble(price+tp*Point,Digits);
}
r=OrderSend(NULL,type,Lot(),NormalizeDouble(price,Digits),33,s,t,"",0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double perceptron()
{
double w1 = x1 - 100;
double w2 = x2 - 100;
double w3 = x3 - 100;
double w4 = x4 - 100;
double a1 = Open[p] - Close[0];
double a2 = Open[p] - Open[p*2];
double a3 = Open[p*2] - Open[p * 3];
double a4 = Open[p*3] - Open[p * 4];
return(w1 * a1 + w2 * a2 + w3 * a3 + w4 * a4);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(OrdersTotal()<1 && tm!=Time[0])
{
if(perceptron()<0) PutOrder(0,Ask);
if(perceptron()>0) PutOrder(1,Bid);
tm=Time[0];
}
}
//+------------------------------------------------------------------+
AM2