How to use iMaOnArray function in EA system?

 

I have written my own indicator. It uses iMaOnArray function and works properly.

When I transform it into an EA system and run testing, everything seems fine except no trades occur. And no error was reported.

I looked through the forum and saw many EA systems. Nearly none uses iMaOnArray function. I wonder if this is the problem: iMaOnArray is not allowed in EA system; it's only fit for writing indicators?

Suggestions are welcome! Thanks!

 

Thanks stringo!

I tried iCustom function and it seems that the struction of the EA has passed the testing. And new problem occur. In the indicator window, the calculated value are correct. But the values I take from the indicator by iCustom are all changed to 2147483647. So certainly there's no trading signal. This is really annoying. Has anybody met this problem before?

 
Use search engine - https://www.mql5.com/en/search
 
Thanks, Rosh! Problem resolved. it seemed the limitation of the bars volumn of the iMa function caused the problem.
 
Rosh wrote >>
Use search engine - https://www.mql5.com/en/search

Hi,

I've been trawling the forum for the number 2147483647 too.

I also have a custom indicator (20 bar high/low entry/exit) which displays fine on screen, but when called, always returns this number - for all 4 of the indicators

None of the articles I've read (& they go back to 2007) actually explain what the solution is.

See Indicator & Expert code below.

The 4 calls to iCustom, always result in the variables EntryLong, EntryShort, ExitLong, ExitShort being set to 2147483647

..even if I set the test start date to only the start of this month.

Any pointers greatly appreciated.

**************** INDICATOR *********************

#property copyright "David Ford"
#property link ""

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Lime
#property indicator_color2 Lime
#property indicator_color3 Red
#property indicator_color4 Red
//---- input parameters
extern int EntryBreakoutBars=22;
extern int ExitBreakoutBars=15;
extern int ATRBars=39;
extern double EntryOffset=-0.4;
extern double ExitOffset=0;

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];

int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3,ExtMapBuffer4);
return(0);
}
int deinit()
{
return(0);
}
int start()
{
int fixed_bars=IndicatorCounted();

double EntryLong=0, EntryShort=0, ExitLong=0, ExitShort=0;
double EntryOffsetAmt=0, ExitOffsetAmt=0;

for(int shift=1;shift< Bars;shift++)
{
EntryLong=Close[Highest(NULL,0,MODE_CLOSE,EntryBreakoutBars,shift)];
EntryShort=Close[Lowest(NULL,0,MODE_CLOSE,EntryBreakoutBars,shift)];
ExitLong=Close[Lowest(NULL,0,MODE_CLOSE,ExitBreakoutBars,shift)];
ExitShort=Close[Highest(NULL,0,MODE_CLOSE,ExitBreakoutBars,shift)];

EntryOffsetAmt = EntryOffset*iATR(NULL,0,ATRBars,shift);
ExitOffsetAmt = ExitOffset*iATR(NULL,0,ATRBars,shift);

ExtMapBuffer1[shift]=EntryLong+EntryOffsetAmt;
ExtMapBuffer2[shift]=EntryShort-EntryOffsetAmt;
ExtMapBuffer3[shift]=ExitLong+ExitOffsetAmt;
ExtMapBuffer4[shift]=ExitShort+ExitOffsetAmt;
}
return(0);
}

*********************** EXPERT ************************************

#property copyright "David Ford"
#property link ""

//---- input parameters
extern int ExtParam1;
int init()
{
return(0);
}
int deinit()
{
return(0);
}
int start()
{
double MacdCurrent, ATRCurrent, EntryLong, EntryShort, ExitLong, ExitShort;
int i, total, iOrderTicket;
bool OpenPosition;

if(Bars<300)
{
Print("bars less than 300");
return(0);
}

MacdCurrent=iMACD(NULL,PERIOD_H1,70,290,9,PRICE_TYPICAL,MODE_MAIN,0);
ATRCurrent = iATR(NULL, PERIOD_H1, 39,0);
i = 0;
OpenPosition = FALSE;


//Get our current entry/exit conditions for use in orders/stops
EntryLong = iCustom(Symbol(), PERIOD_H1, "FORDChannel1", 22, 15, 39, -0.4, 0, 1,0);
ExitLong = iCustom(Symbol(), PERIOD_H1, "FORDChannel1", 22, 15, 39, -0.4, 0, 3,0);
EntryShort = iCustom(Symbol(), PERIOD_H1, "FORDChannel1", 22, 15, 39, -0.4, 0, 2,0);
ExitShort = iCustom(Symbol(), PERIOD_H1, "FORDChannel1", 22, 15, 39, -0.4, 0, 4,0);

//Go through our positions/orders and adjust/delete as necessary
total = OrdersTotal();
if (total>0)
for(i = 0; i <= total; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
iOrderTicket = OrderTicket();

//Are we currently long or short - if so, just adjust our existing stops
if (OrderType() == OP_BUY)
OrderModify(iOrderTicket, NULL, ExitLong, NULL, NULL, CLR_NONE);
if (OrderType() == OP_SELL)
OrderModify(iOrderTicket, NULL, ExitShort, NULL, NULL, CLR_NONE);

//Adjust our entry orders if we have any
if (OrderType()== OP_BUYSTOP)
if (MacdCurrent>0 )
OrderModify(iOrderTicket, EntryLong, ExitLong,NULL,NULL,CLR_NONE);
else
OrderDelete(iOrderTicket);
if (OrderType()== OP_SELLSTOP)
if (MacdCurrent<0 )
OrderModify(iOrderTicket, EntryShort, ExitShort,NULL,NULL,CLR_NONE);
else
OrderDelete(iOrderTicket);

}

//Now check if we still have any orders, if not, we may want to enter new ones.
if (OrdersTotal()==0)
{
if (MacdCurrent>0) //Enter a long position on Stop
{
OrderSend(Symbol(), OP_BUYSTOP, 1, EntryLong, 0, ExitLong, 0); //, "Buy",16384,0,Green);
if (GetLastError()!=0)
{
Alert(GetLastError(), " : ", MarketInfo(Symbol(),MODE_ASK), " : ", EntryLong, " : ",ExitLong);
}
}
else //Enter a short position on Stop
{
OrderSend(Symbol(), OP_SELLSTOP, 1, EntryShort, 0, ExitShort, 0); //, "SELL",8192,0,Red);
if (GetLastError()!=0)
{
Alert(GetLastError(), " : ", MarketInfo(Symbol(),MODE_BID), " : ", EntryShort, " : ",ExitShort);
}
}
}


return(0);
}

Reason: