View Single Post
  #2 (permalink)  
Old 11-28-2005, 11:46 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
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, 41 views)
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Reply With Quote