Try this:
Go to options -> Expert Advisors, click: Allow automatic trading. ( http://prntscr.com/8or7ki )
it is already clicked and activated. I am not sure about 4 or 5 digits broker.I am using broker GKFX . Just in case I just changes the slippage from 3 to 30 because I am using the EA for an index and not for fx. there is an 2.0 version of the EA but I cannot find and download it.
Sorry, you are right. Here is the code:
extern string s1 = "== Basic Settings ==";
extern double StopLoss = 255;
extern double TakeProfit = 100;
extern double TrailingStop = 25;
extern double ReverseTP = 10;
extern double TrailingStep = 5;
extern string s2 = "== Trade Lots Size ==";
extern double Lots = 0.1;
extern string s3 = "== Signal Logic ==";
extern double MACDOpenLevel = 3;
extern double MACDCloseLevel = 2;
extern double MATrendPeriod = 24;
extern string s4 = "== Time Filters == ";
extern string UseTradingHours = "Time Control ( 1 = True, 0 = False )";
extern int TimeControl = 1;
extern string TimeZone = "Adjust ServerTimeZone if Required";
extern int ServerTimeZone = 0;
extern string TradingTimes = "HourStopGMT > HourStartGMT";
extern int HourStartGMT = 8;
extern int HourStopGMT = 20;
extern string DontTradeFriday = "Dont Trade After FridayFinalHourGMT";
extern bool UseFridayFinalTradeTime = TRUE;
extern int FridayFinalHourGMT = 6;
extern string s5 = "== Extra Settings ==";
extern int Slippage = 3;
extern double MaxSpread = 4.0;
extern int MagicNumber = 10042;
extern string TradeComment = "MACD Turbo v2.0";
int checkorder=1;
int SlipPage;
double Points,SL,TP;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
// 4 or 5 Digit Broker Account Recognition
void HandleDigits()
{
// Automatically Adjusts to Full-Pip and Sub-Pip Accounts
if (Digits == 4 || Digits == 2)
{
SlipPage = Slippage;
Points = Point;
}
if (Digits == 5 || Digits == 3)
{
SlipPage = Slippage*10;
Points = Point*10;
}
}
//----------------------- PRINT COMMENT FUNCTION
void subPrintDetails()
{
string sComment = "";
string SP = " ----------------------------------------\n";
string NL = "\n";
string SessionActive,CurrentSpread,spread;
TradeSession();
MaxSpreadFilter();
if(Digits == 4 || Digits == 5){spread = DoubleToStr(10000.0 * (Ask - Bid),1);}
if(Digits == 2 || Digits == 3){spread = DoubleToStr(100.0 * (Ask - Bid),1);}
if (TradeSession())SessionActive = "Trading...";
else SessionActive = "Non-Trading Time";
if (MaxSpreadFilter())CurrentSpread = " is to High";
else CurrentSpread = " is OK";
sComment = "MACD Turbo v2.0" + NL;
sComment = sComment + NL;
sComment = sComment + "Magic Number " + DoubleToStr(MagicNumber,0) + NL;
sComment = sComment + "StopLoss " + DoubleToStr(StopLoss,0) + " | ";
sComment = sComment + "TakeProfit " + DoubleToStr(TakeProfit,0) + " | ";
sComment = sComment + "TrailingStop " + DoubleToStr(TrailingStop,0) + NL;
sComment = sComment + "Date: " + Month() +"-"+Day()+"-"+Year()+" Server Time: " + TimeToStr(TimeCurrent(), TIME_SECONDS) + NL;
sComment = sComment + "GMT Time: " + TimeToStr((TimeCurrent()+ (( 0 - ServerTimeZone) * 3600)), TIME_SECONDS) + NL;
sComment = sComment + "ServerTimeZone: " + ServerTimeZone + " (TimeZone)" + NL;
sComment = sComment + SP;
sComment = sComment + "Lot Size " + DoubleToStr(Lots,2) + NL;
sComment = sComment + SessionActive + NL;
sComment = sComment + "Spread: " + spread + CurrentSpread + NL;
Comment(sComment);
}
//+------------------------------------------------------------------+
bool TradeSession() {
int HourStartTrade;
int HourStopTrade;
HourStartTrade = HourStartGMT + ServerTimeZone;
HourStopTrade = HourStopGMT + ServerTimeZone;
if (HourStartTrade < 0)HourStartTrade = HourStartTrade + 24;
if (HourStartTrade >= 24)HourStartTrade = HourStartTrade - 24;
if (HourStopTrade > 24)HourStopTrade = HourStopTrade - 24;
if (HourStopTrade <= 0)HourStopTrade = HourStopTrade + 24;
if ((UseFridayFinalTradeTime && (Hour()>=FridayFinalHourGMT + ServerTimeZone) && DayOfWeek()==5)||DayOfWeek()==0)return (FALSE); // Friday Control
if((TimeControl(HourStartTrade,HourStopTrade)!=1 && TimeControl==1 && HourStartTrade<HourStopTrade)
|| (TimeControl(HourStopTrade,HourStartTrade)!=0 && TimeControl==1 && HourStartTrade>HourStopTrade)
||TimeControl==0)return (TRUE); // "Trading Time";
return (FALSE); // "Non-Trading Time";
}
//+------------------------------------------------------------------+
int TimeControl(int StartHour, int EndHour)
{
if (Hour()>=StartHour && Hour()< EndHour)
{
return(0);
}
return(1);
}
//+------------------------------------------------------------------+
bool MaxSpreadFilter()
{
RefreshRates();
if ((Digits == 4 || Digits == 5)&&(10000.0 * (Ask - Bid) > MaxSpread))
{return(true);}
if ((Digits == 2 || Digits == 3)&&(100.0 * (Ask - Bid) > MaxSpread))
{return(true);}
else return(false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double MacdCurrent, MacdPrevious, SignalCurrent;
double SignalPrevious, MaCurrent, MaPrevious;
int cnt, ticket, total;
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external
// variables (Lots, StopLoss, TakeProfit,
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return(0); // check TakeProfit
}
// to simplify the coding and speed up access
// data are put into internal variables
MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0);
MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);
HandleDigits();
subPrintDetails();
total=OrdersTotal();
if(checkorder<1)
{
// if no opened orders identified
if(AccountFreeMargin()<(1000*Lots))
{
Print("You dont have enough money. Free Margin = ", AccountFreeMargin());
return(0);
}
// check for long position (BUY) possibility
if(!MaxSpreadFilter() && MacdCurrent<0 && MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious &&
MathAbs(MacdCurrent)>(MACDOpenLevel*Points) && MaCurrent>MaPrevious && TradeSession())
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,SlipPage,0,0,TradeComment,MagicNumber,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
Print("BUY order opened : ",OrderOpenPrice());
checkorder=checkorder+1;
}
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
// check for short position (SELL) possibility
if(!MaxSpreadFilter() && MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
MacdCurrent>(MACDOpenLevel*Points) && MaCurrent<MaPrevious && TradeSession())
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,SlipPage,0,0,TradeComment,MagicNumber,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
Print("SELL order opened : ",OrderOpenPrice());
checkorder=checkorder+1;
}
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
// it is important to enter the market correctly,
// but it is more important to exit it correctly...
if(checkorder>0)
{
checkorder=0;
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol()&& // check for symbol
OrderMagicNumber()==MagicNumber) // check the Magic Number
{
if(OrderType()==OP_BUY) // go to long position
{
checkorder=checkorder+1;
// should it be closed?
if(Bid-OrderOpenPrice()>ReverseTP*Points && MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
MacdCurrent>(MACDCloseLevel*Points))
{
OrderClose(OrderTicket(),OrderLots(),Bid,SlipPage,Violet); // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Points*TrailingStop)
{
if(OrderStopLoss()<Bid-Points*(TrailingStop+TrailingStep))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Points*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
// modify OrderStopLoss and OrderTakeProfit for Buy
if(OrderStopLoss()==0 && OrderTakeProfit()==0 && (StopLoss>0||TakeProfit>0))
{
SL = OrderStopLoss();
if (StopLoss>0) {SL =(OrderOpenPrice() - (StopLoss*Points));}
TP = OrderTakeProfit();
if (TakeProfit>0) {TP =(OrderOpenPrice() + (TakeProfit*Points));}
OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,Green);
return(0);
}
}
if(OrderType()==OP_SELL) // go to short position
{
checkorder=checkorder+1;
// should it be closed?
if((OrderOpenPrice()-Ask)>(ReverseTP*Points) && MacdCurrent<0 && MacdCurrent>SignalCurrent &&
MacdPrevious<SignalPrevious && MathAbs(MacdCurrent)>(MACDCloseLevel*Points))
{
OrderClose(OrderTicket(),OrderLots(),Ask,SlipPage,Violet); // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Points*TrailingStop))
{
if((OrderStopLoss()>(Ask+Points*(TrailingStop+TrailingStep))) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Points*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
// modify OrderStopLoss and OrderTakeProfit for Sell
if(OrderStopLoss()==0 && OrderTakeProfit()==0 && (StopLoss>0||TakeProfit>0))
{
SL = OrderStopLoss();
if (StopLoss>0) {SL =(OrderOpenPrice() + (StopLoss*Points));}
TP = OrderTakeProfit();
if (TakeProfit>0) {TP =(OrderOpenPrice() - (TakeProfit*Points));}
OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,Red);
return(0);
}
}
}
}
}
return(0);
}
// the end.
-
Play videoPlease edit your post.
For large amounts of code, attach it.
Code HourStartTrade = HourStartGMT + ServerTimeZone; : if (HourStartTrade < 0)HourStartTrade = HourStartTrade + 24; if (HourStartTrade >= 24)HourStartTrade = HourStartTrade - 24;
Simplified HourStartTrade = (HourStartGMT + ServerTimeZone + 24) % 24;
Likewise: MaxSpreadFilter returns true if the spread is too large. If it was named isSpreadOK and returned true if it is less than 3 pips then You would have written "if isSpreadOK" which reads good in English instead of your misleading "if not max spread filter."Don't use zero and one extern string UseTradingHours = "Time Control ( 1 = True, 0 = False )"; extern int TimeControl = 1; : if((TimeControl(HourStartTrade,HourStopTrade)!=1 && TimeControl==1 && HourStartTrade<HourStopTrade) || (TimeControl(HourStopTrade,HourStartTrade)!=0 && TimeControl==1 && HourStartTrade>HourStopTrade) ||TimeControl==0)return (TRUE); // "Trading Time"; return (FALSE); // "Non-Trading Time"; } int TimeControl(int StartHour, int EndHour) { if (Hour()>=StartHour && Hour()< EndHour) { return(0); } return(1); }
when you mean true and false //extern string UseTradingHours = "Time Control ( 1 = True, 0 = False )"; extern bool TimeControlEnabled = true; : return (!TimeControl(HourStartTrade,HourStopTrade) && TimeControlEnabled && HourStartTrade<HourStopTrade) || ( TimeControl(HourStopTrade,HourStartTrade) && TimeControlEnabled && HourStartTrade>HourStopTrade) || !TimeControlEnabled; } bool TimeControl(int StartHour, int EndHour) { return Hour()>=StartHour && Hour()< EndHour; }
You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.if (!MaxSpreadFilter() && MacdCurrent<0 && MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious && MathAbs(MacdCurrent)>(MACDOpenLevel*Points) && MaCurrent>MaPrevious && TradeSession()) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,SlipPage,0,0,TradeComment,MagicNumber,0,Green);
OrderClose(OrderTicket(),OrderLots(),Bid,SlipPage,Violet); // close position OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Points*TrailingStop,OrderTakeProfit(),0,Green);
Check your return codes. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles- sheriffonline: Try increasing MaxSpread as more..I agree. Print your variables to your if statements and track it down.
Hm? I changed max spread but no trade since them. WH Roeder I tried to check the return values but I think I am not that expert to find out how. Maybe the the free margin check function could be also a problem. The code says:
if(AccountFreeMargin()<(1000*Lots) {
Print("You dont have enough money. Free Margin = ", AccountFreeMargin());
return(0);
I you are trading indices, in generell you start with lotsize "1" (not 0,1 or 0,001). In this case it checks if the free margin is less than 1000*1 lot -> so I have not enough money of course! Am I right or do I am thinking wrong?
I changed the lotsize in the "free margin check" and additionally the max spread. Now the EA is trading!! The only problem I have is that I don't know what the EA does with SL and TP. The profit is fine butthe trades were not closed at the TP or trailing stop. Thisis still under investigation :)
Many thanks for your answers. they helped me verry much. I keep you informed!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello together,
I set up my own VPN and I am trying an basic EA just to test if everything is working properly via the VPN. I am using the MACD Turbo for trading (a simple EA). Everything is set up right from my point of view. The smiley appears but no trade since two weeks.
The backtest shows that there are many trades since that time period. Can somebody tell me what the problem could be? I am using the EA fpr an Index not for FX but I think that cannot be the reason.
Many thanks in advance