Get Lucky
Prendre son pied
Like the legend of the Phoenix
All ends with beginnings
What keeps the planet spinning, ah
The force from the beginning
Comme la légende du Phénix
Tout fini avec ses débuts
Qu'est-ce qui fait tourner la planète, ah
C'est la force du commencement
We've come too far to give up who we are
So let's raise the bar and our cups to the stars
Nous sommes allés trop loin pour abandonner qui nous sommes
Alors élevons le niveau et levons nos verres jusqu'aux étoiles
…..
Prendre son pied
Like the legend of the Phoenix
All ends with beginnings
What keeps the planet spinning, ah
The force from the beginning
Comme la légende du Phénix
Tout fini avec ses débuts
Qu'est-ce qui fait tourner la planète, ah
C'est la force du commencement
We've come too far to give up who we are
So let's raise the bar and our cups to the stars
Nous sommes allés trop loin pour abandonner qui nous sommes
Alors élevons le niveau et levons nos verres jusqu'aux étoiles
…..
Code
//+------------------------------------------------------------------+
//| LUCKY LUKE.mq4 |
//| QPG |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "QPG"
#property link "https://www.mql5.com"
#property version "1.00"
//#property strict
//+------------------------------------------------------------------+
//| EURGBP ...30 MN |
//+------------------------------------------------------------------+
extern string mm="MONEY MANAGEMENT";
double GetLots; //lotsize
extern double LotFactor = 2.8; //lotsize factor
extern bool trail = true;
extern double TrailingStop = 72;
extern int StopLoss=1900; //stop loss
extern int TakeProfit=64; //take profit
extern double pips = 0.00001; //leave as default for 5 digit brokers
extern int Slippage=3;
extern string mn="MAGIC NUMBER";
extern int MagicNumber=20180807; //magic
extern string bo="BOOSTER";
extern int adxthreshold = 33; //adx threshold - must be greater than this to trade
extern int adxperiod = 25; //adx period
extern int rsiperiod = 2; //rsi period
extern int rsiupper = 100; //rsi upper bound, wont buy above this value
extern int rsilower = 0; //rsi lower bound, wont sell below this value
double a, b;
bool first=true;
extern int Shift = 12;
extern int Limit = 5;
extern int Pr_limit = 4;
double TP=0,SL=0,TR;
//+------------------------------------------------------------------+
//| Hidden StopLoss Calculations |
//+------------------------------------------------------------------+
void StpLoss()
{
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
TP=TakeProfit*MyPoint;
SL=StopLoss*MyPoint;
double OrdP=0,OrdTP=0,OrdSL=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderMagicNumber()==MagicNumber && Symbol()==OrderSymbol())
{
OrdP=OrderProfit()-MathAbs(OrderSwap())-MathAbs(OrderCommission());
OrdSL=(-1)*SL*OrderLots()*MarketInfo(OrderSymbol(),MODE_TICKVALUE)/Point;
OrdTP=TP*OrderLots()*MarketInfo(OrderSymbol(),MODE_TICKVALUE)/Point;
if(OrdP>OrdTP || OrdP<OrdSL)
{
if(OrderType()==OP_BUY)
bool OrdClP=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,clrGreen);
if(OrderType()==OP_SELL)
bool OrdClL=OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,clrYellow);
}
}
}
}
//+------------------------------------------------------------------+
//| Trailing Stop |
//+------------------------------------------------------------------+
void trail()
{
for (int i = 0; i < OrdersTotal(); i++) {
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
if ( OrderSymbol()==Symbol() )
{
if (OrderType() == OP_BUY) {
if (Bid - OrderOpenPrice() > TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)) {
if (OrderStopLoss() < Bid - TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)) {
bool modify1=OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT), OrderTakeProfit(), Red);
}
}
} else if (OrderType() == OP_SELL) {
if (OrderOpenPrice() - Ask > TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)) {
if ((OrderStopLoss() > Ask + TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)) ||
(OrderStopLoss() == 0)) {
bool modify2=OrderModify(OrderTicket(), OrderOpenPrice(),
Ask + TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT), OrderTakeProfit(), Red);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert Initialization Function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Expert Deinitialization Function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Expert Start Function |
//+------------------------------------------------------------------+
int start()
{
if (trail) trail();
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
//----
if(IsNewCandle())
{
trenddirection(); //find trend direction
logic(); //apply indicator logic
Lot_Volume(); //calc lotsize
buyorsell(); //trade - buy or sell
return(0);
}
return(0);
}
//+------------------------------------------------------------------+
//Insuring its a New Candle Function
//+------------------------------------------------------------------+
bool IsNewCandle()
{
static int BarsOnChart=0;
if (Bars == BarsOnChart)
return (false);
BarsOnChart = Bars;
return(true);
}
//+------------------------------------------------------------------+
//Identifies the Direction of the Current Trend
//+------------------------------------------------------------------+
bool trenddirection()
{
if (first)
{
a=Ask;
b=Bid;
first=false;
return(0);
} //----
if ( OrdersTotal() == 0 ) // Mathemat; no more than one opened order
{
if (b-Bid>=Shift*Point)
{
return(true);
}
if (Ask-a>=Shift*Point)
a=Ask;
b=Bid;
CloseAll();
{
return(false);
}
return(0);
}
return(0);
}
//-----------------------------------------------------------------------------
void CloseAll()
{
for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol() == Symbol())
{
// if ((OrderProfit()>0))
if( OrderProfit() > Pr_limit * OrderLots() * 10 ) // Mathemat (for EURUSD)
{
if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
}
else
{
if((OrderType()==OP_BUY) && (((OrderOpenPrice()-Ask)/Point) > Limit))
OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
if((OrderType()==OP_SELL) && (((Bid-OrderOpenPrice())/Point) > Limit))
OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
}
}
}
}
//+------------------------------------------------------------------+
//Applies Logic from Indicators ADX and RSI to determine if we can trade
//+------------------------------------------------------------------+
int logic()
{
double adx,rsi;
adx = iADX(Symbol(),0,adxperiod,PRICE_CLOSE,MODE_MAIN,0);
rsi = iRSI(Symbol(),0,rsiperiod,PRICE_CLOSE,0);
if(adx > adxthreshold)
{
if(rsi > rsilower && rsi < rsiupper)
{
return(1);
}
}
return(0);
}
//+------------------------------------------------------------------+
//Opens Trades
//+------------------------------------------------------------------+
int buyorsell()
{
bool trenddirectionx, logicx;
int TicketNumber;
trenddirectionx = trenddirection();
logicx = logic();
if(OrdersTotal() == 0)
{
if(trenddirectionx == true && logicx == 1 )
{
//buy
TicketNumber = OrderSend(Symbol(),OP_BUY,GetLots,Ask,3,Ask-(StopLoss*pips),Ask+(TakeProfit*pips),NULL,MagicNumber,0,Green);
if( TicketNumber > 0 )
{
Print("Order placed # ", TicketNumber);
}
else
{
Print("Order Send failed, error # ", GetLastError() );
}
}
}
if(OrdersTotal() == 0)
{
if(trenddirectionx == false && logicx == 1 )
//sell
{
TicketNumber = OrderSend(Symbol(),OP_SELL,GetLots,Bid,3,Bid+(StopLoss*pips),Bid-(TakeProfit*pips),NULL,MagicNumber,0,Red);
if( TicketNumber > 0 )
{
Print("Order placed # ", TicketNumber);
}
else
{
Print("Order Send failed, error # ", GetLastError() );
}
}
}
return(0);
}
//+------------------------------------------------------------------+
//Calculates Lot Size based on balance and factor
//+------------------------------------------------------------------+
double Lot_Volume()
{
double lot;
if (AccountBalance()>=50) lot=0.02;
if (AccountBalance()>=75) lot=0.03;
if (AccountBalance()>=100) lot=0.04;
if (AccountBalance()>=125) lot=0.05;
if (AccountBalance()>=150) lot=0.06;
if (AccountBalance()>=175) lot=0.07;
if (AccountBalance()>=200) lot=0.08;
if (AccountBalance()>=225) lot=0.09;
if (AccountBalance()>=250) lot=0.1;
if (AccountBalance()>=275) lot=0.11;
if (AccountBalance()>=300) lot=0.12;
if (AccountBalance()>=325) lot=0.13;
if (AccountBalance()>=350) lot=0.14;
if (AccountBalance()>=375) lot=0.15;
if (AccountBalance()>=400) lot=0.16;
if (AccountBalance()>=425) lot=0.17;
if (AccountBalance()>=450) lot=0.18;
if (AccountBalance()>=475) lot=0.19;
if (AccountBalance()>=500) lot=0.2;
if (AccountBalance()>=525) lot=0.21;
if (AccountBalance()>=550) lot=0.22;
if (AccountBalance()>=575) lot=0.23;
if (AccountBalance()>=600) lot=0.24;
if (AccountBalance()>=625) lot=0.25;
if (AccountBalance()>=650) lot=0.26;
if (AccountBalance()>=675) lot=0.27;
if (AccountBalance()>=700) lot=0.28;
if (AccountBalance()>=725) lot=0.29;
if (AccountBalance()>=750) lot=0.30;
if (AccountBalance()>=800) lot=0.32;
if (AccountBalance()>=825) lot=0.33;
if (AccountBalance()>=850) lot=0.34;
if (AccountBalance()>=875) lot=0.35;
if (AccountBalance()>=900) lot=0.36;
if (AccountBalance()>=925) lot=0.37;
if (AccountBalance()>=950) lot=0.38;
if (AccountBalance()>=975) lot=0.39;
if (AccountBalance()>=1000) lot=0.4;
if (AccountBalance()>=1025) lot=0.41;
if (AccountBalance()>=1050) lot=0.42;
if (AccountBalance()>=1075) lot=0.43;
if (AccountBalance()>=1100) lot=0.44;
if (AccountBalance()>=1125) lot=0.45;
if (AccountBalance()>=1150) lot=0.46;
if (AccountBalance()>=1175) lot=0.47;
if (AccountBalance()>=1200) lot=0.48;
if (AccountBalance()>=1225) lot=0.49;
if (AccountBalance()>=1250) lot=0.5;
if (AccountBalance()>=1275) lot=0.51;
if (AccountBalance()>=1300) lot=0.52;
if (AccountBalance()>=1325) lot=0.53;
if (AccountBalance()>=1350) lot=0.54;
if (AccountBalance()>=1350) lot=0.55;
if (AccountBalance()>=1400) lot=0.56;
if (AccountBalance()>=1450) lot=0.58;
if (AccountBalance()>=1500) lot=0.6;
if (AccountBalance()>=1550) lot=0.62;
if (AccountBalance()>=1600) lot=0.64;
if (AccountBalance()>=1650) lot=0.66;
if (AccountBalance()>=1700) lot=0.68;
if (AccountBalance()>=1750) lot=0.7;
if (AccountBalance()>=1800) lot=0.72;
if (AccountBalance()>=1850) lot=0.74;
if (AccountBalance()>=1900) lot=0.76;
if (AccountBalance()>=1950) lot=0.78;
if (AccountBalance()>=2000) lot=0.8;
if (AccountBalance()>=2025) lot=0.81;
if (AccountBalance()>=2050) lot=0.82;
if (AccountBalance()>=2075) lot=0.83;
if (AccountBalance()>=2100) lot=0.84;
if (AccountBalance()>=2150) lot=0.86;
if (AccountBalance()>=2175) lot=0.87;
if (AccountBalance()>=2200) lot=0.88;
if (AccountBalance()>=2225) lot=0.89;
if (AccountBalance()>=2250) lot=0.9;
if (AccountBalance()>=2275) lot=0.91;
if (AccountBalance()>=2300) lot=0.92;
if (AccountBalance()>=2350) lot=0.94;
if (AccountBalance()>=2400) lot=0.96;
if (AccountBalance()>=2450) lot=0.98;
if (AccountBalance()>=2500) lot=1.0;
if (AccountBalance()>=2550) lot=1.02;
if (AccountBalance()>=2600) lot=1.04;
if (AccountBalance()>=2700) lot=1.08;
if (AccountBalance()>=2800) lot=1.12;
if (AccountBalance()>=2900) lot=0.16;
if (AccountBalance()>=3000) lot=1.2;
if (AccountBalance()>=3100) lot=1.24;
if (AccountBalance()>=3200) lot=1.28;
if (AccountBalance()>=3300) lot=1.32;
if (AccountBalance()>=3400) lot=1.36;
if (AccountBalance()>=3500) lot=1.4;
if (AccountBalance()>=4000) lot=1.6;
if (AccountBalance()>=4500) lot=1.8;
if (AccountBalance()>=5000) lot=2.0;
if (AccountBalance()>=5500) lot=2.2;
if (AccountBalance()>=6000) lot=2.4;
if (AccountBalance()>=6500) lot=2.6;
if (AccountBalance()>=7000) lot=2.8;
if (AccountBalance()>=7500) lot=3;
if (AccountBalance()>=8000) lot=3.2;
if (AccountBalance()>=8500) lot=3.4;
if (AccountBalance()>=9000) lot=3.6;
if (AccountBalance()>=9500) lot=3.8;
if (AccountBalance()>=10000) lot=4.0;
if (AccountBalance()>=10100) lot=4.04;
if (AccountBalance()>=10200) lot=4.08;
if (AccountBalance()>=10300) lot=4.12;
if (AccountBalance()>=10400) lot=4.16;
if (AccountBalance()>=10500) lot=4.2;
if (AccountBalance()>=10600) lot=4.26;
if (AccountBalance()>=10700) lot=4.3;
if (AccountBalance()>=10800) lot=4.34;
if (AccountBalance()>=10900) lot=4.38;
if (AccountBalance()>=11000) lot=4.4;
if (AccountBalance()>=12000) lot=4.8;
if (AccountBalance()>=13000) lot=5.2;
if (AccountBalance()>=14000) lot=5.6;
if (AccountBalance()>=15000) lot=6.0;
if (AccountBalance()>=20000) lot=8.0;
if (AccountBalance()>=30000) lot=12;
if (AccountBalance()>=40000) lot=16;
if (AccountBalance()>=50000) lot=20;
if (AccountBalance()>=60000) lot=24;
if (AccountBalance()>=70000) lot=28;
if (AccountBalance()>=80000) lot=32;
if (AccountBalance()>=90000) lot=36;
if (AccountBalance()>=100000) lot=40;
if (AccountBalance()>=200000) lot=80;
GetLots=lot/LotFactor;
return(GetLots);
}
Modifié le 2018-08-24 20:38:17 par
lefeuvr3