Quote:
|
Originally Posted by astro
I manual trade and I notice I can set the default on the number of lots I buy/sell, but how do I set the default for Stop Loss / Take Profit so I don't have to waste time entering the numbers in manually?
Thank-you in advance.
|
astro,
You
can not set a default value for S/L and T/P manually.
But it's an easy task to write a script in mql4 to do that.
For example you can run this script when you want to
buy without using the New Order dialog:
PHP Code:
//+------------------------------------------------------------------+
//| trade"buy".mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#include <stdlib.mqh>
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//+------------------------------------------------------------------+
//| script "buy" |
//+------------------------------------------------------------------+
extern double TakeProfit = 30;
extern double StopLoss = 15;
extern double Lots = 1.0;
extern double TrailingStop = 15;
int start()
{
int ticket;
//----
while(true)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,Ask+TakeProfit*Point,"buy opened",255,0,Lime);
if(ticket<=0)
{
int error=GetLastError();
Print("Error = ",ErrorDescription(error));
if(error==134) break; // not enough money
if(error==135) RefreshRates(); // prices changed
break;
}
//---- remove break statement below and take trading for all money
else { OrderPrint(); break; }
//---- 10 seconds wait
Sleep(10000);
}
return(0); // exit
}
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
And you can run this script when you want to
sell without using the New Order dialog:
PHP Code:
//+------------------------------------------------------------------+
//| trade"sell".mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#include <stdlib.mqh>
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//+------------------------------------------------------------------+
//| script "sell" |
//+------------------------------------------------------------------+
extern double TakeProfit = 30;
extern double StopLoss = 15;
extern double Lots = 1.0;
extern double TrailingStop = 0;
int start()
{
int ticket;
//----
while(true)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+StopLoss*Point,Bid-TakeProfit*Point,"sell opened",255,0,Red);
if(ticket<=0)
{
int error=GetLastError();
Print("Error = ",ErrorDescription(error));
if(error==134) break; // not enough money
if(error==135) RefreshRates(); // prices changed
break;
}
//---- remove break statement below and take trading for all money
else { OrderPrint(); break; }
//---- 10 seconds wait
Sleep(10000);
}
return(0); // exit
}
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+