This EA is not trading. Can anyone tell me why. Also, is this the correct way to code Take Profit and Stop Loss?
Can you help? I am learning MQL4 and working through the MQL4 tutorials. I have been working on the ROC EA example and have made some tweaks to the code so all it takes for a trade to be made - either opening or closing - is the crossing of one specialised MA(Moving Average) over another. The MA's are calculated via a separate indicator called rocseparate. The data of the two MA's are stored in Buffer 4 and Buffer 5 respectively.
The Stop Loss and Take Profit (TP) are set as external variables but the EA can close trades if the MA criteria is correct before it reaches TP.
The EA is NOT trading!! So my questions are: -
1) Why?
2) Why??
3) I calculated the StopLoss and TP as the External variable x Point. However, in order to get the correct figures I had to multiply the ponts by 10, is this the correct way of getting the orders placed correctly according to the parameters set in the external variables?
SL=Bid - StopLoss*(Point*10); // Calculating SL of opened
TP=Bid + TakeProfit*(Point*10); // Calculating TP of opened.
Any help, as ever, would be very much appreciated.
Thanks
W
How is it not trading in strategietester or on a demo/real account not live trading
Check atleast inside terminal you have tab Experts and Journal read the messages inside this
while(true) // Orders closing loop
while what is true ?
Should that not be while(Work) ?
Ok ignore that, I tested it in a script you can use while that way, I wasn't aware you could set the condition of while explicitly without some conditions ... you learn something new every day ... btw did you check your log file for errors ?
While you mess up ... :)
// Closing orders if (Tip==0 && Cls_B==true) { while(Ans == false) { if (Tip==1 && Cls_S==true) { while(Ans == false) { // Opening orders if (Total==0 && Opn_B==true) { while(Ticket < 1) { if (Total==0 && Opn_S==true) { while(Ticket < 1)
The EA is NOT trading!! So my questions are: -
1) Why?
Why aren't you checking if your OrderSend() works or fails ? if it fails it returns -1 . . . so check if the ticket is -1 if it is report the error then you will know why it has failed . . .
Is your Broker an ECN Broker ? if they are you can't set SL & TP when you do the OrderSend(), you have to send with TP & SL at 0.0 and then do an OrderModify()
//++++ These are adjusted for 5 digit brokers. int pips2points; // slippage 3 pips 3=points 30=points double pips2dbl; // Stoploss 15 pips 0.015 0.0150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ OptParameters(); if (Digits % 2 == 1){ // DE30=1/JPY=3/EURUSD=5 https://www.mql5.com/en/forum/135345 pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl //---- These are adjusted for 5 digit brokers. /* On ECN brokers you must open first and THEN set stops int ticket = OrderSend(..., 0,0,...) if (ticket < 0) Alert("OrderSend failed: ", GetLastError()); else if (!OrderSelect(ticket, SELECT_BY_TICKET)) Alert("OrderSelect failed: ", GetLastError()); else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0) Alert("OrderModify failed: ", GetLastError()); */
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Can you help? I am learning MQL4 and working through the MQL4 tutorials. I have been working on the ROC EA example and have made some tweaks to the code so all it takes for a trade to be made - either opening or closing - is the crossing of one specialised MA(Moving Average) over another. The MA's are calculated via a separate indicator called rocseparate. The data of the two MA's are stored in Buffer 4 and Buffer 5 respectively.
The Stop Loss and Take Profit (TP) are set as external variables but the EA can close trades if the MA criteria is correct before it reaches TP.
The EA is NOT trading!! So my questions are: -
1) Why?
2) Why??
3) I calculated the StopLoss and TP as the External variable x Point. However, in order to get the correct figures I had to multiply the ponts by 10, is this the correct way of getting the orders placed correctly according to the parameters set in the external variables?
SL=Bid - StopLoss*(Point*10); // Calculating SL of opened
TP=Bid + TakeProfit*(Point*10); // Calculating TP of opened.
Any help, as ever, would be very much appreciated.
Thanks
W