<code> //+------------------------------------------------------------------+ //| Smurfik.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 StartHour = 0; // час начала торговли extern int StartMin = 30; // минута начала торговли extern int EndHour = 23; // час окончания торговли extern int EndMin = 30; // минута окончания торговли extern int Slip = 30; // реквот extern int Shift = 1; // на каком баре сигнал индикатора extern int Magic = 123; // магик extern string IndName = "CCI_smoothed"; input int CCI_Period = 14; input ENUM_APPLIED_PRICE CCI_Price = 0; input int Period_Smoothed = 3; input ENUM_MA_METHOD MA_Method = 0; extern double cci_buy_level = -100; extern double cci_sell_level = 100; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- Comment(""); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { Comment(""); } 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 blu = iCustom(NULL,0,IndName,CCI_Period,CCI_Price,Period_Smoothed,MA_Method,cci_buy_level,cci_sell_level,0,Shift); double red = iCustom(NULL,0,IndName,CCI_Period,CCI_Price,Period_Smoothed,MA_Method,cci_buy_level,cci_sell_level,1,Shift); if(blu>0) { PutOrder(0,Ask); } if(red>0) { PutOrder(1,Bid); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void ClosePos() { double blu = iCustom(NULL,0,IndName,CCI_Period,CCI_Price,Period_Smoothed,MA_Method,cci_buy_level,cci_sell_level,0,Shift); double red = iCustom(NULL,0,IndName,CCI_Period,CCI_Price,Period_Smoothed,MA_Method,cci_buy_level,cci_sell_level,1,Shift); if(red>0) { CloseAll(0); } if(blu>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(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) { if(OrderProfit()>0) break; if(OrderProfit()<0) { lot=OrderLots()*KLot; break; } } } } if(lot>MaxLot)lot=Lots; return(lot); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Trailing() { bool mod; for(int i=OrdersTotal()-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) { if(OrderType()==OP_BUY) { if(Bid-OrderOpenPrice()>TrailingStop*Point) { if(OrderStopLoss()<Bid-TrailingStop*Point) { mod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,Yellow); return; } } } if(OrderType()==OP_SELL) { if((OrderOpenPrice()-Ask)>TrailingStop*Point) { if((OrderStopLoss()>(Ask+TrailingStop*Point)) || (OrderStopLoss()==0)) { mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Yellow); return; } } } } } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ 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 blu = iCustom(NULL,0,IndName,CCI_Period,CCI_Price,Period_Smoothed,MA_Method,cci_buy_level,cci_sell_level,0,Shift); double red = iCustom(NULL,0,IndName,CCI_Period,CCI_Price,Period_Smoothed,MA_Method,cci_buy_level,cci_sell_level,1,Shift); if(CountTrades()<1 && isTradeTimeInt(StartHour,StartMin,EndHour,EndMin)) OpenPos(); else ClosePos(); if(BULevel>0) BU(); if(TrailingStop>0) Trailing(); Comment("\n blu: ",blu, "\n red: ",red); } //+------------------------------------------------------------------+ </code>
Привет можешь убрать риск а то я не разобрался и добавить в настройки множитель лота
void OnDeinit(const int reason)
{
Comment("");
if(REASON_REMOVE == _UninitReason) ObjectDelete(0,"L");
}
//+------------------------------------------------------------------+
//| ATRM.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
#define KEY_UP 38
#define KEY_DOWN 40
input int Shift=0;
int atr=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
if(REASON_REMOVE == _UninitReason) ObjectDelete(0,"L");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutLabel(string text)
{
ObjectDelete(0,"L");
//--- создадим текстовую метку
ObjectCreate(0,"L",OBJ_LABEL,0,0,0);
//--- установим координаты метки
ObjectSetInteger(0,"L",OBJPROP_XDISTANCE,55);
ObjectSetInteger(0,"L",OBJPROP_YDISTANCE,10);
//--- установим угол графика, относительно которого будут определяться координаты точки
ObjectSetInteger(0,"L",OBJPROP_CORNER,1);
//--- установим текст
ObjectSetString(0,"L",OBJPROP_TEXT,text);
//--- установим шрифт текста
ObjectSetString(0,"L",OBJPROP_FONT,"Arial");
//--- установим размер шрифта
ObjectSetInteger(0,"L",OBJPROP_FONTSIZE,12);
//--- установим цвет
ObjectSetInteger(0,"L",OBJPROP_COLOR,Red);
}
//+------------------------------------------------------------------+
//| ChartEvent function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, // идентификатор события
const long& lparam, // параметр события типа long
const double& dparam, // параметр события типа double
const string& sparam // параметр события типа string
)
{
//--- нажатие кнопки на клавиатуре
if(id==CHARTEVENT_KEYDOWN)
{
if(lparam==38) PutLabel((string)atr);
if(lparam==40) ObjectDelete(0,"L");
}
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
atr=(int)((iHigh(NULL,PERIOD_MN1,Shift)-iLow(NULL,PERIOD_MN1,Shift))/_Point);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Smurfik.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 TrailingStop = 0; // трал
extern int StartHour = 0; // час начала торговли
extern int StartMin = 30; // минута начала торговли
extern int EndHour = 23; // час окончания торговли
extern int EndMin = 30; // минута окончания торговли
extern int Slip = 30; // реквот
extern int Shift = 1; // на каком баре сигнал индикатора
extern int Magic = 123; // магик
extern string IndName = "CCI smoothed arrow";
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
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 blu = iCustom(NULL,0,IndName,0,Shift);
double red = iCustom(NULL,0,IndName,1,Shift);
if(blu>0)
{
PutOrder(0,Ask);
}
if(red>0)
{
PutOrder(1,Bid);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ClosePos()
{
double blu = iCustom(NULL,0,IndName,0,Shift);
double red = iCustom(NULL,0,IndName,1,Shift);
if(red>0)
{
CloseAll(0);
}
if(blu>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(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()>0) break;
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
break;
}
}
}
}
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Trailing()
{
bool mod;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(Bid-OrderOpenPrice()>TrailingStop*Point)
{
if(OrderStopLoss()<Bid-TrailingStop*Point)
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
if(OrderType()==OP_SELL)
{
if((OrderOpenPrice()-Ask)>TrailingStop*Point)
{
if((OrderStopLoss()>(Ask+TrailingStop*Point)) || (OrderStopLoss()==0))
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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 blu = iCustom(NULL,0,IndName,0,Shift);
double red = iCustom(NULL,0,IndName,1,Shift);
if(CountTrades()<1 && isTradeTimeInt(StartHour,StartMin,EndHour,EndMin)) OpenPos();
else ClosePos();
if(BULevel>0) BU();
if(TrailingStop>0) Trailing();
Comment("\n blu: ",blu,
"\n red: ",red);
}
//+------------------------------------------------------------------+
Этого не проверял как увидел что к ручному ТП не ставит
juozas