Hi, I'm still learning this stuff. I made this custom indicator to draw arrows. I used WPR for testing and the conditions were red arrow down every time WPR crosses -20 level down. The other cond. is green on crossing -80 upbound. The indicator works and I actually understand what it does. I then made an EA using the same indicator conditions, so whenever I got a red arrow, it should sell and reverse on next opposite signal. When I put them together the EA looks like it has a brain of its own and acts weird. The indicator is working OK in the same chart, however the trigger for opening trades doesn't work the way I intend it to do. Here I attached a portion of the chart where the order was triggered without any reason or the reason was a bounch of bars behind. By the way it was a BUY order.
Bump
Really tough to help without seeing the code for entry, might just be as simple as a "<" facing the wrong way, we have no way to know.
The fact that it does execute orders is a good sign, the usual mistakes have been avoided.
If you don't wish to post your code best that I can suggest is use lots of Print statements and compare the results with what you expect them to be.
HTH
Keith
Really tough to help without seeing the code for entry, might just be as simple as a "<" facing the wrong way, we have no way to know.
The fact that it does execute orders is a good sign, the usual mistakes have been avoided.
If you don't wish to post your code best that I can suggest is use lots of Print statements and compare the results with what you expect them to be.
HTH
Keith
Really tough to help without seeing the code for entry, might just be as simple as a "<" facing the wrong way, we have no way to know.
The fact that it does execute orders is a good sign, the usual mistakes have been avoided.
If you don't wish to post your code best that I can suggest is use lots of Print statements and compare the results with what you expect them to be.
HTH
Keith
I'm sorry I'd though I attached the files to the message. Anyway, I'll use old copy/paste:
//+------------------------------------------------------------------+ //| Arrows_2.mq4 | //| | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, " #property link "" //---------------------------------------------------------------------------------------------- #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Green #property indicator_color2 Red extern int WPR_Period =14; double WPR_1,WPR_0; double CrossUp[]; double CrossDown[]; datetime barTime=0; // global variable //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0, DRAW_ARROW, EMPTY); SetIndexArrow(0, 233); SetIndexBuffer(0, CrossUp); SetIndexStyle(1, DRAW_ARROW, EMPTY); SetIndexArrow(1, 234); SetIndexBuffer(1, CrossDown); //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ int Crossed20 (double value0, double value1) { int current_arrow=0; int last_arrow=0; if(value1>-20 && value0<-20)current_arrow = 2; //down arrow else current_arrow=0; if(current_arrow != last_arrow) //changed { last_arrow = current_arrow; return (last_arrow); } else { return (0); } } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ int Crossed80 (double value0, double value1) { int current_arrow=0; int last_arrow=0; if(value1<-80 && value0>-80)current_arrow = 1; //up arrow else current_arrow=0; if(current_arrow != last_arrow) //changed { last_arrow = current_arrow; return (last_arrow); } else { return (0); } } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- int isCrossed20,isCrossed80; WPR_0 =0 ; WPR_1=0; //---- check for history and trading if( barTime < Time[0] ) { //ONLY get here IF *new bar* // we have a new bar opened barTime = Time[0]; // keep the new bar open time //now we do ALL new bar work... int counted_bars = IndicatorCounted(); int i; int limit; if(counted_bars < 0) return(-1); if(counted_bars > 0) counted_bars--; limit = Bars - counted_bars; for(i=0; i<=limit; i++) { WPR_0 = iWPR(NULL,0,WPR_Period,i); WPR_1 = iWPR(NULL,0,WPR_Period,i+1); if(WPR_1>-20) { isCrossed20 = Crossed20 (WPR_0,WPR_1); if(isCrossed20==2)CrossDown[i]=High[i]+0.0020; } if(WPR_1<-80) { isCrossed80 = Crossed80 (WPR_0,WPR_1); if(isCrossed80==1)CrossUp[i]=Low[i]-0.0020; } } } //---- return(0); } //+------------------------------------------------------------------+
Really tough to help without seeing the code for entry, might just be as simple as a "<" facing the wrong way, we have no way to know.
The fact that it does execute orders is a good sign, the usual mistakes have been avoided.
If you don't wish to post your code best that I can suggest is use lots of Print statements and compare the results with what you expect them to be.
HTH
Keith
And here is the EA:
//+------------------------------------------------------------------+ //| WPR_2.mq4 | //| | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, " #property link "" #define MAGICMA 20090320 extern double Lots = 0.1; extern double Stop = 400; datetime barTime=0; // global variable double WI0,WI1; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ int Crossed20 (double value0, double value1) { int current_arrow=0; int last_arrow=0; if(value1>-20 && value0<-20)current_arrow = 2; //down arrow else current_arrow=0; if(current_arrow != last_arrow) //changed { last_arrow = current_arrow; return (last_arrow); } else { return (0); } } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ int Crossed80 (double value0, double value1) { int current_arrow=0; int last_arrow=0; if(value1<-80 && value0>-80)current_arrow = 1; //up arrow else current_arrow=0; if(current_arrow != last_arrow) //changed { last_arrow = current_arrow; return (last_arrow); } else { return (0); } } //****************************************************************** void OpenShort() { double Stop_Loss=iATR(NULL,0,20,0)*Stop; int ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+Stop_Loss,0,"",MAGICMA,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } else Print("Error opening SELL order : ",GetLastError()); return(0); } //******************************************************************* void OpenLong() { double Stop_Loss=iATR(NULL,0,20,0)*Stop; int ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-Stop_Loss,0,"",MAGICMA,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError()); return(0); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ void NewOpen() { double WI0=iWPR(NULL,0,14,0); double WI1=iWPR(NULL,0,14,1); int isCrossed20,isCrossed80; if(WI1>-20) { isCrossed20 = Crossed20 (WI0,WI1); if(isCrossed20==2) OpenShort(); } if(WI1<-80) { isCrossed80 = Crossed80 (WI0,WI1); if(isCrossed80==1) OpenLong(); } } //+------------------------------------------------------------------+ void Modify() { double WI0=iWPR(NULL,0,14,0); double WI1=iWPR(NULL,0,14,1); int isCrossed20,isCrossed80; for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue; if(WI1>-20) isCrossed20 = Crossed20 (WI0,WI1); if(WI1<-80) isCrossed80 = Crossed80 (WI0,WI1); //---- check order type if(OrderType()==OP_BUY) { if(isCrossed20==2)// closing long orders { OrderClose(OrderTicket(),OrderLots(),Bid,3,White); OpenShort(); break; } } if(OrderType()==OP_SELL) { if(isCrossed80==1)// closing short orders { OrderClose(OrderTicket(),OrderLots(),Ask,3,White); OpenLong(); break; } } } } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { if( barTime < Time[0] ) { int arrow=iCustom(NULL,0,"Arrows",1,0); barTime = Time[0]; // keep the new bar open time if( OrdersTotal() < 1 ) NewOpen(); else Modify(); } //---- return(0); } //+------------------------------------------------------------------+
Dunno, first glance looks ok, I have it running on a 1 hour chart and will watch, in the tester the errors show up. I suspect that the difference is between the indicator values which the EA retrieves and the values that are plotted by the indicator attached to the chart. I think I'll put it on a smaller time frame and let it run and see if the discrepancies occur in real time.
Be in touch.
Keith
PS Performed nicely in Back testing, neatly coded.
EDIT Forget, it dumb idea, just realised that you haven't hard coded the indicator into the ea so there would be the same problem, ea calcs
compared to indicators calcs. I get a minute i'll insert the indicator into the ea and see what happens.
Dunno, first glance looks ok, I have it running on a 1 hour chart and will watch, in the tester the errors show up. I suspect that the difference is between the indicator values which the EA retrieves and the values that are plotted by the indicator attached to the chart. I think I'll put it on a smaller time frame and let it run and see if the discrepancies occur in real time.
Be in touch.
Keith
PS Performed nicely in Back testing, neatly coded.
EDIT Forget, it dumb idea, just realised that you haven't hard coded the indicator into the ea so there would be the same problem, ea calcs
compared to indicators calcs. I get a minute i'll insert the indicator into the ea and see what happens.
Thank you Keith, waiting for your testing results. I checked the logs to see if there was any OrderSend errors, but there wasn't any. What really intrigues me is that oviously when the indicator draws an arrow, means there was a signal trigger. However the EA didn't carry on. In the same time stamp for where the arrows shows there is nothing from the ea side, no even an error in execution of the trade. In the meanwhile I'll keep banging my head against the wall :(
BTW I really appreciated your help.
Thank you Keith, waiting for your testing results. I checked the logs to see if there was any OrderSend errors, but there wasn't any. What really intrigues me is that oviously when the indicator draws an arrow, means there was a signal trigger. However the EA didn't carry on. In the same time stamp for where the arrows shows there is nothing from the ea side, no even an error in execution of the trade. In the meanwhile I'll keep banging my head against the wall :(
BTW I really appreciated your help.
Not getting anywhere fast, adding the indicator to the Ea is a lot harder than I thought, still blundering through that learning curve.
I still think that the issue is that the display of the indicator is drifting off of the data used by the ea.
When I follow through the backtesting it seems ok at first and gradually gets worse, I suspect that they start out at the same point in the data
history and drift apart.
I'll keep trying to insert the indicator into the ea, it's a skill set I need to master sooner or later might as well be now.
cheers
Keith
Not getting anywhere fast, adding the indicator to the Ea is a lot harder than I thought, still blundering through that learning curve.
I still think that the issue is that the display of the indicator is drifting off of the data used by the ea.
When I follow through the backtesting it seems ok at first and gradually gets worse, I suspect that they start out at the same point in the data
history and drift apart.
I'll keep trying to insert the indicator into the ea, it's a skill set I need to master sooner or later might as well be now.
cheers
Keith
Yep, samething with my data, only first order gets right . From that point on everything gets off,I mean way off. I'm completly clueless.
Thank you

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, I'm still learning this stuff. I made this custom indicator to draw arrows. I used WPR for testing and the conditions were red arrow down every time WPR crosses -20 level down. The other cond. is green on crossing -80 upbound. The indicator works and I actually understand what it does. I then made an EA using the same indicator conditions, so whenever I got a red arrow, it should sell and reverse on next opposite signal. When I put them together the EA looks like it has a brain of its own and acts weird. The indicator is working OK in the same chart, however the trigger for opening trades doesn't work the way I intend it to do. Here I attached a portion of the chart where the order was triggered without any reason or the reason was a bounch of bars behind. By the way it was a BUY order.