
//+------------------------------------------------------------------+
//| Grider.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 Lot = 0.1; // Trade volume
extern double KLot = 1.3; // Lot increase
extern double MaxLot = 5; // Maximum lot
extern int StopLoss = 0; // Order sroploss
extern int TakeProfit = 0; // Order takeprofit
extern int Profit = 0; // Querency Profit
extern int TrailingStop = 0; // Trailing stop
extern int TrailingStep = 0; // Trailing step
extern int Count = 5; // Orders count
extern int Expiration = 55; // The expiry of the order in hours
extern int Step = 100; // Order step
extern int Delta = 100; // Distance from the price
extern int Slip = 3; // Slippage
extern int StopLimit = 0; // 0-Stop 1-Limit
extern int ClosePos = 0; // 1-Close Positions
extern int Magic = 123; // Magic number
datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
if(!IsTradeAllowed())Alert("Allow the EA to trade!");
if(!IsLibrariesAllowed())Alert("Allow DLL import!");
if(!IsExpertEnabled()) Alert("Allow startup advisors!");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0,err=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,Lots(type),NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*3600,clr);
return;
}
//+------------------------------------------------------------------+
//| Ступенчатый трал if(TrailingStop>0) Trailing(); |
//+------------------------------------------------------------------+
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+TrailingStep-1)*Point)
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-TrailingStop*Point,Digits),OrderTakeProfit(),0,Yellow);
}
}
}
if(OrderType()==OP_SELL)
{
if((OrderOpenPrice()-Ask)>TrailingStop*Point)
{
if(OrderStopLoss()>Ask+(TrailingStop+TrailingStep-1)*Point || OrderStopLoss()==0)
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+TrailingStop*Point,Digits),OrderTakeProfit(),0,Yellow);
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Закрытие позиции по типу ордера |
//+------------------------------------------------------------------+
void CloseAll(int ot=-1)
{
bool cl;
int err=0;
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);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу |
//+------------------------------------------------------------------+
int CountOrders(int type=-1)
{
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 || (OrderType()>=0 && type==-1)) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Профит всех ордеров по типу ордера |
//+------------------------------------------------------------------+
double AllProfit(int ot=-1)
{
double pr=0;
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))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
}
}
}
return(pr);
}
//+------------------------------------------------------------------+
//| Лот для усреднителя |
//+------------------------------------------------------------------+
double Lots(int type)
{
double lots=Lot;
lots=NormalizeDouble(Lot*MathPow(KLot,CountOrders(type)),2);
if(lots>MaxLot)lots=Lot;
return(lots);
}
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров |
//+------------------------------------------------------------------+
void DelOrder(int type)
{
bool del;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==type) del=OrderDelete(OrderTicket());
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(TrailingStop>0) Trailing();
if(t!=Time[0])
{
if(Open[1]<Close[1])
{
DelOrder(5);
DelOrder(2);
for(int i=1; i<=Count;i++)
{
if(StopLimit==0)PutOrder(4,Bid+Delta*Point+Step*Point*i);//buystop
if(StopLimit==1)PutOrder(3,Bid+Delta*Point+Step*Point*i);//selllimit
}
}
if(Open[1]>Close[1])
{
DelOrder(4);
DelOrder(3);
for(int i=1; i<=Count;i++)
{
if(StopLimit==0)PutOrder(5,Bid-Delta*Point-Step*Point*i);//sellstop
if(StopLimit==1)PutOrder(2,Bid-Delta*Point-Step*Point*i);//buylimit
}
}
t=Time[0];
}
if(AllProfit()>Profit && Profit>0) CloseAll();
if(ClosePos>0 && CountOrders(0)>0 && CountOrders(1)>0) CloseAll();
Comment("\n All Profit: ",AllProfit(-1),
"\n Buy Profit: ",AllProfit(0),
"\n Sell Profit: ",AllProfit(1),
"\n Buy Positions: ",CountOrders(0),
"\n Sell Positions: ",CountOrders(1),
"\n All Positions: ",CountOrders(0)+CountOrders(1));
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Speed.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
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutText(string text,double price,datetime time)
{
string name="Text"+(string)price;
//--- создадим объект "Текст"
ObjectCreate(0,name,OBJ_TEXT,0,time,price);
//--- установим текст
ObjectSetString(0,name,OBJPROP_TEXT,text);
//--- установим шрифт текста
ObjectSetString(0,name,OBJPROP_FONT,"Arial");
//--- установим размер шрифта
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,10);
//--- установим способ привязки
ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER);
//--- установим цвет
ObjectSetInteger(0,name,OBJPROP_COLOR,Yellow);
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
int n1=0,n2=0;
double p1=0,p2=0,speed=0;
datetime t1=0,t2=0;
for(int i=ObjectsTotal();i>=0;i--)
{
if(ObjectType(ObjectName(i))==OBJ_TREND)
{
p1 = ObjectGet(ObjectName(i),OBJPROP_PRICE1);
p2 = ObjectGet(ObjectName(i),OBJPROP_PRICE2);
t1 = ObjectGet(ObjectName(i),OBJPROP_TIME1);
t2 = ObjectGet(ObjectName(i),OBJPROP_TIME2);
n1 = iBarShift(NULL,0,t1);
n2 = iBarShift(NULL,0,t2);
speed = NormalizeDouble((p1-p2)/(Point*(n1-n2)),1);
PutText((string)speed,p2,t2);
}
}
Comment("\n P1: ",p1,
"\n P2: ",p2);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Speed.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
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutText(const string text,double price,datetime time)
{
ObjectsDeleteAll(0,OBJ_TEXT);
const string name="Text"+TimeToStr(TimeCurrent());
//--- создадим объект "Текст"
ObjectCreate(0,name,OBJ_TEXT,0,time,price);
//--- установим текст
ObjectSetString(0,name,OBJPROP_TEXT,text);
//--- установим шрифт текста
ObjectSetString(0,name,OBJPROP_FONT,"Arial");
//--- установим размер шрифта
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,10);
//--- установим способ привязки
ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER);
//--- установим цвет
ObjectSetInteger(0,name,OBJPROP_COLOR,Yellow);
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
double p1=0,p2=0;
datetime t1=0,t2=0;
for(int i=ObjectsTotal();i>=0;i--)
{
if(ObjectType(ObjectName(i))==OBJ_TREND)
{
p1 = ObjectGet(ObjectName(i),OBJPROP_PRICE1);
p2 = ObjectGet(ObjectName(i),OBJPROP_PRICE2);
t1 = ObjectGet(ObjectName(i),OBJPROP_TIME1);
t2 = ObjectGet(ObjectName(i),OBJPROP_TIME2);
PutText((string)NormalizeDouble((p1-p2)/Point,1),p2,t2);
}
}
Comment("\n P1: ",p1,
"\n P2: ",p2);
}
//+------------------------------------------------------------------+
AM2