Dukascopy
 
 
Wiki JStore Search Login

my custom function generates null pointer runtime error and it stops the strategy.
 Post subject: my custom function generates null pointer runtime error and it stops the strategy. Post rating: 0   New post Posted: Tue 29 Oct, 2013, 02:09 
User avatar

User rating: 0
Joined: Mon 23 Sep, 2013, 14:17
Posts: 1
Location: Indonesia, Jakarta
I have successfully convert / compile my EA code using JForex MQL converter.
And it has running good for 1 day... but when I stopped my running EA and I restarted it with some existing positions in the current demo account, it quickly gives me this error :
java.lang.NullPointerException

And it pointed inside one of my custom functions named FindFirstPrice.

Here's the function code in MQL language :


double FindFirstPrice(int MagicNumber, int OP_Type) {
double l_ord_open_price_0;
int l_ticket_8;
double ld_unused_12 = 0;
int l_ticket_20 = 0;
for (int l_pos_24 = 0; l_pos_24 < OrdersTotal(); l_pos_24++) {
OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_Type) {
l_ticket_8 = OrderTicket();
if (l_ticket_8 < l_ticket_20) {
l_ord_open_price_0 = OrderOpenPrice();
l_ticket_20 = l_ticket_8;
}
if(l_ticket_20 == 0) {
l_ord_open_price_0 = OrderOpenPrice();
l_ticket_20 = l_ticket_8;
}
}
}
return (l_ord_open_price_0);
}

I hope you can help point out what went wrong in the code.


 
 Post subject: Re: my custom function generates null pointer runtime error and it stops the strategy. Post rating: 0   New post Posted: Tue 29 Oct, 2013, 20:32 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Hi,

I could probably help if you provide the .mq4 code, and the line number in the java file (within your function) where you have the NPE.
If the EA is confidential, and you are not willing to share it, no problem, I can understand. In that case wait till Support replies.


 
 Post subject: Re: my custom function generates null pointer runtime error and it stops the strategy. Post rating: 0   New post Posted: Mon 04 Nov, 2013, 15:04 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
In JForex platform you can't use trading functions (OrderSelect(), OrderOpenPrice() etc.) in indicators. If you converted your EA as indicator, then that kind of error would happen when trading functions gets executed. If your EA doesn't have any output buffers, then converting and running it as a strategy would probably help, before doing that mind to delete the previously compiled jfx file.


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com