Price Data Components
Orders Execution
Indicators Used
0
Views
0
Downloads
0
Favorites
eLisa_1_4
//+------------------------------------------------------------------+
//| eLisa 1-0.mq4 |
//| kwadrad |
//| kwadrad@yandex.ru |
//+------------------------------------------------------------------+
#property copyright "kwadrad"
#property link "kwadrad@yandex.ru"
extern string ñ1= "Ïàðàìåòðû";
extern int perMAFiltr=55;
extern int perMACD1Filtr=12;
extern int perMACD2Filtr=26;
extern int perMACD3Filtr=9;
extern int perMAforOpen=3;
extern int FiltrFrame=6;
extern int Fibo1=10;
extern string ñ2= "Ðèñêè, ëîòû, òðåéëèíã-ñòîï, áåçóáûòîê";
extern double Lot=0;
extern double Risk=0.05;
extern int Breakeven=21;
extern int TrailingStop=34;
extern double DecreaseFactor= 13.0;
extern int MinTP=13;
extern int MinSL=13;
extern double PercentLocker= 2.0;
extern string ñ3= "Âðåìÿ âûñòàâëåíèÿ îðäåðîâ";
extern int begin=7;
extern int end=22;
extern string ñ5= "Äîïîëíèòåëüíî";
extern int Filtr=2;
extern bool CloseOrder=true;
extern int OtstupSpreeds=2;
extern int TimeOfLifeTiket=3600;
int per[10]={0,1,5,15,30,60,240,1440,10080,43200};
double fibolevel[30]={0.236,0.382,0.5,0.618,0.764,1.0,1.236,1.382,1.5,1.618,1.764,2,2.236,2.382,2.5,2.618,2.764,3,3.236,3.382,3.5,3.618,3.764,4,4.236,4.382,4.618,4.764,5,5.618};
int TrailingStep=2;
int Mn=123;
int slippage=10;
double MinDepo=30.0;
//+------------------------------------------------------------------+
int start()
{
int CT=CountTrades(Mn);
if (AccountFreeMargin()>=MinDepo && CT==0){
double DMA=NormalizeDouble(MA(0,perMAforOpen,0),Digits);
int ticket,ticket1,ticket2;
if(FiltrOneUp() && CandleSignalBuy() && time()&& timeBar())
{ticket=OrderSend(Symbol(),OP_BUYLIMIT,LotsOptimized(),DMA,slippage,SLup(),TPup(),"Lisa",Mn,TimeCurrent()+TimeOfLifeTiket,DodgerBlue);
ticket1=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,slippage,SLup(),TPup(),"Lisa",Mn,0,Blue);}
if(FiltrOneDn() && CandleSignalSell() && time()&& timeBar())
{ticket=OrderSend(Symbol(),OP_SELLLIMIT,LotsOptimized(),DMA,slippage,SLdn(),TPdn(),"Lisa",Mn,TimeCurrent()+TimeOfLifeTiket,Red);
ticket1=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,slippage,SLdn(),TPdn(),"Lisa",Mn,0,Magenta);}
}
//----
Bezubytok();
TrailingStop();
if(HistoryProfit()) {Sleep(3000);}
if(CloseOrder) {CheckForClose();}
// Ëîêèðóåì
if (OpenProfit()<0 && OpenLots()>0 && CandleSignalSell())
{ticket2=OrderSend(Symbol(),OP_SELL,NormalizeDouble(OpenLots()*2,1),Bid,slippage,SLdn(),TPdn(),"LisaLockDN",Mn+1,0,DeepPink);}
if (OpenProfit()<0 && OpenLots()<0 && CandleSignalBuy())
{ticket2=OrderSend(Symbol(),OP_BUY,NormalizeDouble(OpenLots()*2,1),Ask,slippage,SLup(),TPup(),"LisaLockUP",Mn+1,0,DarkViolet);}
if(CountTrades(Mn+1)>0 && OpenProfit()>AccountFreeMargin()*PercentLocker/100) {CloseOrders(Mn);CloseOrders(Mn+1);}
//----
Comment (OpenLots(), " " , OpenProfit());
return(0);
}
//------------------------------------------------------------------------+
bool CandleSignalBuy()
{
if (iClose(NULL,0,1)>iOpen(NULL,0,2)&& iClose(NULL,0,2)<iOpen(NULL,0,3))
return(true);else return(false);
}
//------------------------------------------------------------------------+
bool CandleSignalSell()
{
if (iClose(NULL,0,1)<iOpen(NULL,0,2)&& iClose(NULL,0,2)>iOpen(NULL,0,3))
return(true);else return(false);
}
//------------------------------------------------------------------------+
bool FiltrOneUp()
{
if(Filtr==0){return(true);}
if(Filtr==1){double ma = MA(per[FiltrFrame],perMAFiltr,1);double ma2 = MA(per[FiltrFrame],perMAFiltr,2);
if (Close[1]>ma && ma>ma2)
return(true);}
if(Filtr==2){
double macd1 = MACD(per[FiltrFrame],perMACD1Filtr,perMACD2Filtr,perMACD3Filtr,0);
double macd2 = MACD(per[FiltrFrame],perMACD1Filtr,perMACD2Filtr,perMACD3Filtr,1);
double AO1 = AO(per[FiltrFrame],0);double AO2 = AO(per[FiltrFrame],1);
if (macd1>macd2 && AO1>AO2 && macd1>0)
return(true);}
else return(false);
}
//------------------------------------------------------------------------+
bool FiltrOneDn()
{
if(Filtr==0){return(true);}
if(Filtr==1){double ma = MA(per[FiltrFrame],perMAFiltr,1);double ma2 = MA(per[FiltrFrame],perMAFiltr,2);
if (Close[1]<ma && ma<ma2)
return(true);}
if(Filtr==2){
double macd1 = MACD(per[FiltrFrame],perMACD1Filtr,perMACD2Filtr,perMACD3Filtr,0);
double macd2 = MACD(per[FiltrFrame],perMACD1Filtr,perMACD2Filtr,perMACD3Filtr,1);
double AO1 = AO(per[FiltrFrame],0);double AO2 = AO(per[FiltrFrame],1);
if (macd1<macd2 && AO1<AO2 && macd1<0)
return(true);}
else return(false);
}
//---------------------------------------------------------------
double MA(int x1,int x2,int x3)
{
double ma=iMA(NULL,x1,x2,0,MODE_SMA,PRICE_CLOSE,x3);
return(ma);
}
//---------------------------------------------------------------
double MACD(int x1,int x2,int x3,int x4,int x5)
{
double ao=iMACD(NULL,x1,x2,x3,x4,PRICE_CLOSE,MODE_MAIN,x5);
return(ao);
}
//---------------------------------------------------------------
double AO(int x1,int x2)
{
double ao=iAO(NULL, x1, x2);
return(ao);
}
//------------------------------------------------------------------------+
double TPup()
{
double tp=FrDn(per[FiltrFrame],1)+(Bid-FrDn(per[FiltrFrame],1))* fibolevel[Fibo1]-OtstupSpreeds*MarketInfo(Symbol(),MODE_SPREAD)*fPointX();
if(tp-Bid<MinTP*fPointX()) tp=Bid+MinTP*fPointX();
return (tp);
}
//------------------------------------------------------------------------+
double TPdn()
{
double tp=FrUp(per[FiltrFrame],1)-(Ask-FrDn(per[FiltrFrame],1))*fibolevel[Fibo1]+OtstupSpreeds*MarketInfo(Symbol(),MODE_SPREAD)*fPointX();
if(Ask-tp<MinTP*fPointX()) tp=Ask-MinTP*fPointX();
return (tp);
}
//------------------------------------------------------------------------+
double SLup()
{
double sl=FrDn(per[FiltrFrame],1)-OtstupSpreeds*MarketInfo(Symbol(),MODE_SPREAD)*fPointX();
if(Bid-sl<MinSL*fPointX()) sl=Ask-MinSL*fPointX();
return (sl);
}
//------------------------------------------------------------------------+
double SLdn()
{
double sl=FrUp(per[FiltrFrame],1)+OtstupSpreeds*MarketInfo(Symbol(),MODE_SPREAD)*fPointX();
if(sl-Ask<MinSL*fPointX()) sl=Ask+MinTP*fPointX();
return (sl);
}
//+------------------------------------------------------------------+
double FrUp(int z,int a)
{ int b=0;
for (int i=1;i<Bars;i++)
{
double f=NormalizeDouble(iFractals(NULL, z, MODE_UPPER, i),Digits);
if (f!=0) b++;
if (a==b)return (f);
}
}
//+------------------------------------------------------------------+
double FrDn(int z,int a)
{ int b=0;
for (int i=1;i<Bars;i++)
{
double f=NormalizeDouble(iFractals(NULL, z, MODE_LOWER, i),Digits);
if (f!=0) b++;
if (a==b)return (f);
}
}
//------------------------------------------------------------------------+
bool HistoryProfit()
{
int orders=OrdersHistoryTotal(); // history orders total
for(int i=orders-1;i>=orders-2;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()!=Symbol() ) continue;
//----
if(OrderProfit()>0) break;
if(OrderProfit()<0)
return(true);else return(false);}
}
//-----------------------------------------------------
double LotsOptimized()
{
double lot_;
int orders=OrdersHistoryTotal(); // history orders total
int losses=0; // number of losses orders without a break
//---- select lot size
if(Lot ==0)
{
lot_=NormalizeDouble(AccountFreeMargin()*Risk/1000.0,2);
//---- calcuulate number of losses orders without a break
if(DecreaseFactor>0)
{
for(int i=orders-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; }
if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;
//----
if(OrderProfit()>0) break;
if(OrderProfit()<0) losses++;
}
if(losses>1) lot_=NormalizeDouble(lot_-lot_*losses/DecreaseFactor,2);
}}
//---- return lot size
else lot_=Lot;
if(lot_<MarketInfo(Symbol(), MODE_MINLOT) ) lot_=MarketInfo(Symbol(), MODE_MINLOT);
if(lot_> MarketInfo( Symbol(), MODE_MAXLOT) ) {lot_= MarketInfo(Symbol(), MODE_MAXLOT);}
return(lot_);
}
//+------------------------------------------------------------------+
void Bezubytok()
{
int cnt,total;
total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Mn)
{
if(OrderType()==OP_BUY)
{
if((Bid-OrderOpenPrice())> Breakeven*fPointX()&& Breakeven>0)
{
if(OrderStopLoss() < OrderOpenPrice())
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green);
return(0);
}
}
}
else
{
if((OrderOpenPrice()-Ask)/fPointX() > Breakeven && Breakeven>0)
{
if( OrderStopLoss() > OrderOpenPrice()) {
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Red);
return(0);
}}
}
}
}
return(0);
}
//+------------------------------------------------------------------+
void TrailingStop()
{
int cnt,total;
total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==Mn)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>fPointX()*TrailingStop)
{
if(OrderStopLoss()<Bid-(TrailingStop+TrailingStep-1)*fPointX())
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask-TrailingStop*fPointX(),OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else
{
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(fPointX()*TrailingStop))
{
if(OrderStopLoss()>Ask+(TrailingStop+TrailingStep-1)*fPointX() || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid+TrailingStop*fPointX(),OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}
//-------------------------------------------------------------------------------------------++
void CheckForClose()
{
int cnt,total,y;
total=OrdersTotal();
if(CandleSignalSell()){y=-1;}else if(CandleSignalBuy()){y=1;}
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if((OrderType()<=OP_SELL ||OrderType()<=OP_SELLLIMIT) && OrderSymbol()==Symbol() && OrderMagicNumber()==Mn)
{
if(OrderType()==OP_BUY || OrderType()==OP_BUYLIMIT)
{
if(y==-1 && OrderProfit()>0)
{
OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Violet);// close position
return(0); Sleep(1000);
}
}
else
{
if(y==1 && OrderProfit()>0)
{
OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Violet); // close position
return(0); Sleep(1000);
}
}
}
}
return(0);
}
//--------------------------------------------------------------------------|
double fPointX()
{
double PointX = 0;
if(Digits==5 || Digits==3)
{
PointX = Point * 10;
}
if(Digits==4 || Digits==2)
{
PointX = Point;
}
return(PointX);
}
//-------------------------------------------------------------+
bool time()
{
if(Hour()>=begin && Hour()<=end)
return(true);else return(false);
}
//-------------------------------------------------------------+
bool timeBar()
{
if(iVolume(NULL,0,0)<21)
return(true);else return(false);
}
//-------------------------------------------------------------------------------------------++
double OpenLots()
{
int cnt,total; double pp=0;
total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Mn)
{
if(OrderType()==OP_BUY || OrderType()==OP_BUYLIMIT) {pp=pp+OrderLots();}
else
if(OrderType()==OP_SELL || OrderType()==OP_SELLLIMIT) {pp=pp-OrderLots();}
}
}
return(pp);
}
//-------------------------------------------------------------------------------------------++
double OpenProfit()
{
int cnt,total; double Pr=0;
total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && (OrderMagicNumber()==Mn ||OrderMagicNumber()==Mn+1) )
{
Pr=Pr+OrderProfit();
}
}
return(Pr);
}
//-------------------------------------------------------------------+
int CloseOrders(int mmmm) // ïðîöåäóðà çàêðûòèÿ âñåõ îðäåðîâ
{
int total = OrdersTotal();
for (int cnt = total-1 ; cnt >= 0 ; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == mmmm && OrderSymbol()==Symbol())
{
//Print(cnt);
if (OrderType()==OP_BUY)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Green);
}
if (OrderType()==OP_SELL)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
}
if (OrderType()==OP_BUYSTOP)
{
OrderDelete(OrderTicket());
}
if (OrderType()==OP_SELLSTOP)
{
OrderDelete(OrderTicket());
}
}
}
return(0);
}
//+------------------------------------------------------------------+
int CountTrades(int m)
{
int count = 0;
for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol()|| OrderMagicNumber() != m) continue;
if (OrderSymbol() == Symbol()&& OrderMagicNumber() == m)
if (OrderType() == OP_SELL || OrderType() == OP_BUY) count++;
}
return (count);
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---