//+------------------------------------------------------------------+
//| Extreme.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 BULevel = 0; // уровень БУ
extern int BUPoint = 30; // пункты БУ
extern int TrailingStop = 0; // трал
extern int Slip = 30; // реквот
extern int Shift = 1; // на каком баре сигнал индикатора
extern int Magic = 123; // магик
extern string IndName = "ExtremeTMALine";
extern string TimeFrame = "Current";
extern int TMAPeriod = 56;
extern int Price = PRICE_CLOSE;
extern double ATRMultiplier = 2.0;
extern int ATRPeriod = 100;
extern double TrendThreshold = 0.5;
extern string IndName2 = "TmaSlope.v1.5 Normalized";
extern string TimeFrames="0";
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,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 lim=iCustom(NULL,0,IndName2,TimeFrames,1,Shift);
double red=iCustom(NULL,0,IndName2,TimeFrames,3,Shift);
double up=iCustom(NULL,0,IndName,TimeFrame,TMAPeriod,Price,ATRMultiplier,ATRPeriod,TrendThreshold,1,Shift);
double dn=iCustom(NULL,0,IndName,TimeFrame,TMAPeriod,Price,ATRMultiplier,ATRPeriod,TrendThreshold,2,Shift);
if(Open[Shift]<up && Close[Shift]>up && lim!=0) PutOrder(0,Ask);
if(Open[Shift]>dn && Close[Shift]<dn && red!=0) PutOrder(1,Bid);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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 BU()
{
bool m;
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(OrderOpenPrice()<=(Bid-(BULevel+BUPoint)*Point) && OrderOpenPrice()>OrderStopLoss())
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+BUPoint*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
if(OrderType()==OP_SELL)
{
if(OrderOpenPrice()>=(Ask+(BULevel+BUPoint)*Point) && (OrderOpenPrice()<OrderStopLoss() || OrderStopLoss()==0))
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-BUPoint*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double lim=iCustom(NULL,0,IndName2,TimeFrames,1,Shift);
double red=iCustom(NULL,0,IndName2,TimeFrames,3,Shift);
if(CountTrades()<1) OpenPos();
if(BULevel>0) BU();
if(TrailingStop>0) Trailing();
Comment("\n lime: ",lim,
"\n red: ",red);
}
//+------------------------------------------------------------------+
от года до года
//+------------------------------------------------------------------+
//| ATRGod.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
input int delta=1000;
int sigma=1000;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| 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 shift=iBarShift(NULL,PERIOD_MN1,StringToTime("31"+".12."+(string(Year()-1))));
double lo=iLow(NULL,PERIOD_MN1,iLowest(NULL,PERIOD_MN1,MODE_LOW,shift,0));
double hi=iHigh(NULL,PERIOD_MN1,iHighest(NULL,PERIOD_MN1,MODE_HIGH,shift,0));
PutRect("UP",time[0],hi-delta*_Point,time[shift],hi-(delta+sigma)*_Point,Green);
PutRect("DN",time[0],lo+delta*_Point,time[shift],lo+(delta+sigma)*_Point,Green);
Comment("\n BAR: ",shift);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
блин, так не честно, вы убрали удаление в deinit которое я думал вы вообще трогать не будете(( эхх, ладно создам новый топик в надежде что кто-то станет поручителем, очень нужно
а возможно ли сделать чтобы при удалении индикатора удалялось бы и число??
//+------------------------------------------------------------------+
//| 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("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
CHART_EVENT_OBJECT_DELETE=false
для запрета удаления объекта с графика
AM2