Hi,
Timeframe: Daily
Pairs: Any
At the start of each day (0:01) place pending Buy and Sell 40 pips from current price with TP/SL of 40 pips.
You could use the average daily range to estimate how many pips to place TP.
If a trade is in motion on the next day I sometimes move the SL and TP up again 40 pips from current Bid trailing the stop manually depending on momentum and trend direction.
There might be a better way to trail stop every 40 pips or so but this strategy seems to always gain at least 40 pips. Add many pairs and you have yourself a few pips.
It would be great if someone could code this in to an EA with money management and dashboard trading all pairs, way over my head.
Here is the template, indicators, scripts (pending orders and close all) and the broken ea.
DailyRange.zip (22.8 KB)
I’ve modified the send_pending script from MT4 to set the pending orders manually each night which saves some time.
//+------------------------------------------------------------------+
//| send_pending.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link ""
#property show_confirm
//+------------------------------------------------------------------+
//| script "send pending order with expiration data" |
//+------------------------------------------------------------------+
int start()
{
int ticket,expiration;
double point;
//----
point=MarketInfo(Symbol(),MODE_POINT);
expiration=CurTime()+PERIOD_D1*60;
//----
while(true)
{
ticket=OrderSend(Symbol(),OP_SELLSTOP,1.0,Bid-400*point,0,Bid,Bid-800*point,"SELLSTOP",16384,expiration,Green);
if(ticket<=0) Print("Error = ",GetLastError());
else { Print("ticket = ",ticket); break; }
}
while(true)
{
ticket=OrderSend(Symbol(),OP_BUYSTOP,1.0,Bid+400*point,0,Bid,Bid+800*point,"BUYSTOP",16384,expiration,Green);
if(ticket<=0) Print("Error = ",GetLastError());
else { Print("ticket = ",ticket); break; }
Sleep(10000);
}
//----
return(0);
}
//+------------------------------------------------------------------+
I tried to build a simple EA by using snippets of code and patching together but am seeing OrderSend error 130.
#property copyright "Copyright © 2013"
#property link "[email protected]"
//---- input parameters
extern double Lotsize=0.1;
extern double iEma=200;
bool tradeOpen=false;
int ticket,point,expiration,order=0;
double yClose;
bool NewBar()
{
static datetime lastbar = 0;
datetime curbar = Time[0];
if(lastbar!=curbar)
{
lastbar=curbar;
return (true);
}
else
{
return(false);
}
}
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
for(int pos=0;pos<OrdersTotal();pos++)
{//Loop through existing orders
if(OrderSelect(pos,SELECT_BY_POS)==false) continue;
if(OrderSymbol()!=Symbol()) continue;//Order doesn't match current chart pair
if(OrderSymbol()==Symbol())
{//Order matches chart pair
ticket=OrderTicket();
tradeOpen=true;
break;
}//End order match
}//End looping through open orders
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
/*
int i=0,R10=0;
double magic,raw,ravg,bsl,ssl,buy_tp,sell_tp;
for(i=1;i<=10;i++)
R10 = R10 + (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;
raw = R10/10;
ravg = 10 * (MathRound(((25 * (MathRound(raw / 25))) / 2) / 10));
yClose=Close[1];
magic=ravg*Point;
bsl=Ask-magic;
ssl=Bid+magic;
buy_tp=Ask+magic;
sell_tp=Bid-magic;
*/
if((NewBar()==true)&&(DayOfWeek()!=0)&&(tradeOpen==false))
{ // start New Bar trade, but not on Sunday, nor if last trade still open
iEma=iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,1);
if(yClose>iEma)
order=1;
else
{
if(yClose<iEma)
order=-1;
else
order=0;
}
if(order==1) // Buy
{
ticket=OrderSend(Symbol(),OP_BUYSTOP,1.0,Bid+400*point,0,0,0,"BUYSTOP",16384,expiration,Green);
if(ticket<=0) Print("Error = ",GetLastError());
else Print("ticket = ",ticket);
tradeOpen=true;
}
if(order==-1)//Sell
{
ticket=OrderSend(Symbol(),OP_SELLSTOP,1.0,Bid-400*point,0,0,0,"SELLSTOP",16384,expiration,Green);
if(ticket<=0) Print("Error = ",GetLastError());
else Print("ticket = ",ticket);
tradeOpen=true;
}
if(order==0)//Neither
Alert("No valid signal on ",Symbol()," today.");
} //End New Bar
/*
if(tradeOpen==true)
{
if(OrderSelect(ticket,SELECT_BY_TICKET)==true)
{
if(OrderCloseTime()!=0)
tradeOpen=false;
}
else
Print("OrderSelect returned the error of ",GetLastError());
} */
//----
return(0);
}
//+------------------------------------------------------------------+