//+------------------------------------------------------------------+
//| Lots.mq4 |
//| Copyright 2015, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern double Lots = 0.1; // лот
extern double DeltaLots = 0.3; // разница в лотах
extern int StopLoss = 0; // лось
extern int TakeProfit = 0; // язь
extern int BULevel = 0; // уровень БУ
extern int BUPoint = 30; // пункты БУ
extern int TrailingStop = 0; // трал
extern int Procent = 100; // процент
extern int Delta = 300; // расстояние от цены
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
bool one=true;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price, double lot)
{
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 CountOrders(int type)
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==type) count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Подсчет лота ордеров по типу |
//+------------------------------------------------------------------+
double CountLots(int type)
{
double count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==type) count+=OrderLots();
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(IsTesting() && (CountOrders(0)<1 || CountOrders(1)<1))
{
if(CountOrders(4)<1) for(int i=1;i<=5;i++) PutOrder(4,Bid+200*Point*i,0.1);
if(CountOrders(5)<1) for(int k=1;k<=5;k++) PutOrder(5,Bid-200*Point*k,0.1);
}
double delta=MathAbs(CountLots(0)-CountLots(1));
if(delta>=DeltaLots && CountLots(0)>CountLots(1)) if(CountOrders(4)<6) PutOrder(5,Bid-Delta*Point,delta*Procent*0.01);
if(delta>=DeltaLots && CountLots(1)>CountLots(0)) if(CountOrders(4)<6) PutOrder(4,Bid+Delta*Point,delta*Procent*0.01);
Comment("\n Buy Lots: ",CountLots(0),
"\n Sell Lots: ",CountLots(1),
"\n Delta Lots: ",MathAbs(CountLots(0)-CountLots(1)));
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Tree.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; // лот рыночного
extern double Lots = 0.1; // лот отложенного
extern int Loss = 333; // лось рыночного
extern int Profit = 333; // язь рыночного
extern int StopLoss = 333; // лось отложенного
extern int TakeProfit = 333; // язь отложенного
extern int Slip = 30; // реквот
extern int Shift = 1; // на каком баре сигнал индикатора
extern int Delta = 300; // расстояние от цены
extern int Magic = 123; // магик
extern string IndName = "Trix";
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price,double lot,int stop,int take)
{
int r=0;
color clr=Green;
double sl=0,tp=0;
if(type==1 || type==3 || type==5)
{
clr=Red;
sl=NormalizeDouble(price+stop*Point,Digits);
tp=NormalizeDouble(price-take*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
sl=NormalizeDouble(price-stop*Point,Digits);
tp=NormalizeDouble(price+take*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 lime = iCustom(NULL,0,IndName,2,Shift);
double red = iCustom(NULL,0,IndName,3,Shift);
double lime1 = iCustom(NULL,0,IndName,2,Shift+1);
double red1 = iCustom(NULL,0,IndName,3,Shift+1);
if(lime<1000)
{
PutOrder(0,Ask,Lot,Loss,Profit);
if(CountOrders(2)<1) PutOrder(2,Ask-Delta*Point,Lots,StopLoss,TakeProfit);
}
if(red<1000)
{
PutOrder(1,Bid,Lot,Loss,Profit);
if(CountOrders(3)<1) PutOrder(3,Bid+Delta*Point,Lots,StopLoss,TakeProfit);
}
}
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| Результат последней сделки |
//+------------------------------------------------------------------+
int Last()
{
int result=0;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()>0)
{
result=1;//tp
}
if(OrderProfit()<0)
{
result=2;//sl
}
}
}
return(result);
}
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров |
//+------------------------------------------------------------------+
void DelOrder()
{
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()>1) del=OrderDelete(OrderTicket());
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseAll()
{
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()==OP_BUY)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==OP_SELL)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double lime= iCustom(NULL,0,IndName,2,Shift);
double red = iCustom(NULL,0,IndName,3,Shift);
if(CountTrades()<1)
{
DelOrder();
OpenPos();
}
if((Last()==1 || Last()==2) && CountTrades()>0)
{
DelOrder();
CloseAll();
}
Comment("\n lime: ",lime,
"\n red: ",red);
}
//+------------------------------------------------------------------+
4. Если оба ордера в рынке, то при достижении у одного из них С.Л. или Т.П. оставшийся ордер должен быть закрыт принудительно.
//+------------------------------------------------------------------+
//| Cardon.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
//--- Inputs
extern int StopLoss = 200; // лось
extern int StopLoss2 = 100; // лось 2
extern int TakeProfit = 500; // язь
extern int BULevel = 100; // уровень БУ
extern int BUPoint = 30; // пункты БУ
extern int Count = 3; //
extern int ProfitPoint = 100; //
extern double Lot = 1; //
bool one=true;
//+------------------------------------------------------------------+
//| 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(type==0 || type==2 || type==4)
{
clr=Blue;
}
r=OrderSend(NULL,type,1,NormalizeDouble(price,Digits),0,0,0,"",0,0,clr);
return;
}
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу |
//+------------------------------------------------------------------+
int CountOrders(int type)
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==type) count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseLot()
{
bool c;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==0)
{
if(Bid-OrderOpenPrice()>=ProfitPoint*Point)
if(OrderLots()==Lot)
c=OrderClose(OrderTicket(),OrderLots()/2,Bid,100,White);
}
if(OrderType()==1)
{
if(OrderOpenPrice()-Ask>=ProfitPoint*Point)
if(OrderLots()==Lot)
c=OrderClose(OrderTicket(),OrderLots()/2,Ask,100,White);
}
}
}
}
//+------------------------------------------------------------------+
//| Модификация стопов |
//+------------------------------------------------------------------+
void StopMode()
{
bool m;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==OP_BUY)
{
if(OrderStopLoss()==0 || OrderTakeProfit()==0)
{
if(OrderLots()==Lot)
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-StopLoss*Point,OrderOpenPrice()+TakeProfit*Point,0,Yellow);
return;
}
if(OrderLots()==Lot/2)
{
if(OrderStopLoss()>OrderOpenPrice())
if(OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()-StopLoss2*Point,Digits))
m=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-StopLoss2*Point,Digits),OrderTakeProfit(),0,Yellow);
return;
}
}
if(OrderType()==OP_SELL)
{
if(OrderStopLoss()==0 || OrderTakeProfit()==0)
{
if(OrderLots()==Lot)
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+StopLoss*Point,OrderOpenPrice()-TakeProfit*Point,0,Yellow);
return;
}
if(OrderLots()==Lot/2)
{
if(OrderStopLoss()>OrderOpenPrice())
if(OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()+StopLoss2*Point,Digits))
m=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+StopLoss2*Point,Digits),OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
//+------------------------------------------------------------------+
//| Безубыток ордеров if(BULevel>0) BU(); |
//+------------------------------------------------------------------+
void BU()
{
bool m;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==OP_BUY)
{
if(OrderOpenPrice()<=Bid-BULevel*Point && OrderOpenPrice()>OrderStopLoss())
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+BUPoint*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
if(OrderType()==OP_SELL)
{
if(OrderOpenPrice()>=Ask+BULevel*Point && (OrderOpenPrice()<OrderStopLoss() || OrderStopLoss()==0))
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-BUPoint*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров |
//+------------------------------------------------------------------+
void DelOrder()
{
bool del;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()>1) del=OrderDelete(OrderTicket());
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(IsTesting() && (CountOrders(0)<1 || CountOrders(1)<1) && one)
{
if(CountOrders(4)<1) for(int i=1;i<=5;i++) PutOrder(4,Bid+200*Point*i);
if(CountOrders(5)<1) for(int k=1;k<=5;k++) PutOrder(5,Bid-200*Point*k);
one=false;
}
StopMode();
CloseLot();
if(BULevel>0) BU();
if(CountOrders(0)+CountOrders(1)>=Count) DelOrder();
Comment("\n ");
}
//+------------------------------------------------------------------+
то-есть у нас есть все, кроме стопа и тейка полного ордера и стоп 1/2 ордера.
//+------------------------------------------------------------------+
//| Gap.mq4 |
//| Copyright 2015, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
input int Delta=100;
input int Times=8;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
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[])
{
//---
if(Hour()>=Times)
if(close[Times+1]-open[Times]>Delta*Point || open[Times]-close[Times+1]>Delta*Point)
{
PutTrendLine("Line1",open[Times],Red);
PutTrendLine("Line2",close[Times+1],Blue);
PutTrendLine("Line3",open[Times+1],Blue);
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutTrendLine(string name,double price,color clr)
{
ObjectDelete(0,name);
ObjectCreate(0,name,OBJ_TREND,0,Time[1],price,Time[Times],price);
//--- установим цвет линии
ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
//--- установим стиль отображения линии
ObjectSetInteger(0,name,OBJPROP_STYLE,0);
//--- установим толщину линии
ObjectSetInteger(0,name,OBJPROP_WIDTH,2);
//--- включим (true) или отключим (false) режим продолжения отображения линии вправо
ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,false);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Cardon.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
//--- Inputs
extern int BULevel = 100; // уровень БУ
extern int BUPoint = 30; // пункты БУ
extern int Count = 3; //
extern int ProfitPoint = 100; //
extern double Lot = 1; //
bool one=true;
//+------------------------------------------------------------------+
//| 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(type==0 || type==2 || type==4)
{
clr=Blue;
}
r=OrderSend(NULL,type,1,NormalizeDouble(price,Digits),0,0,0,"",0,0,clr);
return;
}
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу |
//+------------------------------------------------------------------+
int CountOrders(int type)
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==type) count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseLot()
{
bool c;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==0)
{
if(Bid-OrderOpenPrice()>=ProfitPoint*Point)
if(OrderLots()==Lot)
c=OrderClose(OrderTicket(),OrderLots()/2,Bid,100,White);
}
if(OrderType()==1)
{
if(OrderOpenPrice()-Ask>=ProfitPoint*Point)
if(OrderLots()==Lot)
c=OrderClose(OrderTicket(),OrderLots()/2,Ask,100,White);
}
}
}
}
//+------------------------------------------------------------------+
//| Безубыток ордеров if(BULevel>0) BU(); |
//+------------------------------------------------------------------+
void BU()
{
bool m;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==OP_BUY)
{
if(OrderOpenPrice()<=Bid-BULevel*Point && OrderOpenPrice()>OrderStopLoss())
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+BUPoint*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
if(OrderType()==OP_SELL)
{
if(OrderOpenPrice()>=Ask+BULevel*Point && (OrderOpenPrice()<OrderStopLoss() || OrderStopLoss()==0))
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-BUPoint*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров |
//+------------------------------------------------------------------+
void DelOrder()
{
bool del;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()>1) del=OrderDelete(OrderTicket());
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(IsTesting() && (CountOrders(0)<1 || CountOrders(1)<1) && one)
{
if(CountOrders(4)<1) for(int i=1;i<=5;i++) PutOrder(4,Bid+200*Point*i);
if(CountOrders(5)<1) for(int k=1;k<=5;k++) PutOrder(5,Bid-200*Point*k);
one=false;
}
CloseLot();
if(BULevel>0) BU();
if(CountOrders(0)+CountOrders(1)>=Count) DelOrder();
Comment("\n ");
}
//+------------------------------------------------------------------+
Да мне не в падлу было и так разместить, в чем прикол только не пойму…
Пообщаться-так я всегда за… можно было бы и пару соточек водочки пропустить…
Печалька…хороший бы индюк получился бы
AM2