if(ADXIsLow&&ForceIsLow)
{
Print("ADX & Force is low; Ready for explosive: LOOP HANDLING");
if(Price1>Price2&&Price2>Price3&&Price3>Price4&&MacdCurrent>SignalCurrent&&MacdCurrent>0*MacdSelfValue)//&&Price4>Price5)
{
Print("Order is in progress...");
ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,2,Ask-8*Point,Ask+8*Point,"TrendBuyer_BUY_EXPLODE",1002,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
Alert("BUY explosive order opened @ ",OrderOpenPrice(),", with ticket no. ",ticket,". Order sent successfully!");
ExplosiveIsBought = True;
}
} else { Alert("Error opening BUY EXPLOSIVE order : ",GetLastError()); }
}
if(Price1<Price2&&Price2<Price3&&Price3<Price4&&MacdCurrent<SignalCurrent&&MacdCurrent<0*MacdSelfValue)//&&Price4<Price5)
{
Print("Order is in progress...");
ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,2,Bid+8*Point,Bid-8*Point,"TrendBuyer_SELL_EXPLODE",1003,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
Alert("SELL explosive order opened @ ",OrderOpenPrice(),", with ticket no. ",ticket,". Order sent successfully!");
ExplosiveIsBought = True;
}
} else { Alert("Error opening SELL EXPLOSIVE order : ",GetLastError()); }
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi. I'm sort of new to this MQL4 thingy and I need your opinion on how to improve this code I have. Here it is:
int TicksWithLowADX = 0, TicksWithLowForce = 0, SlippageCounter=0;
bool ADXIsLow = False;
bool ExplosiveIsBought = False;
bool ForceIsLow;
double Price1,Price2,Price3,Price4,Price5;
int init()
{
Alert("TrendBuyer v2.1 is loaded. Please check the Forex list trade order errors if any error occurs.");
return(0);
}
int start()
{
double MacdCurrent, MacdPrev, ADXValue, SignalCurrent, SignalPrev, MacdSelfValue, MACurrent, MAPrev, Force, Bear;
int ticket;
MacdCurrent=iMACD("EURUSD",0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
MacdPrev=iMACD("EURUSD",0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
ADXValue=iADX("EURUSD",0,14,PRICE_CLOSE,MODE_MAIN,0);
SignalCurrent=iMACD("EURUSD",0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrev=iMACD("EURUSD",0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
MACurrent=iMA("EURUSD",0,10,0,MODE_SMA,PRICE_CLOSE,0);
MAPrev=iMA("EURUSD",0,10,0,MODE_SMA,PRICE_CLOSE,1);
Force=iForce("EURUSD",0,13,MODE_SMA,PRICE_CLOSE,0);
MacdSelfValue=0.00001;
Bear=iBearsPower("EURUSD",0,13,PRICE_CLOSE,0);//Bear=DOWNTREND
Price1 = iClose(Symbol(),0,0);
Price2 = iClose(Symbol(),0,1);
Price3 = iClose(Symbol(),0,2);
Price4 = iClose(Symbol(),0,3);
Price5 = iClose(Symbol(),0,4);
Print("Current MACD value: ",MacdCurrent);
Print("Current MACD signal: ",SignalCurrent);
Print("Current ADX value: ",ADXValue);
Print("Ticks with low ADX value: ",TicksWithLowADX);
Print("Price1: ",Price1," Price2: ",Price2," Price3: ",Price3," Price4: ",Price4," Price5: ",Price5);
if(OrdersTotal()<1)
{
//Print("Total orders < 1");
if(AccountFreeMargin()>100.0)
{
//Print("Account free margin > 100.0");
if(ADXValue>=35.0)
{
TicksWithLowADX=0;
Print("ADX>35; Trend strength is good!");
if(MacdCurrent<-1*MacdSelfValue)
{
Print("MACD<-0.00001: BUY STEP 1");
if(MacdCurrent>SignalCurrent)
{
Print("MACD>Signal: BUY STEP 2");
// if(MacdPrev<SignalPrev)
// {
// Print("MACD1<Signal1: BUY STEP 3");
if(MACurrent>MAPrev)
{
Print("MACurrent>MAPrev: BUY STEP 4");
if(Bear<0)
{
Print("Bears<0: BUY STEP 5");
Print("Order is in progress...");
ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,2,Ask-8*Point,Ask+8*Point,"TrendBuyer_BUY",1000,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
Alert("BUY order opened @ ",OrderOpenPrice(),", with ticket no. ",ticket,". Order sent successfully!");
}
} else { Alert("Error opening BUY order : ",GetLastError()); }
}
}
// }
}
}
if(MacdCurrent>1*MacdSelfValue)
{
Print("MACD>0.00001 SELL STEP 1");
if(MacdCurrent<SignalCurrent)
{
Print("MACD>SIGNAL: SELL STEP 2");
// if(MacdPrev>SignalPrev)
// {
// Print("MACD1>SIGNAL1: SELL STEP 3");
if(MACurrent<MAPrev)
{
Print("MACurrent<MAPrev: SELL STEP 4");
if(Bear>0)
{
Print("Bear>0: SELL STEP 5");
Print("Order is in progress...");
ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,2,Bid+8*Point,Bid-8*Point,"TrendBuyer_SELL",1001,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
Alert("SELL order opened @ ",OrderOpenPrice(),", with ticket no. ",ticket,". Order sent successfully!");
}
} else { Alert("Error opening SELL order : ",GetLastError()); }
}
}
// }
}
}
}
if(ADXValue<22)
{
TicksWithLowADX++;
}
else
{
TicksWithLowADX=0;
}
if(TicksWithLowADX>60)
{
Print("Preparing to buy/sell using explosive method...");
ADXIsLow = True;
}
else
{
ADXIsLow = False;
}
if(Force<0.00007&&Force>-0.00007)
{
TicksWithLowForce++;
SlippageCounter--;
}
else
{
SlippageCounter++;
}
if(SlippageCounter>=4)
{
SlippageCounter=0;
TicksWithLowForce=0;
}
if(TicksWithLowForce>40)
{
ForceIsLow=True;
}
else
{
ForceIsLow=False;
}
if(ADXIsLow&&ForceIsLow)
{
Print("ADX & Force is low; Ready for explosive: LOOP HANDLING");
if(Price1>Price2&&Price2>Price3&&Price3>Price4&&MacdCurrent>SignalCurrent&&MacdCurrent>0*MacdSelfValue)//&&Price4>Price5)
{
Print("Order is in progress...");
ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,2,Ask-8*Point,Ask+8*Point,"TrendBuyer_BUY_EXPLODE",1002,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
Alert("BUY explosive order opened @ ",OrderOpenPrice(),", with ticket no. ",ticket,". Order sent successfully!");
ExplosiveIsBought = True;
}
} else { Alert("Error opening BUY EXPLOSIVE order : ",GetLastError()); }
}
if(Price1<Price2&&Price2<Price3&&Price3<Price4&&MacdCurrent<SignalCurrent&&MacdCurrent<0*MacdSelfValue)//&&Price4<Price5)
{
Print("Order is in progress...");
ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,2,Bid+8*Point,Bid-8*Point,"TrendBuyer_SELL_EXPLODE",1003,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
Alert("SELL explosive order opened @ ",OrderOpenPrice(),", with ticket no. ",ticket,". Order sent successfully!");
ExplosiveIsBought = True;
}
} else { Alert("Error opening SELL EXPLOSIVE order : ",GetLastError()); }
}
if(ExplosiveIsBought)
{
ADXIsLow = False;
TicksWithLowADX = 0;
ForceIsLow = False;
TicksWithLowForce = 0;
}
}
}
}
return(0);
}
int deinit()
{
Alert("TrendBuyer v2.1 unititialised because of reason ",UninitializeReason());
return(0);
}