I wrote a custom indicator and had tested it working.
But when I tried to test it in EA using iCustom, it ALWAYS returned 2147483647!
I saw some article saying that to change the Shift to 1, I tried but still to no avail!
Could somebody be so kind and teach me how to fix it properly, PLEASE!?
Much appreciated!!!
If you post the code of your indicator we would be able to better know why it returns EMPTY_VALUE
Anyway, ensure you pass the correct inputs in the iCustom() call.
Indicator:
//+------------------------------------------------------------------+ //| SDV.mq4 | //| Copyright 2019, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict #property indicator_separate_window //#property indicator_minimum -4 //#property indicator_maximum 4 #property indicator_buffers 2 #property indicator_plots 2 //--- plot SDV #property indicator_label1 "Main" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 #property indicator_label2 "AVG" #property indicator_type2 DRAW_LINE #property indicator_color2 clrLime #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- input parameters input int Avg=5; //--- indicator buffers double MainBuffer[],AVGBuffer[],Sum; int n=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,MainBuffer); SetIndexBuffer(1,AVGBuffer); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- double main,avg,a,b; if(n==0) { Sum=0; for(int i=n-1;i>0;i--) { b=n-i; a=(open[i]+high[i]+low[i]+close[i])/4; Sum+=a; MainBuffer[i]=Sum/b; avg=0; for(int j=0;j<Avg;j++) { if(i+j<n) avg+=MainBuffer[i+j]; } AVGBuffer[i]=avg/Avg; } } else { a=(open[0]+high[0]+low[0]+close[0])/4; double tS=Sum+a; main=tS/n; if(n==rates_total) { MainBuffer[0]=main; avg=0; for(int j=0;j<Avg;j++) { avg+=MainBuffer[j]; } AVGBuffer[0]=avg/Avg; } else { n=rates_total; Sum=tS; ArraySetAsSeries(SDVBuffer,false); ArrayResize(SDVBuffer,n,100000); ArraySetAsSeries(SDVBuffer,true); ArraySetAsSeries(AVGBuffer,false); ArrayResize(AVGBuffer,n,100000); ArraySetAsSeries(AVGBuffer,true); } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Expert Adviser:
//+------------------------------------------------------------------+ //| SDV.mq4 | //| Copyright 2019, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict //--- input parameters input int Avg=5; datetime lastbartime; int ticket,total; double Lots; bool IsBarClosed(int timeframe) { if(iTime(NULL,timeframe,0)==lastbartime) return(false); else { lastbartime=iTime(NULL,timeframe,0); return(true); } } void Short() { Exit(); Lots=AccountBalance()/2000; ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,0,Bid+3000*Point,Bid-10000*Point,"Ichimoku Short",16384,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()); } void Long() { Exit(); Lots=AccountBalance()/2000; ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Ask-3000*Point,Ask+10000*Point,"Ichimoku Long",16384,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } else Print("Error opening SELL order : ",GetLastError()); } void Exit() { for(int i=0;i<total;i++) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()) // check for symbol { //--- long position is opened if(OrderType()==OP_BUY && !OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet)) Print("OrderClose error ",GetLastError()); else if(OrderType()==OP_SELL && !OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet)) Print("OrderClose error ",GetLastError()); } } } //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- if(!IsBarClosed(0)) return; double main=iCustom(NULL,0,"SDV",Avg,0,0); double avg=iCustom(NULL,0,"SDV",Avg,1,0); if(main>avg || avg-main>10) Long(); else if(main<avg || main-avg>10) Short(); } //+------------------------------------------------------------------+
Indicator:
Expert Adviser:
I have seen your issue on the forum. 2147483647 is basically EMPTY_VALUE. This means your custom indicator doesnt have a buffer value for that PERIOD/BAR ...
I have seen your issue on the forum. 2147483647 is basically EMPTY_VALUE. This means your custom indicator doesnt have a buffer value for that PERIOD/BAR ...
Could you PLEASE be so kind and teach me how to fix it!?
Much appreciated!!!
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I wrote a custom indicator and had tested it working.
But when I tried to test it in EA using iCustom, it ALWAYS returned 2147483647!
I saw some article saying that to change the Shift to 1, I tried but still to no avail!
Could somebody be so kind and teach me how to fix it properly, PLEASE!?
Much appreciated!!!