//+------------------------------------------------------------------+
//| FiboLevel.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
extern double Lots = 0.1; // лот
extern int Slip = 5; // реквот
extern int Magic = 123; // магик
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string Name()
{
string name="";
for(int i=ObjectsTotal()-1;i>=0;i--)
{
if(StringFind(ObjectName(i),"Fibo",0)>-1) name=ObjectName(i);
}
return(name);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price,double stop,double take)
{
int r=0;
color clr=Green;
double sl=0,tp=0;
if(type==1 || type==3 || type==5)
{
clr=Red;
sl=NormalizeDouble(stop,_Digits);
tp=NormalizeDouble(take,_Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
sl=NormalizeDouble(stop,_Digits);
tp=NormalizeDouble(take,_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);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
string name=Name();
double p0=NormalizeDouble(ObjectGet(name,OBJPROP_PRICE2),_Digits);
double p100=NormalizeDouble(ObjectGet(name,OBJPROP_PRICE1),_Digits);
double p1618=NormalizeDouble((p100-p0)*1.618+p0,_Digits);
double p2618=NormalizeDouble((p100-p0)*2.618+p0,_Digits);
if(CountTrades()<1)
{
if(p100>p0 && Ask>p100)
{
PutOrder(0,Ask,p0,p1618);
PutOrder(0,Ask,p0,p2618);
}
if(p100<p0 && Bid<p100)
{
PutOrder(1,Bid,p0,p1618);
PutOrder(1,Bid,p0,p2618);
}
}
Comment("\n Fibo 100: ",p100,
"\n Fibo 0: ",p0,
"\n Name: ",Name());
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| LevelsPainter.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
#property indicator_chart_window
input int LineWidth=1;
input int LineStyle=3;
input color LineColor=Red;
input int LabelWidth=1;
input color LabelColor=Red;
input int BarsCount=10;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
ModeObjects();
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutTrendLine(string name,datetime time1,double price1,datetime time2,double price2)
{
ObjectCreate(0,name,OBJ_TREND,0,time1,price1,time2,price2);
//--- установим цвет линии
ObjectSetInteger(0,name,OBJPROP_COLOR,LineColor);
//--- установим стиль отображения линии
ObjectSetInteger(0,name,OBJPROP_STYLE,LineStyle);
//--- установим толщину линии
ObjectSetInteger(0,name,OBJPROP_WIDTH,LineWidth);
//--- включим (true) или отключим (false) режим продолжения отображения линии вправо
ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ModeObjects()
{
for(int i=ObjectsTotal()-1;i>=0;i--)
{
if(ObjectType(ObjectName(i))==OBJ_TREND) ObjectSet(ObjectName(i),OBJPROP_TIME2,Time[0]+PeriodSeconds()*BarsCount);
if(ObjectType(ObjectName(i))==OBJ_ARROW_RIGHT_PRICE) ObjectSet(ObjectName(i),OBJPROP_TIME,Time[0]+PeriodSeconds()*BarsCount);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutRightLabel(string name,datetime time,double price)
{
//--- создадим текстовую метку
ObjectCreate(0,name,OBJ_ARROW_RIGHT_PRICE,0,time,price);
//--- установим размер метки
ObjectSetInteger(0,name,OBJPROP_WIDTH,LabelWidth);
//--- установим цвет
ObjectSetInteger(0,name,OBJPROP_COLOR,LabelColor);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
//--- если это события клика мышки на графике
if(id==CHARTEVENT_CLICK)
{
//--- подготовим переменные
int x =(int)lparam;
int y =(int)dparam;
datetime dt =0;
double price =0;
int window=0;
//--- преобразуем координаты X и Y в терминах дата/время
if(ChartXYToTimePrice(0,x,y,window,dt,price))
{
PutTrendLine("Line"+(string)price,dt,price,Time[0]+PeriodSeconds()*BarsCount,price);
PutRightLabel("Label"+(string)price,Time[0]+PeriodSeconds()*BarsCount,price);
ChartRedraw(0);
}
}
}
//+------------------------------------------------------------------+
AM2