Forex



Go Back   Forex Trading > Training > Metatrader > Metatrader 4 mql 4 - Development course > Questions
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 11-28-2005, 10:34 PM
Junior Member
 
Join Date: Nov 2005
Posts: 17
TheExponential is on a distinguished road
OrderSend error with OP_SELLSTOP and OP_BUYSTOP

Hi there,

I have a problem with issuing OP_SELLSTOP/OP_BUYSTOP.

For example, I ran a script on EURUSD 1 Hourly:
MyPrice = High[1] + (iATR(Symbol(),0,6,1)*1.5);
Ticket=OrderSend(Symbol(), OP_BUYSTOP, Lots, MyPrice,3, Low[1], 0,"BUYSTOP",0,0,Green);

MyPrice returns 1.16925750.

It gives me an error "2005.11.28 22:00:06 EURUSD,H1: invalid price 1.16925750 for OrderSend function". It is associated with error code: 4107.

So, I thought it was because of the rounding off issue. Hence, I replaced MyPrice with:
MyPrice = High[1] + NormalizeDouble(((iATR(Symbol(),0,6,1)*1.5),4);
Ticket=OrderSend(Symbol(), OP_BUYSTOP, Lots, MyPrice,3, Low[1], 0,"BUYSTOP",0,0,Green);

Now, I get "OrderSend BUYSTOP failed with error #4109" (ERR_TRADE_NOT_ALLOWED).


Even if I hardcoded the price like so, it still returns me #4109 error. Can anyone do me a favour and execute this, and tell me if it works?:
OrderSend("EURUSD", OP_BUYSTOP, 1, 1.1900, 3, Low[1], 0,"BUYSTOP",0,0,Green);


Has anyone got a successful OP_BUYSTOP/SELLSTOP sample? What does the above error really mean 4107 and 4109?

Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 11-29-2005, 12:46 AM
codersguru's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 994
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Arrow It works!

Quote:
Originally Posted by TheExponential
Hi there,

I have a problem with issuing OP_SELLSTOP/OP_BUYSTOP.

For example, I ran a script on EURUSD 1 Hourly:
MyPrice = High[1] + (iATR(Symbol(),0,6,1)*1.5);
Ticket=OrderSend(Symbol(), OP_BUYSTOP, Lots, MyPrice,3, Low[1], 0,"BUYSTOP",0,0,Green);

MyPrice returns 1.16925750.

It gives me an error "2005.11.28 22:00:06 EURUSD,H1: invalid price 1.16925750 for OrderSend function". It is associated with error code: 4107.

So, I thought it was because of the rounding off issue. Hence, I replaced MyPrice with:
MyPrice = High[1] + NormalizeDouble(((iATR(Symbol(),0,6,1)*1.5),4);
Ticket=OrderSend(Symbol(), OP_BUYSTOP, Lots, MyPrice,3, Low[1], 0,"BUYSTOP",0,0,Green);

Now, I get "OrderSend BUYSTOP failed with error #4109" (ERR_TRADE_NOT_ALLOWED).


Even if I hardcoded the price like so, it still returns me #4109 error. Can anyone do me a favour and execute this, and tell me if it works?:
OrderSend("EURUSD", OP_BUYSTOP, 1, 1.1900, 3, Low[1], 0,"BUYSTOP",0,0,Green);


Has anyone got a successful OP_BUYSTOP/SELLSTOP sample? What does the above error really mean 4107 and 4109?

Thanks!
TheExponential,

Your code worked for me, I don't know what's the problem with your platform (I'm using MT4 Build 186).

This is the code I used:

PHP Code:
//+------------------------------------------------------------------+
//|                                                  My_First_EA.mq4 |
//|                                                      Coders Guru |
//|                                         http://www.forex-tsd.com |
//+------------------------------------------------------------------+
#property copyright "Coders Guru"
#property link      "http://www.forex-tsd.com"


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   
//----
   
return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   
return(0);
  }


//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

   
   
int total  OrdersTotal(); 
   if(
total 1
     {
            
double MyPrice High[1] + NormalizeDouble((iATR(Symbol(),0,6,1)*1.5),4);
            
double ticket=OrderSend(Symbol(), OP_BUYSTOP0.1MyPrice,3Low[1], 0,"BUYSTOP",0,0,Green);
       }
   return(
0);
  }
//+------------------------------------------------------------------+ 
Please see the attached Strategy Tester Report and the screen shot of a pending order in live trade.

2- I didn't get those errors:
4107 means "invalid price parameter for trade function"
4109 means "trade is not allowed"
Attached Files
File Type: zip Report and Screen shot.zip (60.1 KB, 61 views)
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 11-29-2005, 01:23 AM
Junior Member
 
Join Date: Nov 2005
Posts: 17
TheExponential is on a distinguished road
Thanks CodesGuru. That actually works as an EA on the same MT4 build as yours.

But I want to challenge you more, because the following does not work for me as a script (instead of EA). I think we have a bug!. Would you mind testing it for me.

Code:
int Ticket=OrderSend(Symbol(), OP_BUYSTOP, 1, (High[1]+0.0020), 3, (Low[1]-0.0020), 0,"BuyStop",0,0,Green);
if(Ticket<0) string MsgText = "OrderSend BUYSTOP failed with error #" + GetLastError();
Print(Symbol()+", "+(High[1]+0.0020) + ", " + (Low[1]-0.0020) + ", " +MsgText);
Do you think I need to put "NormalizeDouble" to make it work? Have you tried it without the "NormalizeDouble" in EA, and did you get 4107 error code?

If you do get 4107 error (Invalid Price), do you think it's because the MyPrice results in more than FOUR decimal places?

Thanks once again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 02-16-2006, 05:49 AM
Junior Member
 
Join Date: Feb 2006
Posts: 1
Bear142746 is on a distinguished road
TheExponential,

Did you ever get this resolved. I'm having the same problem when building a "script" to close/open positions on a "single click". If I run it as an expert, it runs fine and will close all open positions. If I run it as a script, it fails with your error. I do know that it's tied to not being allowed to run live trades from a script, but wondered if you found a way to force an allow of live trades. (the Trader script that comes with MT4 won't even work due to the same error.

Bear
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 03-01-2006, 07:48 AM
Shahin's Avatar
Junior Member
 
Join Date: Oct 2005
Posts: 21
Shahin is on a distinguished road
Yes in fact it is true that:
Anytime the price is bigger than number of decimal digits used for the pair, you need to normalizedouble to the correct number of digits.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #6 (permalink)  
Old 04-07-2006, 05:17 AM
BC Brett's Avatar
Member
 
Join Date: Mar 2006
Location: Vancouver, British Columbia
Posts: 33
BC Brett is on a distinguished road
deleted

deleted message

Last edited by BC Brett; 04-07-2006 at 09:12 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #7 (permalink)  
Old 04-07-2006, 09:09 AM
Member
 
Join Date: Mar 2006
Posts: 58
pengie is on a distinguished road
Your volume is too high. If you want 100000, which is 1 lot, just use 1 for your volume.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
ordersend error 4107, ordersend, OrderSend error 4109, OP_SELLSTOP, mql4 error 4107, OrderSend failed with error #4109, error 4107, OP_BUYSTOP, ordersend error 3, Error 4109, ERR_TRADE_NOT_ALLOWED, mt4 ordersend, ordersend op_buystop


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
OrderSend problem Hartadi Expert Advisors - Metatrader 4 10 04-11-2007 02:12 PM
OrderSend and stops Pertti Questions 2 03-12-2007 06:47 AM
EA -- OrderSend issue SaxMan Metatrader 4 2 02-23-2007 04:00 AM
OrderSend question knili Metatrader 4 5 10-03-2006 01:16 AM
OrderSend at a certain time martin80 Metatrader 4 4 09-18-2006 01:47 PM


All times are GMT. The time now is 04:08 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.