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.
Funny you should ask that, I've been thinking about that while at work tonight. I was going to ask you the same thing just now. I thought of a couple of solutions (which may or may not work lol).
First, since the only difference between a trendline and a horizontal line is the slope, if you had the beginning and end points of the line and knew how many bars were between, you could programmatically calculate the value of a concurrent trendline touch. Sort of like if you had a very small 5 bar sample and you drew a line from the top of the first bar to the top of the third bar. Based on that you could calculate where the top of any concurrent bar would be if they followed the trend line.
Second, I thought about using the arctangent or other function and programmatically figuring the trendline touch that way with the angle of the line. Knowing the slope of an upward trendline for example, theoretically you should be able to count over a certain number of bars (x) and calculate how high or low the (y) coordinate should be and make the trade there. After typing this all out, I have not put as much thought into this as the others so it's still sort of murky. Programming wise, it might be easier since you could (theoretically at least) take the slope of the line times the beginning point and calculate all the way up the line or down the line as the case may be.
Third, since you can move objects around based on coordinates you could use the beginning and end of the trendline and calculate the coordinates of the trendline. I think it would be pretty processor intensive since you'd have to create and delete an object say the size of at least a pixel every tick and when that object hit the calculated coordinates of the trendline then make the trade.
There may be some other ways, I just haven't thought of them yet.
Trading either would be pretty cool, short or long based on the bid+spread if shorting it or the ask-spread if going long. If it broke the trendline, then go with the breakout. Should be able to do it with a very minimal manually calculated stop as well like 3 pips or so.
Me again...have you found anything to mimic the Cross function from VTTrader? It sure is a lot more convoluted to code in MT4....(this type of thing anyway)
I have been trying to reference the objects in that SDC indie, and when I pull the PRICE1 and PRICE2 on each of the two channels, I get the same value regardless of whether it is the standard channel or the regression. Just sending it to the screen in an alert for now, but the numbers don't match what I see on the chart...have you done anything with it yet?
yep a lot better view
Or yes, you can do it that way too! I am more comfortable seeing it that way too, it gives me room for hope that it will go my direction lol.
Yes, right click on the chart and select properties, then check the box marked "Chart Shift".
sherri i found a button it has alittle red cross on it--i like to be able to see my charts this way--they seem crammed up against the wall the other way --also i can extend my trend line better
lol-tks anyway-so if you did it accidently-there must be a way to do it-i'll hunt
I've done it before, usually accidentally....though I cannot tell you how you are supposed to do it. Sorry!
sherri or git-is there a way on mt4 to move the chart to the right more in the future --oanda charts have that ability
Nicely done! I am still trying to get SG's long ported and compiling....LOL...LOTS of code
Hey Sherri, check out this indie I made. Not finished yet, but it shows the 1 hour support and 1 hour resistance regardless of the timeframe of the chart you're looking at with the red horizontal lines plus it adds the e64, the e144, and the e169. It's my first attempt at using Objects instead of buffers and I'm pretty tickled. Gonna add the 4 hour for sure later and play around with the colors and line widths.
Kind of even been thinking about showing it as a histogram of the difference between the current price and the support or resistance levels.
Here's the code so far.
//+------------------------------------------------------------------+
//| GitsTunnelResistance.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 PowderBlue //Recent 1 Hour resistance
#property indicator_color2 Khaki//Recent 1 Hour support
#property indicator_color3 Chartreuse//Recent 4 Hour resistance
#property indicator_color4 Red//Recent 4 Hour support
#property indicator_color5 Red//Current62ema
#property indicator_color6 Yellow//Current144ema
#property indicator_color7 Chartreuse//Current169ema
//---- buffers
double H1R,H1S,H4R,H4S;
double E62[];
double E144[];
double E169[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(7);
//---- drawing settings
SetIndexStyle(0,DRAW_LINE,STYLE_DASHDOT,3);//1 Hour Resistance
SetIndexStyle(1,DRAW_LINE,STYLE_DASHDOT,3);//1 Hour Support
SetIndexStyle(2,DRAW_LINE,2);//4 Hr Resistance
SetIndexStyle(3,DRAW_LINE,2);//4 Hr Support
SetIndexStyle(4,DRAW_LINE);//E62
SetIndexStyle(5,DRAW_LINE);//E144
SetIndexStyle(6,DRAW_LINE);//E169
//---- indicator mapping
SetIndexBuffer(0,H1R);
SetIndexBuffer(1,H1S);
SetIndexBuffer(2,H4R);
SetIndexBuffer(3,H4S);
SetIndexBuffer(4,E62);
SetIndexBuffer(5,E144);
SetIndexBuffer(6,E169);
//---- indicator labeling
IndicatorShortName("Gits Tunnel Resistance");
SetIndexLabel(0,"1 Hour Resistance");
SetIndexLabel(1,"1 Hour Support");
SetIndexLabel(2,"4 Hour Resistance");
SetIndexLabel(3,"4 Hour Support");
SetIndexLabel(4,"Current E62");
SetIndexLabel(5,"Current E144");
SetIndexLabel(6,"Current E169");
return(0);
}
int deinit()
{
//----
ObjectsDeleteAll();
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- Current EMAs
for(int i=0; i<limit; i++)
E62=iMA(NULL,0,62,0,MODE_EMA,PRICE_CLOSE,i);
for(i=0; i<limit; i++)
E144=iMA(NULL,0,144,0,MODE_EMA,PRICE_CLOSE,i);
for(i=0; i<limit; i++)
E169=iMA(NULL,0,169,0,MODE_EMA,PRICE_CLOSE,i);
// 1 Hour resistance
for(i=1; i<limit; i++)
{
if(iHigh(NULL,60,i+1) > iHigh(NULL,60,i)) H1R=iHigh(NULL,60,i+1); else H1R=iHigh(NULL,60,i);
ObjectCreate("H1Resistance",OBJ_HLINE,0,0,H1R);
break;
}
// 1 Hour support
for(i=0; i<limit; i++)
{
if(iLow(NULL,60,i+1) < iLow(NULL,60,i)) H1S=iLow(NULL,60,i+1); else H1S=iLow(NULL,60,i);
ObjectCreate("H1Support",OBJ_HLINE,0,0,H1S);
break;
}
// 4 Hour resistance
for(i=0; i<limit; i++)
{
if(iHigh(NULL,240,i+1) < iHigh(NULL,240,i)) H4R=High; break;
}
// 4 Hour support
for(i=0; i<limit; i++)
{
if(iLow(NULL,240,i+1) > iLow(NULL,240,i)) H4S=Low; break;
}
Comment("H1R = ",H1R, " || H1S = ",H1S," || H4R = ",H4R," || H4S = ",H4S);
//---- done
return(0);
}
//+------------------------------------------------------------------+
LOL! Found a really simple HA indie that works nicely...
Yeah, originally I had instead of the [t] and it kept making everything italic lol.
Ahhhh - makes sense....formatting is a b|tch sometimes
I figured it out, not through with it yet though. It is indented, but when I copied and pasted, the formatting didn't transfer.
Eventually, I put break where the return was, since I want it to stop looking when it found the instance to be true and save the H1R and H1S values. Just got home, when I get it working like it should I'll send it to you. Thanks!
It looks like you have two statements to be executed if the if portion is true....parentheses are required for more than one statement. FWIW, it would be good to get in the habit of using indentation - makes it easier to spot syntax issues (and easier for other people to read )
Code should be basically like this:
// 1 Hour resistance
for(t=0; t<limit; t++)
if(iHigh(NULL,60,t+1)!>iHigh(NULL,60,t))
(
H1R==High[t];
return(0);
)
// 1 Hour support
for(t=0; t<limit; t++)
if(iLow(NULL,60,t+1)!<iLow(NULL,60,t))
(
H1S==Low[t];
return(0);
)
One thing I am curious about is why you have the return in each of those statements? If you don't need it, you could also leave the code like this:
// 1 Hour resistance
for(t=0; t<limit; t++)
if(iHigh(NULL,60,t+1)!>iHigh(NULL,60,t))
H1R==High[t];
// 1 Hour support
for(t=0; t<limit; t++)
if(iLow(NULL,60,t+1)!<iLow(NULL,60,t))
H1S==Low[t];
Sherri, what am I doing wrong here?
I want to go back through the candles and if the high of the previous candle is not higher than the current candle then set the H1R or H1S value to the high of the current candle and determine support/resistance. It gives me an unbalanced parenthesis error.
// 1 Hour resistance
for(t=0; t<limit; t++)
if(iHigh(NULL,60,t+1)!>iHigh(NULL,60,t)) H1R==High[t]; return(0);
// 1 Hour support
for(t=0; t<limit; t++)
if(iLow(NULL,60,t+1)!<iLow(NULL,60,t)) H1S==Low[t]; return(0);
The 1 min was way too short, but as I posted on the other board, the 5 min ran overnight and netted 29 pips on 2 trades with no losses. (The first trade being one I manually closed for like 5 pips).
Still needs more tweaking. Little revelation came to light there with the PRICE_CLOSE vs PRICE_OPEN emas after making about 10 changes and still getting trades being entered when (I thought) they shouldn't. It's evidently more logical than I am, which is a good thing, just have to be very specific. At work the next 3 or 4 days so my posting will be limited at best.
How did your 1 min test go?
You've been busy! How did it work for you?
Crossing of the CLOSE and OPEN EMAs are crucial. If the PRICE_CLOSE is above the PRICE_OPEN and the 64 is under the 169 then it's going to blow past the 64 to the 169 and vice versa. Similarly if the PRICE_CLOSE is below the PRICE_OPEN while the 64 is above the 169, then it's going to blow past the 64 headed down to the 169 or below.
Mainly wanted to leave this note to myself so I don't loose my train of thought after I come back from work in a few days.
//+------------------------------------------------------------------+
//| TunnelPips64.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
extern double SL=40;//Stop Loss
extern double TP=200;//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 Ltrigger=False;
bool Strigger=False;
bool TT=False;
double C64,C169;
//IFT Parameters
extern double IHi=0.65;//IFT Hi Line (passed to custom)
extern double ILo=-0.65;//IFT Lo Line (passed to custom)
extern int IRsi=5;// IFT first parameter
extern int IWma=9;// IFT second parameter
//******************* 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 O169=iMA(NULL,0,169,0,MODE_EMA,PRICE_OPEN,0);
double O64=iMA(NULL,0,64,0,MODE_EMA,PRICE_OPEN,0);
double C64=iMA(NULL,0,64,0,MODE_EMA,PRICE_CLOSE,0);
double HTrend=iMA(NULL,0,169,0,MODE_EMA,PRICE_CLOSE,1)-iMA(NULL,0,169,0,MODE_EMA,PRICE_CLOSE,12);
//64 direction - Looking for uptrend with CLOSE EMA crossing above OPEN EMA
double CTrend1=iMA(NULL,0,64,0,MODE_EMA,PRICE_CLOSE,1)-iMA(NULL,0,64,0,MODE_EMA,PRICE_CLOSE,5);
double CTrend2=iMA(NULL,0,64,0,MODE_EMA,PRICE_CLOSE,1)-iMA(NULL,0,64,0,MODE_EMA,PRICE_OPEN,10);
//64 direction - Looking for downtrend with OPEN EMA crossing below CLOSE EMA
double CTrend3=iMA(NULL,0,64,0,MODE_EMA,PRICE_OPEN,1)-iMA(NULL,0,64,0,MODE_EMA,PRICE_CLOSE,5);
double CTrend4=iMA(NULL,0,64,0,MODE_EMA,PRICE_OPEN,1)-iMA(NULL,0,64,0,MODE_EMA,PRICE_OPEN,10);
//IFT Function
double ITrig=iCustom(NULL,5,"IFT",IHi,ILo,IRsi,IWma,1,1);//current IFT
double PITrig=iCustom(NULL,5,"IFT",IHi,ILo,IRsi,IWma,1,2);//previous IFT
if(C64>C169)
{
if(High[0]>=O64 && Low[0]<=O64) tunn64=True; else tunn64=False;
if(High[0]>=O169 && Low[0]<=O169) tunn169=True; else tunn169=False;
}
if(C64<C169)
{
if(High[0]>=C64 && Low[0]<=C64) tunn64=True; else tunn64=False;
if(High[0]>=C169 && Low[0]<=C169) tunn169=True; else tunn169=False;
}
//This part is very important when the 64 is close to the 169. Determine the switch between
//the open and close EMAs - Do not change
if(ITrig<ILo && C64>C169 && CTrend1>CTrend2) Ltrigger=True; else Ltrigger=False;
if(ITrig>IHi && C64<C169 && CTrend3<CTrend4) Strigger=True; else Strigger=False;
if((tunn64==True && Ltrigger==True) || (tunn169==True && Ltrigger==True)) up=True; else up=False;
if((tunn64==True && Strigger==True) || (tunn169==True && Strigger==True)) 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);
}
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);
}
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 && TimeCurrent()>time+300) // long position is open
{
if(ITrig>IHi && ITrig<PITrig)
{
OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Blue);
return(0);
}
}
if(OrderType()==OP_SELL && TimeCurrent()>time+300) // short position is open
{
if(ITrig<ILo && ITrig>PITrig)
{
OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Blue);
return(0);
}
}
}
}
return(0);
}
//+------------------------------------------------------------------+
Tonight's version. Thank goodness for copy and paste.
//+------------------------------------------------------------------+
//| TunnelPips64.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
extern double SL=40;//Stop Loss
extern double TP=200;//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 Ltrigger=False;
bool Strigger=False;
bool TT=False;
double C64,C169;
//IFT Parameters
extern double IHi=0.65;//IFT Hi Line (passed to custom)
extern double ILo=-0.65;//IFT Lo Line (passed to custom)
extern int IRsi=5;// IFT first parameter
extern int IWma=9;// IFT second parameter
//******************* 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 O169=iMA(NULL,0,169,0,MODE_EMA,PRICE_OPEN,0);
double O64=iMA(NULL,0,64,0,MODE_EMA,PRICE_OPEN,0);
double C64=iMA(NULL,0,64,0,MODE_EMA,PRICE_CLOSE,0);
double HTrend=iMA(NULL,0,169,0,MODE_EMA,PRICE_CLOSE,1)-iMA(NULL,0,169,0,MODE_EMA,PRICE_CLOSE,12);
//64 direction - Close EMAS
double CTrend1=iMA(NULL,0,64,0,MODE_EMA,PRICE_CLOSE,1)-iMA(NULL,0,64,0,MODE_EMA,PRICE_CLOSE,5);
double CTrend2=iMA(NULL,0,64,0,MODE_EMA,PRICE_CLOSE,5)-iMA(NULL,0,64,0,MODE_EMA,PRICE_CLOSE,10);
//64 direction - Open EMAS
double CTrend3=iMA(NULL,0,64,0,MODE_EMA,PRICE_OPEN,1)-iMA(NULL,0,64,0,MODE_EMA,PRICE_OPEN,5);
double CTrend4=iMA(NULL,0,64,0,MODE_EMA,PRICE_OPEN,5)-iMA(NULL,0,64,0,MODE_EMA,PRICE_OPEN,10);
//IFT Function
double ITrig=iCustom(NULL,5,"IFT",IHi,ILo,IRsi,IWma,1,1);//current IFT
double PITrig=iCustom(NULL,5,"IFT",IHi,ILo,IRsi,IWma,1,2);//previous IFT
if(C64>C169)
{
if(High[0]>=O64 && Low[0]<=O64) tunn64=True; else tunn64=False;
if(High[0]>=O169 && Low[0]<=O169) tunn169=True; else tunn169=False;
}
if(C64<C169)
{
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(ITrig<ILo && C64>C169) Ltrigger=True; else Ltrigger=False;
if(ITrig>IHi && C64<C169) Strigger=True; else Strigger=False;
if((tunn64==True && Ltrigger==True) || (tunn169==True && Ltrigger==True)) up=True; else up=False;
if((tunn64==True && Strigger==True) || (tunn169==True && Strigger==True)) 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);
}
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);
}
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 && TimeCurrent()>time+300) // long position is open
{
if(ITrig>IHi && ITrig<PITrig)
{
OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Blue);
return(0);
}
}
if(OrderType()==OP_SELL && TimeCurrent()>time+300) // short position is open
{
if(ITrig<ILo && ITrig>PITrig)
{
OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Blue);
return(0);
}
}
}
}
return(0);
}
//+------------------------------------------------------------------+
I gotcha. This is what I have figured out after yesterday....and I will send you the EA in all its "commented out" glory. Those percentages you are trying to bring up? It is all about your exit criteria. I changed to enter on a simple EMA cross - nothing else - with a 50 pip TP and no stop losses. Using the strat tester (which I still don't trust, especially after I look at the chart it produces because it misses a lot), only 1 trade out of 15 was bad, yet my drawdown was never more than 11% in any case I tested. BUT, that leaves you exposed in a way that I would not do on an EA....
So....what that tells me is we are concentrating on the wrong thing. We need to find the criteria that makes us exit at the right time and we will be home free.
I am going to try a couple of things today and really really study a chart for where I would manually exit. Will let you know what I see....
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);
}
//+------------------------------------------------------------------+
Hiya Sherri, just been piddling with my EAs most of the day. Funny how my brain thinks about 12 steps ahead of my coding skills and my, my the tangents I've been on. Been working on a tunnel EA today mostly, with surprisingly decent results. I've modified it about 10 times and it hasn't gotten much better lol.
Where ya been Git??? I told ST I got the SAR added today, and right now, I am finishing up with an MA cross also, so between the three, I think my entries should be refined. Then, the next step is to do some tests on when the indies start reversing so I can take profits before they change too much....
This is just way too much fun!
I'm still just a baby in MT4 terms, the only time stuff I have messed with is the indicators on multiple charts and using the global variables to share info....
BUT, since custom indicators are based upon ticks, I'll bet the time functions would not be that difficult to use.
Sherri have you ever done anything with the Time functions in MT4? For example, on an Heiken Ashi chart lets say you were 4:40 into the current 5 min bar and the price was so far away from the ends of the candle that you could more or less predict what the candle was going to look like before it actually printed. Just a wild thought.
I know....I am still trying to kick this bronchitis...haven't felt like doing much of anything.
OK gang, I have coded probably 5 EAs since starting with MT4 and I keep thinking about HA candles, specifically HA candles with no tails since on an HA chart these signify a strong trend. My idea is to find a candle with no tail and a long body. Here is my code so far, but it doesn't work like I expected it would, some timeframes work great, some pairs work great, but not all. In theory, it should be a perfect trend follower, trading the HA trend similar to a Renko chart...here is the code so far.
I think there is definitely merit to this, but gotta step through the logic first...
//+------------------------------------------------------------------+
//| HA_EA.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
extern double SL=40;//Stop Loss
extern double TP=200;//Take Profit
extern double lots=0.10;
extern int slippage=3;
extern int magicnumber=913;
double scalp=0.75;
double entry;
bool up=False;
bool down=False;
//***************** START **********************
int start()
{
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();
//first determine previous HA candle
double haC=(Open[1]+High[1]+Low[1]+Close[1])/4;
double haO=(Open[1]+Close[1])/2;
double haH=MathMax(High[1],MathMax(haO,haC));
double haL=MathMin(Low[1],MathMin(haO,haC));
//find a candle where there is no upper/lower tail and a body longer than 30
//percent of the candle
if(haL>=haO && MathAbs(haC-haO)>(0.3*MathAbs(haH-haL))) up=True; else up=False;
if(haH<=haO && MathAbs(haC-haO)>(0.3*MathAbs(haH-haL))) down=True; else down=False;
//if(OT==1) Print("CSum = ",CSum, " | PCSum = ",PCSum," || Orders Open = ",OT," Entry Price - ",entry, " Target Price - ",entry+scalp);
if(OT<1) //Are any orders open already?
{
//SHORT ENTRY
if(down==True && IsTradeAllowed()==True)
{
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();
Print("SELL order opened : ",OrderOpenPrice(),"|| Target Price : ",entry-scalp);
}
return(0);
}
//LONG ENTRY
if(up==True && IsTradeAllowed()==True)
{
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();
Print("BUY order opened : ",OrderOpenPrice(),"|| Target Price : ",entry+scalp);
}
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(haL<haO)
{
OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Blue);
return(0);
}
}
if(OrderType()==OP_SELL) // short position is open
{
if(haH>haO)
{
OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Blue);
return(0);
}
}
}
}
return(0);
}
//+-----------------------------------------
LOL Sherri, time to get busy with all the ideas that need to come to fruition.