- MetaEditor - Professional editor of trading applications
- How to Become a Seller - Market App Store
- Lists of Objects Applied - Additional Features - Price Charts, Technical and Fundamental Analysis
- We have no idea whether you mean code or an actual script.
- Perhaps you should read the manual.
Constant Value Description REASON_PROGRAM 0 Expert Advisor terminated its operation by calling the ExpertRemove() function - What part of "called … function" is unclear to you?
Hi, I'm trying to initialize my script but it is failed with an error message that it was uninitialized with a reason 0. I looked into the documentation and find the description doesn't tell me anything about the problem. Someone know how to fix this?
You are reading something wrong.
A script cannot un-initialize before it is initialized.
A script is loaded, then initialized, executed and then removed from the chart ( with "Uninit reason 0").
- We have no idea whether you mean code or an actual script.
- Perhaps you should read the manual.
- What part of "called … function" is unclear to you?
A Script, I'm trying to run in a script before run it as an EA. I have read the documentation but it doesn't tell me anything why that's happened, that's the part where I'm unclear.
You are reading something wrong.
A script cannot un-initialize before it is initialized.
A script is loaded, then initialized, executed and then removed from the chart ( with "Uninit reason 0").
0 08:20:21.469 Script Test USDCHF,H1: loaded successfully 0 08:20:21.485 Test USDCHF,H1: initialized 0 08:20:21.486 Test USDCHF,H1: Alert: 0 08:20:21.486 Test USDCHF,H1: uninit reason 0 0 08:20:21.525 Script Test USDCHF,H1: removed
That's the log.
void OnStart() { Alert(""); double bbUpperBand2 = iBands(NULL,0,20,4,0,PRICE_CLOSE,MODE_UPPER,0); double bbUpperBand = iBands(NULL,0,20,1,0,PRICE_CLOSE,MODE_UPPER,0); double bbMidBand = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_MAIN,0); double bbLowerBand = iBands(NULL,0,20,1,0,PRICE_CLOSE,MODE_LOWER,0); double bbLowerBand2 = iBands(NULL,0,20,4,0,PRICE_CLOSE,MODE_LOWER,0); //Alert(MarketInfo(NULL, MODE_STOPLEVEL)); //check minimum stop level if(Ask < bbLowerBand){//Buying Alert("Price is below bbLowerBand, sending buy order"); double stopLossPrice = bbLowerBand2; double takeProfitPrice = bbMidBand; Alert("Entry price = " + Ask); Alert("Stop loss price = " + NormalizeDouble(stopLossPrice,Digits)); Alert("Take profit price = " + NormalizeDouble(takeProfitPrice,Digits)); //syntax for calculate optimal lot size double lotSize = OptimalLotSize(0.02,Ask,stopLossPrice); Alert("Optimal Lot Size: " + lotSize); //syntax for buy order int orderID = OrderSend(NULL,OP_BUYLIMIT,lotSize,Ask,1,stopLossPrice,takeProfitPrice); //syntax to check if EA working properly or not and give message to user if (orderID < 0){ Alert("Order Rejected, error code: " + GetLastError()); }else{ Alert("Order Accepted"); } }else if (Bid > bbUpperBand){//Shorting Alert("Price is above bbUpperBand, sending short order"); double stopLossPrice = bbUpperBand2; double takeProfitPrice = bbMidBand; Alert("Entry price = " + Bid); Alert("Stop loss price = " + NormalizeDouble(stopLossPrice,Digits)); Alert("Take profit price = " + NormalizeDouble(takeProfitPrice,Digits)); double lotSize = OptimalLotSize(0.02,Bid,stopLossPrice); Alert("Optimal Lot Size: " + lotSize); int orderID = OrderSend(NULL,OP_SELLLIMIT,lotSize,Bid,1,stopLossPrice,takeProfitPrice); if (orderID < 0){ Alert("Order Rejected, error code: " + GetLastError()); }else{ Alert("Order Accepted"); } } }
That's my code. The script only run the first alert that has no text. and the rest is not initialized at all.
That's my code. The script only run the first alert that has no text. and the rest is not initialized at all.
Please post code that compiles.
double lotSize = OptimalLotSize(0.02,Ask,stopLossPrice);
You have 2 conditions
if(Ask < bbLowerBand)
{}
and
else if (Bid > bbUpperBand) {}
If neither is true, you will get nothing else but the first alert executed.
okay now I really now what's wrong. It's not the code that is not working. The broker set a minimum stop loss of 40 pips. When I'm running the code for short time frame such as H1 below, the condition (stop loss to take profit less than 40 pips) cannot be meet that's why the system rejected the script. Thanks for the help @Keith Watford
The system did not reject the script.
Conditions were not right for the code to be executed.
Start began. It Alerted. It returned and script exited (0);
Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
okay now I really now what's wrong. It's not the code that is not working. The broker set a minimum stop loss of 40 pips. When I'm running the code for short time frame such as H1 below, the condition (stop loss to take profit less than 40 pips) cannot be meet that's why the system rejected the script. Thanks for the help @Keith Watford
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use