//+------------------------------------------------------------------+
//| Fibo8.mq4 |
//| Copyright 2021, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double KLot = 2; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern double Level1 = 0.382; // уровень 1
extern double Level2 = 0.5; // уровень 2
extern double Level3 = 0.618; // уровень 3
extern int StopLoss = 500; // лось
extern int TakeProfit = 280; // язь
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
int hi = iHighest(NULL,0,MODE_HIGH,33,0);
int lo = iLowest(NULL,0,MODE_LOW,33,0);
double up = High[iHighest(NULL,0,MODE_HIGH,33,0)];
double dn = Low[iLowest(NULL,0,MODE_LOW,33,0)];
PutFibo("Fibo",Time[hi],up,Time[lo],dn);
//---
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;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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 PutFibo(string name,datetime time1,double price1,datetime time2,double price2)
{
ObjectDelete(0,name);
ObjectCreate(0,name,OBJ_FIBO,0,time1,price1,time2,price2);
//--- установим цвет
ObjectSetInteger(0,name,OBJPROP_COLOR,Red);
//--- установим стиль линии
ObjectSetInteger(0,name,OBJPROP_STYLE,0);
//--- установим толщину линии
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
//--- успешное выполнение
return;
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double l0=ObjectGetDouble(0,"Fibo",OBJPROP_PRICE2);
double l100=ObjectGetDouble(0,"Fibo",OBJPROP_PRICE1);
double delta=MathAbs(l0-l100);
double l382=l0+delta*Level1;
double l500=l0+delta*Level2;
double l618=l0+delta*Level3;
if(t!=Time[0])
{
if(Open[1]<l382 && Close[1]>l382 && Level1>0)
PutOrder(0,Ask);
if(Open[1]<l500 && Close[1]>l500 && Level2>0)
PutOrder(0,Ask);
if(Open[1]<l618 && Close[1]>l618 && Level3>0)
PutOrder(0,Ask);
if(Open[1]>l382 && Close[1]<l382 && Level1>0)
PutOrder(1,Bid);
if(Open[1]>l500 && Close[1]<l500 && Level2>0)
PutOrder(1,Bid);
if(Open[1]>l618 && Close[1]<l618 && Level3>0)
PutOrder(1,Bid);
t=Time[0];
}
Comment("\n 0.0 ",l0,
"\n 100.0 ",l100,
"\n 38.2 ",l382,
"\n 50.0 ",l500,
"\n 61.8 ",l618);
}
//+------------------------------------------------------------------+
а который я скину он не перерисовывается… спасибо )
AM2