Wednesday, May 13, 2009 7:38:13 PM
This is where I'm at right now. Once I can get these circled numbers up there around 85 percent I'll be a lot happier. Not too worried about the dollar profit yet, I just want it to trade right and right on time. This is from a 3 day stretch on 10k units. It's hard teaching a computer to figure out the beast! Gonna post my EA code now in case I screw it up tonight lol and need to get back to where I once belonged lmao.
//+------------------------------------------------------------------+
//| TunnelPips64.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
extern double SL=50;//Stop Loss
extern double TP=100;//Take Profit
extern double lots=0.10;
extern int slippage=3;
extern int magicnumber=913;
double scalp=0.40;
double entry;
int time;
bool up=False;
bool down=False;
bool tunn64=False;
bool tunn169=False;
bool TT=False;
double C64,C144,C169;
//******************* TIME TO TRADE ******************
extern int _sHour=1; // Start hour
extern int _eHour=23; // End hour
int init()
{
time=TimeCurrent();
return(0);
}
//***************** START **********************
int start()
{
//Start/End Time
if(Hour()>=_sHour && Hour()<=_eHour) TT=True; else TT=False;
int D=(Digits);//# of digits after decimal of current pair in the window
double SNSL=NormalizeDouble(Bid+SL*Point,D);//Short position stop loss
double SNTP=NormalizeDouble(Bid-TP*Point,D);//Short position take profit
double LNSL=NormalizeDouble(Ask-SL*Point,D);//Long position stop loss
double LNTP=NormalizeDouble(Ask+TP*Point,D);//Long position take profit
int OT=OrdersTotal();
//EMAs
double C169=iMA(NULL,0,169,0,MODE_EMA,PRICE_CLOSE,0);
double C144=iMA(NULL,0,144,0,MODE_EMA,PRICE_CLOSE,0);
double C64=iMA(NULL,0,64,0,MODE_EMA,PRICE_CLOSE,0);
//1 Hour tunnel direction
double Trend1=iMA(NULL,60,64,0,MODE_EMA,PRICE_CLOSE,1)-iMA(NULL,60,64,0,MODE_EMA,PRICE_CLOSE,4);
double Trend2=iMA(NULL,60,144,0,MODE_EMA,PRICE_CLOSE,1)-iMA(NULL,60,144,0,MODE_EMA,PRICE_CLOSE,10);
//Current Chart tunnel direction
double CTrend1=iMA(NULL,0,64,0,MODE_EMA,PRICE_CLOSE,1)-iMA(NULL,0,64,0,MODE_EMA,PRICE_CLOSE,4);
double CTrend2=iMA(NULL,0,144,0,MODE_EMA,PRICE_CLOSE,1)-iMA(NULL,0,144,0,MODE_EMA,PRICE_CLOSE,10);
if(High[0]>C64 && Low[0]<C64) tunn64=True; else tunn64=False;
if(High[0]>C169 && Low[0]<C169) tunn169=True; else tunn169=False;
if((tunn64==True && CTrend1>CTrend2) || (tunn169==True && Trend2>0)) up=True; else up=False;
if((tunn64==True && CTrend1<CTrend2) || (tunn169==True && Trend2<0)) down=True; else down=False;
if(OT<1 && TT==True) //Are any orders open already?
{
//SHORT ENTRY
if(down==True && IsTradeAllowed()==True && TimeCurrent()>time+900)
{
int shortticket=OrderSend(Symbol(),OP_SELL,lots,Bid,slippage,SNSL,SNTP,"Short Order Being Placed ",magicnumber,0,Red);
if(shortticket<0)
{
Print("Short Order Send failed - error #",GetLastError());
}
if(shortticket>0)
{
if(OrderSelect(shortticket,SELECT_BY_TICKET,MODE_TRADES))
entry=OrderOpenPrice();
time=TimeCurrent();
Print("SELL order opened : ",OrderOpenPrice(),"|| Target Price : ",entry-scalp," Trend1 : ",Trend1," Trend2 : ",Trend2);
}
return(0);
}
//LONG ENTRY
if(up==True && IsTradeAllowed()==True && TimeCurrent()>time+900)
{
int longticket=OrderSend(Symbol(),OP_BUY,lots,Ask,slippage,LNSL,LNTP,"Long Order Being Placed ",magicnumber,0,Green);
if(longticket<0)
{
Print("Long Order Send failed - error #",GetLastError());
}
if(longticket>0)
{
if(OrderSelect(longticket,SELECT_BY_TICKET,MODE_TRADES))
entry=OrderOpenPrice();
time=TimeCurrent();
Print("BUY order opened : ",OrderOpenPrice(),"|| Target Price : ",entry+scalp," Trend1 : ",Trend1," Trend2 : ",Trend2);
}
return(0);
}
return(0);
}
//************** Close Orders ***********************
for(int cnt=0;cnt<OT;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber()==magicnumber)
{
if(OrderType()==OP_BUY) // long position is open
{
if(Bid>=entry+scalp)
{
OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Blue);
return(0);
}
}
if(OrderType()==OP_SELL) // short position is open
{
if(Ask<=entry-scalp)
{
OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Blue);
return(0);
}
}
}
}
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| TunnelPips64.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
extern double SL=50;//Stop Loss
extern double TP=100;//Take Profit
extern double lots=0.10;
extern int slippage=3;
extern int magicnumber=913;
double scalp=0.40;
double entry;
int time;
bool up=False;
bool down=False;
bool tunn64=False;
bool tunn169=False;
bool TT=False;
double C64,C144,C169;
//******************* TIME TO TRADE ******************
extern int _sHour=1; // Start hour
extern int _eHour=23; // End hour
int init()
{
time=TimeCurrent();
return(0);
}
//***************** START **********************
int start()
{
//Start/End Time
if(Hour()>=_sHour && Hour()<=_eHour) TT=True; else TT=False;
int D=(Digits);//# of digits after decimal of current pair in the window
double SNSL=NormalizeDouble(Bid+SL*Point,D);//Short position stop loss
double SNTP=NormalizeDouble(Bid-TP*Point,D);//Short position take profit
double LNSL=NormalizeDouble(Ask-SL*Point,D);//Long position stop loss
double LNTP=NormalizeDouble(Ask+TP*Point,D);//Long position take profit
int OT=OrdersTotal();
//EMAs
double C169=iMA(NULL,0,169,0,MODE_EMA,PRICE_CLOSE,0);
double C144=iMA(NULL,0,144,0,MODE_EMA,PRICE_CLOSE,0);
double C64=iMA(NULL,0,64,0,MODE_EMA,PRICE_CLOSE,0);
//1 Hour tunnel direction
double Trend1=iMA(NULL,60,64,0,MODE_EMA,PRICE_CLOSE,1)-iMA(NULL,60,64,0,MODE_EMA,PRICE_CLOSE,4);
double Trend2=iMA(NULL,60,144,0,MODE_EMA,PRICE_CLOSE,1)-iMA(NULL,60,144,0,MODE_EMA,PRICE_CLOSE,10);
//Current Chart tunnel direction
double CTrend1=iMA(NULL,0,64,0,MODE_EMA,PRICE_CLOSE,1)-iMA(NULL,0,64,0,MODE_EMA,PRICE_CLOSE,4);
double CTrend2=iMA(NULL,0,144,0,MODE_EMA,PRICE_CLOSE,1)-iMA(NULL,0,144,0,MODE_EMA,PRICE_CLOSE,10);
if(High[0]>C64 && Low[0]<C64) tunn64=True; else tunn64=False;
if(High[0]>C169 && Low[0]<C169) tunn169=True; else tunn169=False;
if((tunn64==True && CTrend1>CTrend2) || (tunn169==True && Trend2>0)) up=True; else up=False;
if((tunn64==True && CTrend1<CTrend2) || (tunn169==True && Trend2<0)) down=True; else down=False;
if(OT<1 && TT==True) //Are any orders open already?
{
//SHORT ENTRY
if(down==True && IsTradeAllowed()==True && TimeCurrent()>time+900)
{
int shortticket=OrderSend(Symbol(),OP_SELL,lots,Bid,slippage,SNSL,SNTP,"Short Order Being Placed ",magicnumber,0,Red);
if(shortticket<0)
{
Print("Short Order Send failed - error #",GetLastError());
}
if(shortticket>0)
{
if(OrderSelect(shortticket,SELECT_BY_TICKET,MODE_TRADES))
entry=OrderOpenPrice();
time=TimeCurrent();
Print("SELL order opened : ",OrderOpenPrice(),"|| Target Price : ",entry-scalp," Trend1 : ",Trend1," Trend2 : ",Trend2);
}
return(0);
}
//LONG ENTRY
if(up==True && IsTradeAllowed()==True && TimeCurrent()>time+900)
{
int longticket=OrderSend(Symbol(),OP_BUY,lots,Ask,slippage,LNSL,LNTP,"Long Order Being Placed ",magicnumber,0,Green);
if(longticket<0)
{
Print("Long Order Send failed - error #",GetLastError());
}
if(longticket>0)
{
if(OrderSelect(longticket,SELECT_BY_TICKET,MODE_TRADES))
entry=OrderOpenPrice();
time=TimeCurrent();
Print("BUY order opened : ",OrderOpenPrice(),"|| Target Price : ",entry+scalp," Trend1 : ",Trend1," Trend2 : ",Trend2);
}
return(0);
}
return(0);
}
//************** Close Orders ***********************
for(int cnt=0;cnt<OT;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber()==magicnumber)
{
if(OrderType()==OP_BUY) // long position is open
{
if(Bid>=entry+scalp)
{
OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Blue);
return(0);
}
}
if(OrderType()==OP_SELL) // short position is open
{
if(Ask<=entry-scalp)
{
OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Blue);
return(0);
}
}
}
}
return(0);
}
//+------------------------------------------------------------------+
"remember the mayonaise jar...keep cool but don't freeze"
Join the InvestorsHub Community
Register for free to join our community of investors and share your ideas. You will also get access to streaming quotes, interactive charts, trades, portfolio, live options flow and more tools.