There are some brokers that do not allow scripted or EA orders that have the stop-loss and the take-profit included with the order. Some of those will execute the trade, but leave off the SL and the TP, others will not execute the order at all.
In those cases, the script or the EA must place the order in one command, and then use another command to modify the position to add the SL and TP.
So I edited the code to do just that.
It places the trade, then goes in and puts on the SL and the TP.
I also put the variables for the lot size and the stop and profit targets at the very top, so that anyone with virtually no programming experience can open it and change the values to what they want.
To do this, with your Navigator window open, and the "Scripts" box expanded, just right click on the script, and click "Modify". It will open the code, and the first three lines of code (after the comments) are the lots and the stopsize and the profsize.
For the BUY order it looks like:
//+------------------------------------------------------------------+
//|1-Click Buy Order.mq4 |
//+------------------------------------------------------------------+
double lots = 0.1;
double stopsize = 100;
double profsize = 100;
int ticket;
double stop;
double prof;
int start()
{
ticket=OrderSend(Symbol(), OP_BUY, lots, Ask, 3, 0, 0);
stop=(Ask-stopsize*Point);
prof=(Ask+profsize*Point);
OrderModify( ticket, OrderOpenPrice(), stop, prof, 0, Blue);
return(0);
}
and for the SELL order it looks like:
//+------------------------------------------------------------------+
//|1-Click Sell Order.mq4 |
//+------------------------------------------------------------------+
double lots = 0.1;
double stopsize = 100;
double profsize = 100;
int ticket;
double stop;
double prof;
int start()
{
ticket=OrderSend(Symbol(), OP_SELL, 0.1, Bid, 3, 0, 0);
stop=(Bid+stopsize*Point);
prof=(Bid-profsize*Point);
OrderModify( ticket, OrderOpenPrice(), stop, prof, 0, Red);
return(0);
}
You just put in the lots you want, and the stop and profit targets you want.
When finished, click the "Compile" button at the top, and it will save the changes.
Also, many brokers are now using 5th decimal place (or 3rd for JPY pairs), and so if you want a 10-pip SL/TP, you need to enter 100.
If you are using a broker that still is on 4th decimal, then you input 10 for a 10-pip SL/TP, or 100 for a 100-pip SL/TP.
I am attaching the scripts in a zip file. In the attached files are several extra lines of code I was using to troubleshoot, but they will have no effect on you if you just leave them there if you see them.
I hope someone finds this to be helpful!
Jeff