Download MetaTrader 5

Noob asking for help. My fisrt script doesn't work

To add comments, please log in or register
landmeister
197
landmeister  

Dear all, I created my first scrpit designed to launch buy orders at a preset TP/SL distances from current price, as well as lots. Unfortunately, it doesn't work. I get error 4109. Any help would be much appreciated. Here you have it.

int start()
{

double lots;
int take_profit,stop_loss;

//----

// Lots
lots=0.5;

// Take Profit
take_profit=2000;

// Stop Loss
stop_loss=4000;

if (Digits==5 || Digits==3)
{
take_profit=take_profit*10;
stop_loss=stop_loss*10;
}

RefreshRates();
OrderSend(Symbol(),OP_BUY,lotes,Ask,3,Ask-stop_loss*Point,Ask+take_profit*Point);
Alert(GetLastError());

//----
return(0);

}

Thank you very much in advance
qjol
3243
qjol  

error 4109 = you have to check "Allow live trading" or enable trading -- CTRL + E



Alain Verleyen
Moderator
32828
Alain Verleyen  
landmeister:
...
Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

landmeister
197
landmeister  
angevoyageur:
Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.


Sorry, Thank you.
landmeister
197
landmeister  
qjol:

error 4109 = you have to check "Allow live trading" or enable trading -- CTRL + E



Maybe I didin't explain myself correctly. It's a script, not an EA. That option is not available for scripts.

Thank you

Alain Verleyen
Moderator
32828
Alain Verleyen  
landmeister:

Maybe I didin't explain myself correctly. It's a script, not an EA. That option is not available for scripts.

Thank you


Of course it's available for script.

Add this line :

#property show_inputs
landmeister
197
landmeister  

I didn't know that. This is why this forum is priceless.

Thank you.

Alain Verleyen
Moderator
32828
Alain Verleyen  
landmeister:

I didn't know that. This is why this forum is priceless.

Thank you.

You are welcome.
landmeister
197
landmeister  

Bad news. The error is still present. Now I can check "Allow live trading" in the script but the order is not launched. Could someone please tell what am I missing?

Thank you in advance.


Edit. Ok. I finally got it. I didn't have the "autotrading" button on. Problem finally solved. Thanx

Keith Watford
Moderator
10646
Keith Watford  
landmeister:

Bad news. The error is still present. Now I can check "Allow live trading" in the script but the order is not launched. Could someone please tell what am I missing?

Thank you in advance.


The variable lotes has not been declared, so the script will not compile. This means that you will be unable to use this script

OrderSend(Symbol(),OP_BUY,lotes,Ask,3,Ask-stop_loss*Point,Ask+take_profit*Point);

I doubt that it us a typo, because I am sure that you copy and paste your code and don't completely re-type it.

The only conclusion is that you are using a different script to the one that you have posted.

Brian
9
Brian  

I'm a bit concerned. I just hit a problem where an automated order did not complete.

Order of events:

I was using build 610 until 4/5/14, and automated trades worked via automated script (not EA)

I restarted MT4 on 4/5/14, and let it upgrade to build 625

I restarted my order script (not EA)

On 4/8/14, it tried to make a trade, and I got error 4109. Now, I'm staring at the screen and the "AutoTrading" button is enabled. The Tools\Expert Advisors tab has "Allow automated trading" enabled, along with the first two options "Disable automated trading when the account has been changed" and "Disable automated trading when the profile has been changed". Again, the AutoTrading button is enabled with the green arrow showing inside that button.

Are there other options that need to be set in build 625 to allow automated trading, or could this be a build 625 bug?

12
To add comments, please log in or register