
И на будущее всегда продумывайте ТЗ перед тем как писать.
Сможете доделать до конца?
//+------------------------------------------------------------------+
//| CCIEnter.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 int Profit = 30; // язь в валюте
extern int StopLoss = 2000; // лось
extern int TakeProfit = 3000; // язь
extern int MaxTrades = 20; // максимальное число позиций
extern int Slip = 30; // реквот
extern int CCIPeriod = 14; // период индикатора
extern int Shift = 1; // на каком баре сигнал индикатора
extern int Magic = 123; // магик
datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
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,Lots,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 OpenOrd()
{
double cci1 = iCCI(NULL,0,CCIPeriod,0,Shift);
double cci2 = iCCI(NULL,0,CCIPeriod,0,Shift+1);
if(cci1>0 && cci2<0)
{
PutOrder(4,High[1]);
}
if(cci1<0 && cci2>0)
{
PutOrder(5,Low[1]);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double LowestBuyPrice()
{
double pr=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType()==OP_BUY)
{
pr=OrderOpenPrice();
}
}
}
return(pr);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Профит всех ордеров по типу ордера |
//+------------------------------------------------------------------+
double AllProfit(int ot=-1)
{
double pr=0;
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))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
}
}
}
return(pr);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(t!=Time[0])
{
if(CountTrades()<=MaxTrades) OpenOrd();
t=Time[0];
}
if(AllProfit(0)>Profit && Profit>0) CloseAll(0);
if(AllProfit(1)>Profit && Profit>0) CloseAll(1);
Comment("\n Trades: ",CountTrades(),
"\n Buy Profit: ",AllProfit(0),
"\n Sell Profit: ",AllProfit(1),
"\n All Profit: ",AllProfit());
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| 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++)
{
Hi=iHigh(NULL,PERIOD_MN1,i);
Lo=iLow(NULL,PERIOD_MN1,i);
Mid+=(Hi-Lo)/_Point;
}
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);
PutRect("UP"+(string)i,t1,Lo+(Mid/Count)*Point,t2,Lo+(Mid/Count)*Point+Heigth*Point,Red);
PutRect("DN"+(string)i,t1,Hi-(Mid/Count)*Point,t2,Hi-(Mid/Count)*Point-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 АТР "+(string)Count+" месяцев: ",(int)Mid/Count);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
AM2