All EA's tp and sl are stuck on stoploss 10 and takeprofit 60, no matter what I set in the EA or the properties
Just before your OrderSend add a print statement . . . print all the relevant variables (and Bid and Ask) so you can see what is going on . . without info how can you hope to solve the problem ? When you have fixed the issue simply comment out the Print statement if you don't want to clutter the Journal and log . . . don't delete it, you might need it again.
Show entire code
Hmm, Are you using any Templates with EA's already attached. I'm just guessing here.
Here is A code, but they are all doing this now for some reason
I'll add some print statements to see if I can find whats wrong, but this EA was working I haven't done anything to it I just used it for learning then once it was working I moved on to another EA to learn something new.
I'll add some print statements to see if I can find whats wrong, but this EA was working I haven't done anything to it I just used it for learning then once it was working I moved on to another EA to learn something new.
//+------------------------------------------------------------------+ //| Dirty_Rat.mq4 | //| Agent86's Dirty Rat learning Trade | //| //+------------------------------------------------------------------+ #property copyright "Agent86" //---- input parameters extern double TakeProfit=300.0; extern double Lots=0.1; extern double StopLoss=20.0; //++++ These are adjusted for 5 digit brokers. int pips2points; // slippage 3 pips 3=points 30=points double pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { if (Digits == 5 || Digits == 3) { // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- int ticket,i,total,result; double faster = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1), //MODE_SIGNAL faster_2 = iMACD(NULL,PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_2 = iMACD(NULL,PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); //MODE_SIGNAL //I'm going to have to create some loop total = OrdersTotal(); if(total < 1) { //I'll change this later so it will work with other EA's and other symbols if(faster > slower) { ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3*pips2points,Bid-StopLoss*pips2dbl,Bid+TakeProfit*pips2dbl,"My EA",12345,0,Green); if(ticket > 0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError()); return(0); } if(faster < slower) { ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,3*pips2points,Ask+StopLoss*pips2dbl,Ask-TakeProfit*pips2dbl,"My EA",12345,0,Red); if(ticket > 0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))Print("SELL order opened : ",OrderOpenPrice()); } else Print("Error opening SELL order : ",GetLastError()); return(0); } } for (i = total - 1; i >= 0; i--) { //many have recommmended deincriment due to error 4108, and increment may miss orders //deincrement had no effect with error 4108 //for(i = 0; i < OrdersTotal(); i++) //many say this will miss orders. //anyhow moving on OrderSelect(i, SELECT_BY_POS, MODE_TRADES); //I'll add return codes later, it opens trades currently if(OrderType() == OP_BUY && Symbol() == OrderSymbol()) { if(faster < slower) { result = OrderClose( OrderTicket(), OrderLots(), Bid,3, White); if(result == false) { Print("Order", OrderTicket()," failed to close Error ",GetLastError()); return(0); } } } if(OrderType() == OP_SELL && Symbol() == OrderSymbol()) { if(faster > slower) { result = OrderClose(OrderTicket(), OrderLots(), Ask,3, White); if(result == false) { Print("Order", OrderTicket()," failed to close Error ", GetLastError()); return(0); } } } } return(0); } //+------------------------------------------------------------------+See stoploss = 20, but all stop losses are hitting at -30 and tp = 300 but hits at +290 for some reason I have no idea; and I didn't change anything that I can recall.
Even if I use the Expert Properties button to make changes no matter what I change it to it's off by 10
All EA's just started doing this even those that were working when I stopped using them for learning purposes.
sl and tp was the least of my learning problems, now all the sudden.
Back to the drawing board again.
Ok for kicks I changed the OrderSend from Bid,Ask,Ask to Bid,Bid Bid etc.
And this seems to have adjusted things properly however this should not be right ?
ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3*pips2points,Ask-StopLoss*pips2dbl,Ask+TakeProfit*pips2dbl,"My EA",12345,0,Green);
This gives me the -20 stop
But it should be ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3*pips2points,Bid-StopLoss*pips2dbl,Bid+TakeProfit*pips2dbl,"My EA",12345,0,Green);
But it only started doing this, just now.
And this seems to have adjusted things properly however this should not be right ?
ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3*pips2points,Ask-StopLoss*pips2dbl,Ask+TakeProfit*pips2dbl,"My EA",12345,0,Green);
This gives me the -20 stop
But it should be ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3*pips2points,Bid-StopLoss*pips2dbl,Bid+TakeProfit*pips2dbl,"My EA",12345,0,Green);
But it only started doing this, just now.
Use to give me like -21.5 pips or so which is understandable because there is a difference in the Ask / Bid price, but 10 pips is way off ?
I did nothing, and came back from an event today and now all EA's back to normal trading as they should
Very strange, thanks all for the help and I will remember to first try and put in the print errors so I can see what is happening
Very strange, thanks all for the help and I will remember to first try and put in the print errors so I can see what is happening
All EA's tp and sl are stuck on stoploss 10 and takeprofit 60, no matter what I set in the EA or the properties
I can changed the Expert properties via properties button and it's off by 10 pips every time ?
Seems like this occured when I downloaded the data in history center, however that may not be related at all.
I since deleted the .hst files and cannot get the EA's to set sl and tp
extern double TakeProfit=20.0;
extern double Lots=0.1;
extern double StopLoss=100.0;
extern int MagicNumber=12345;
Seems straight forward
And Setting orders pretty simple
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3*pips2points,Bid-StopLoss*pips2dbl,Bid+TakeProfit*pips2dbl,"Agent86",MagicNumber,0,Green);
?
Just when I think things are going so well LOL DARN THIS THING