void OnTick()
{
CloseOne();
//--------------
}
// +------------------------------------------------------------------+
// | |
// +------------------------------------------------------------------+
void CloseOne()
{
bool cl;
double pr=0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol()&& OrderMagicNumber() == MagicNumber)
{
if(OrderType()<2)
{
pr=OrderProfit()+OrderCommission()+OrderSwap();
double pro=(pr/AccountBalance())*100;
if(pro>=Procent && Procent>0)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,_Digits),Slippage,Gold);
}
}
}
}
}
}
//---------------закрывает селл--------------
double pro=(AllProfit(1)/AccountBalance())*100;
if(pro>=Procent && Procent>0)// 2000/10000*100=20
CloseAll(1);//закрывает селл
//------------------------закрывает бай--------------------
double pro=(AllProfit(0)/AccountBalance())*100;
if(pro>=Procent && Procent>0)// 2000/10000*100=20
CloseAll(0);//закрывает бай
//+------------------------------------------------------------------+
//| TrailClosePart.mq4 |
//| Copyright 2021, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern int TrailingStop = 500; // трал
extern int TrailingStep = 50; // трал степ
extern double KClose = 0.5; // K.Close
double MINLOT,MAXLOT;
int countb=1;
int counts=1;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
MINLOT = MarketInfo(Symbol(),MODE_MINLOT);
MAXLOT = MarketInfo(Symbol(),MODE_MAXLOT);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//-------------------
}
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу |
//+------------------------------------------------------------------+
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())
{
if(OrderType()==type || type==-1)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| функция трала и частичного закрытия ордеров |
//+------------------------------------------------------------------+
void Trailing()
{
bool mod,cl;
double sl=0,lot=0,CloseLot=0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==0)
{
if(Bid-OrderOpenPrice()>(TrailingStop*countb)*_Point)
{
lot=OrderLots();
CloseLot=NormalizeDouble(lot*KClose,2);
countb++;
if(CloseLot<MINLOT)
{
CloseLot=MINLOT;
countb=1;
}
cl=OrderClose(OrderTicket(),CloseLot,NormalizeDouble(Bid,Digits),Slip,White);
}
if(Bid-OrderOpenPrice()>TrailingStop*_Point && OrderStopLoss()<Bid-(TrailingStop+TrailingStep)*_Point)
{
sl=NormalizeDouble(Bid-TrailingStop*_Point,_Digits);
if(OrderStopLoss()!=sl)
mod=OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,Yellow);
}
}
if(OrderType()==1)
{
if(OrderOpenPrice()-Ask>(TrailingStop*counts)*_Point)
{
lot=OrderLots();
CloseLot=NormalizeDouble(lot*KClose,2);
counts++;
if(CloseLot<MINLOT)
{
CloseLot=MINLOT;
counts=1;
}
cl=OrderClose(OrderTicket(),CloseLot,NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderOpenPrice()-Ask>TrailingStop*_Point && OrderStopLoss()>(Ask+(TrailingStop+TrailingStep)*_Point))
{
sl=NormalizeDouble(Ask+TrailingStop*_Point,_Digits);
if(OrderStopLoss()!=sl)
mod=OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,Yellow);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(CountOrders()>0)
Trailing();
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| ProBoy.mq4 |
//| Copyright 2021, AM2 |
//| https://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, AM2"
#property link "https://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double KLot = 2; // умножение лота
extern double MaxLot = 5; // лот для вирта
extern int StopLoss = 0; // лось
extern int TakeProfit = 0; // язь
extern int Candles = 20; // свечей в коробке
extern int CandleTrail = 10; // свечей для трала
extern int Delta = 100; // расстояние от цены
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
extern bool BuyStop = true; // BuyStop
extern bool SellStop = true; // SellStop
datetime t=0;
double hi=0,lo=0;
//+------------------------------------------------------------------+
//| 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;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ModeOOP()
{
bool m=1;
double sl=0,tp=0;
lo=Low[iLowest(NULL,0,1,Candles,0)];
hi=High[iHighest(NULL,0,2,Candles,0)];
double opb=NormalizeDouble(hi+Delta*_Point,_Digits);
double slb=NormalizeDouble(Low[iLowest(NULL,0,1,CandleTrail,1)],Digits);
double ops=NormalizeDouble(lo-Delta*_Point,_Digits);
double sls=NormalizeDouble(High[iHighest(NULL,0,2,CandleTrail,1)],_Digits);
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==OP_SELLLIMIT)//4
{
if(OrderOpenPrice()!=opb)
{
if(TakeProfit>0)
{
tp=NormalizeDouble(OrderOpenPrice()-TakeProfit*_Point,_Digits);
}
if(StopLoss>0)
{
sl=NormalizeDouble(OrderOpenPrice()+StopLoss*_Point,_Digits);
}
m=OrderModify(OrderTicket(),opb,sl,tp,0,Blue);
return;
}
}
if(OrderType()==OP_BUYLIMIT)//5
{
if(OrderOpenPrice()!=ops)
{
if(TakeProfit>0)
{
tp=NormalizeDouble(OrderOpenPrice()+TakeProfit*_Point,_Digits);
}
if(StopLoss>0)
{
sl=NormalizeDouble(OrderOpenPrice()-StopLoss*_Point,_Digits);
}
m=OrderModify(OrderTicket(),ops,sl,tp,0,Blue);
return;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CandleTrailing()
{
bool mod=1;
double tp=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)
{
tp=NormalizeDouble(High[iHighest(NULL,0,2,CandleTrail,1)],Digits);
if(Bid<tp)
{
if(OrderTakeProfit()<tp || OrderTakeProfit()==0)
{
if(OrderTakeProfit()!=tp)
mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),tp,0,Yellow);
return;
}
}
}
if(OrderType()==1)
{
tp=NormalizeDouble(Low[iLowest(NULL,0,1,CandleTrail,1)],Digits);
if(Ask>tp)
{
if(OrderTakeProfit()>tp || OrderTakeProfit()==0)
{
if(OrderTakeProfit()!=tp)
mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),tp,0,Yellow);
return;
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(t!=Time[0])
{
lo=Low[iLowest(NULL,0,1,Candles,0)];
hi=High[iHighest(NULL,0,2,Candles,0)];
ModeOOP();
if(CandleTrail>0)
CandleTrailing();
if(CountTrades()<1)
{
if(BuyStop && CountOrders(3)<1)
{
PutOrder(3,hi+Delta*_Point);
}
if(SellStop && CountOrders(2)<1)
{
PutOrder(2,lo-Delta*_Point);
}
}
t=Time[0];
}
Comment("\n Lot: ",Lot());
}
//+------------------------------------------------------------------+
verta81