
//+------------------------------------------------------------------+
//| Cycle.mq4 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double KLot = 1; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern int MaxTrades = 5; // число поз
extern int StopLoss = 2000; // лось
extern int TakeProfit = 3000; // язь
extern int Slip = 30; // реквот
extern int Shift = 1; // на каком баре сигнал индикатора
extern int CloseSig = 1; // 1-закрытие по сигналу
extern int Magic = 123; // магик
extern string IndName="CycleIdentifier";
extern int PriceActionFilter=5;
extern int Length=7;
extern int MajorCycleStrength=8;
extern bool UseCycleFilter=false;
extern int UseFilterSMAorRSI=60;
extern int FilterStrengthSMA=85;
extern int FilterStrengthRSI=100;
extern bool SoundAlert=true;
extern bool WaitForClose=true;
extern string note1 = "alert all = 0";
extern string note2 = "buy only = 1, sell only = 2";
extern int alertsOption=0;
datetime t=0;
double lt[10]={0.1,0.2,0.4,0.6,0.8,1,1.2,1.4,1.6,1.8};
//+------------------------------------------------------------------+
//| 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 sig=iCustom(NULL,0,IndName,PriceActionFilter,Length,MajorCycleStrength,UseCycleFilter,UseFilterSMAorRSI,FilterStrengthSMA,FilterStrengthRSI,SoundAlert,WaitForClose,note1,note2,alertsOption,0,Shift);
if(sig<0)
{
PutOrder(0,Ask);
}
if(sig>0)
{
PutOrder(1,Bid);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ClosePos()
{
double sig=iCustom(NULL,0,IndName,PriceActionFilter,Length,MajorCycleStrength,UseCycleFilter,UseFilterSMAorRSI,FilterStrengthSMA,FilterStrengthRSI,SoundAlert,WaitForClose,note1,note2,alertsOption,0,Shift);
if(sig>0)
{
CloseAll(0);
}
if(sig<0)
{
CloseAll(1);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=lt[CountTrades()];
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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()
{
if(t!=Time[0])
{
if(CountTrades()<MaxTrades) OpenPos();
t=Time[0];
}
if(CloseSig>0) ClosePos();
Comment(iCustom(NULL,0,IndName,PriceActionFilter,Length,MajorCycleStrength,UseCycleFilter,UseFilterSMAorRSI,FilterStrengthSMA,FilterStrengthRSI,SoundAlert,WaitForClose,note1,note2,alertsOption,0,Shift));
}
//+------------------------------------------------------------------+
Comment("\n ZZ0: ",ZigzagBuffer[0],
"\n H: ",HighMapBuffer[1],
"\n L: ",LowMapBuffer[1],
"\n CLR: ",(color)ObjectGet("ZZLabel_Leg1",OBJPROP_COLOR));
//+------------------------------------------------------------------+
//| FiboLevels.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, 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 = 500; //лось
extern int TakeProfit = 500; //язь
extern int BULevel = 300; //уровень бу
extern int BUPoint = 30; //пункты бу
extern int TrailingStop = 300; //трал
extern int Delta = 100; //проход цены
extern int Slip = 10; //проскальзывание
extern int Expiration = 10; //время истечения ордера
extern int Start = 1; //начальный бар
extern int End = 20; //конечный бар
extern int Magic = 123; //магик
int cross=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=clrNONE;
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,TimeCurrent()+Expiration*3600,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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountOrders(int type)
{
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()==type) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Cоздает "Уровни Фибоначчи" по заданным координатам |
//+------------------------------------------------------------------+
void FiboLevelsCreate(datetime t1,double p1,datetime t2,double p2)
{
ObjectsDeleteAll(0,OBJ_FIBO);
//--- создадим "Уровни Фибоначчи" по заданным координатам
ObjectCreate(0,"FiboLevels",OBJ_FIBO,0,t1,p1,t2,p2);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CrossUP(double p)
{
int res=0;
if(Open[0]<p && Bid-p>=Delta*Point) res=1;
return(res);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CrossDN(double p)
{
int res=0;
if(Open[0]>p && p-Bid>=Delta*Point) res=1;
return(res);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Trailing()
{
bool mod;
for(int i=0; i<OrdersTotal(); 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=0; i<OrdersTotal(); 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,Green);
return;
}
}
if(OrderType()==OP_SELL)
{
if(OrderOpenPrice()>=(Ask+(BULevel+BUPoint)*Point) && OrderOpenPrice()<OrderStopLoss())
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-BUPoint*Point,OrderTakeProfit(),0,Green);
return;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderProfit()>0) break;
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
break;
}
}
}
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double up=High[iHighest(NULL,0,MODE_HIGH,End,Start)];
double dn=Low[iLowest(NULL,0,MODE_LOW,End,Start)];
FiboLevelsCreate(Time[Start],up,Time[End],dn);
string name="FiboLevels";
double F = ObjectGet(name, OBJPROP_PRICE1);
double S = ObjectGet(name, OBJPROP_PRICE2);
double p0=NormalizeDouble(S,Digits);
double p100 = NormalizeDouble(F, Digits);
double p236 = NormalizeDouble((F-S)*0.236+S, Digits);
double p382 = NormalizeDouble((F-S)*0.382+S, Digits);
double p50=NormalizeDouble((F-S)*0.50+S,Digits);
double p618=NormalizeDouble((F-S)*0.618+S,Digits);
if(High[1]>p50 && Low[1]<p50) cross=1;
if(Hour()==5) cross=0;
if(CountTrades()<1)
{
if(CountOrders(4)<1 && CrossDN(p50)==1) PutOrder(4,p50);
if(CountOrders(5)<1 && CrossUP(p50)==1) PutOrder(5,p50);
}
if(BULevel>0) BU();
if(TrailingStop>0) Trailing();
Comment("\n Fibo 100: ",p100,
"\n Fibo 0: ",p0,
"\n Fibo 236: ",p236,
"\n Fibo 382: ",p382,
"\n Fibo 50: ",p50,
"\n Fibo 618: ",p618,
"\n Name: ",name,
"\n Cross: ",cross,
"\n CrossUP: ",CrossUP(p50),
"\n CrossDN: ",CrossDN(p50));
}
//+------------------------------------------------------------------+
AM2