Forex
Google
New signals service!

Go Back   Forex Trading > Programming > Metatrader Programming


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack (1) Thread Tools Display Modes
  #51 (permalink)  
Old 04-09-2006, 02:45 PM
Senior Member
 
Join Date: Dec 2005
Posts: 217
eric79 is on a distinguished road
Thank you very much, i will try it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #52 (permalink)  
Old 04-10-2006, 05:13 AM
FX5 FX5 is offline
Junior Member
 
Join Date: Oct 2005
Posts: 13
FX5 is on a distinguished road
Question Error Code: 4109

Hello Everybody:

I wrote a script to close all trades including the pending orders, but was disapointed after testing it. The functions: OrderClose, and Orderdelete fail in closing the trades. By calling the GetLastError function I get the error code: 4109 which is defined in the error header file as TRADE_NOT_ALLOWED.

I even tried to execute those scripts which come with the platform but with no success.

I hope someone can solve the problem.

Thanks,
Attached Files
File Type: mq4 CloseAll2.mq4 (2.0 KB, 26 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #53 (permalink)  
Old 04-10-2006, 05:47 AM
firedave's Avatar
Senior Member
 
Join Date: Nov 2005
Location: Jakarta, Indonesia
Posts: 416
firedave is on a distinguished road
Okay, try this one. I think Lots and Price variable should be double not integer. Hope this help

Code:
//+------------------------------------------------------------------+
//|                                                     CloseAll.mq4 |
//|                                                     FX5          |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "FX5"
#property link      " "

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
      int Ticket,Lots,Price,Type,Result;
      int Error=0;
      int Total=OrdersTotal();
      for(int i=0;i<Total;i++)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==0)
         {
            Alert("Can''t select the order indexed: ",i);
            Alert("Error code is ", GetLastError());
            Error++;
         }
         else
         {
/*            Lots=OrderLots();
            Ticket=OrderTicket();
            Type=OrderType();*/
            Result=0;
/*            if(Type==OP_BUY)
               Price=Bid;
            if(Type==OP_SELL)
               Price=Ask;*/
//            if(Type==OP_BUY || Type==OP_SELL)
            if(OrderType()<=OP_SELL)
            {
               Alert(OP_BUY,"  ",OP_SELL,"  ",Type);
//               Result=OrderClose(Ticket,Lots,Price,5,Blue);
               if(OrderType()==OP_BUY)  Result=OrderClose(OrderTicket(),OrderLots(),Bid,5,Blue);
               if(OrderType()==OP_SELL) Result=OrderClose(OrderTicket(),OrderLots(),Ask,5,Blue);
            }
            else
            {
               Result=OrderDelete(OrderTicket());
            }
            if(Result==0)
            {
               Alert("Can''t close the Order number: ",i," with Ticket:  ",Ticket);
               Alert("Error Code:  ",GetLastError());
               Error++;
            }
         }
      }
   if(Error!=0)
      Alert(Error,"   Errors have occured");
   else
      Alert("Close all Orders Succeeded with no Errors");
//----
   return(0);
  }
//+------------------------------------------------------------------+
__________________
David Michael H
"Trader helps traders with sincerity, honesty and integrity"

Last edited by firedave; 04-10-2006 at 05:50 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #54 (permalink)  
Old 04-10-2006, 06:11 AM
Member
 
Join Date: Mar 2006
Posts: 40
crepuscular is on a distinguished road
try this

Quote:
Originally Posted by FX5
Hello Everybody:

I wrote a script to close all trades including the pending orders, but was disapointed after testing it. The functions: OrderClose, and Orderdelete fail in closing the trades. By calling the GetLastError function I get the error code: 4109 which is defined in the error header file as TRADE_NOT_ALLOWED.

I even tried to execute those scripts which come with the platform but with no success.

I hope someone can solve the problem.

Thanks,
In metatrader, go to tools -> options, click the expert advisor tab and select allow live trading, and click the allow dll imports, and uncheck confirm calls. I wrote a few scripts and was having the same problem.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #55 (permalink)  
Old 04-10-2006, 12:50 PM
Senior Member
 
Join Date: Feb 2006
Posts: 559
Michel is on a distinguished road
Quote:
Originally Posted by firedave
Okay, try this one. I think Lots and Price variable should be double not integer. Hope this help

Code:
//+------------------------------------------------------------------+
//|                                                     CloseAll.mq4 |
//|                                                     FX5          |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "FX5"
#property link      " "

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
      int Ticket,Lots,Price,Type,Result;
      int Error=0;
      int Total=OrdersTotal();
      for(int i=0;i<Total;i++)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==0)
         {
            Alert("Can''t select the order indexed: ",i);
            Alert("Error code is ", GetLastError());
            Error++;
         }
         else
         {
/*            Lots=OrderLots();
            Ticket=OrderTicket();
            Type=OrderType();*/
            Result=0;
/*            if(Type==OP_BUY)
               Price=Bid;
            if(Type==OP_SELL)
               Price=Ask;*/
//            if(Type==OP_BUY || Type==OP_SELL)
            if(OrderType()<=OP_SELL)
            {
               Alert(OP_BUY,"  ",OP_SELL,"  ",Type);
//               Result=OrderClose(Ticket,Lots,Price,5,Blue);
               if(OrderType()==OP_BUY)  Result=OrderClose(OrderTicket(),OrderLots(),Bid,5,Blue);
               if(OrderType()==OP_SELL) Result=OrderClose(OrderTicket(),OrderLots(),Ask,5,Blue);
            }
            else
            {
               Result=OrderDelete(OrderTicket());
            }
            if(Result==0)
            {
               Alert("Can''t close the Order number: ",i," with Ticket:  ",Ticket);
               Alert("Error Code:  ",GetLastError());
               Error++;
            }
         }
      }
   if(Error!=0)
      Alert(Error,"   Errors have occured");
   else
      Alert("Close all Orders Succeeded with no Errors");
//----
   return(0);
  }
//+------------------------------------------------------------------+
This may be wrong : to delete multiple orders, you must begin from the last one as their indexes are decrementing following the deleting process.
So, in place of " for(int i=0;i<Total;i++) ", use " for(int i=Total-1;i>=0;i--) "
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #56 (permalink)  
Old 04-10-2006, 12:56 PM
FX5 FX5 is offline
Junior Member
 
Join Date: Oct 2005
Posts: 13
FX5 is on a distinguished road
Thanks firedave for the code modification. It was a small bug which I didn't pay attention to.

Crepuscular, thank you so much for hint. I could have spent a century before figuring out the solution. Finally, I have a working code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #57 (permalink)  
Old 04-10-2006, 01:04 PM
FX5 FX5 is offline
Junior Member
 
Join Date: Oct 2005
Posts: 13
FX5 is on a distinguished road
Michel, that was a very clever note, thank you very much.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #58 (permalink)  
Old 04-11-2006, 08:45 PM
Junior Member
 
Join Date: Dec 2005
Posts: 3
harriss is on a distinguished road
get max drawdown function

i would like to write a function which gets the max drawdown from trade that have been closed. i have come up with two solutions.

1. calculate the drawdown while the trade is still active. saving the number to a global variable and writing the data to file according to ticket number. MT4 would always have to be online.

2. get the drawdown by geting the highest high or lowest low from the 1 min chart. the problem here is we have to have the 1 min history for the trade. (i would use this method if i could get the 1 min bars neccessary if they werent already downloaded)

I would like to come up with a nicer way of getting max drawdown.

Any input is appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #59 (permalink)  
Old 04-11-2006, 10:11 PM
Mohammed's Avatar
Senior Member
 
Join Date: Mar 2006
Posts: 119
Mohammed is on a distinguished road
Question

Quote:
Originally Posted by harriss
i would like to write a function which gets the max drawdown from trade that have been closed. i have come up with two solutions.

1. calculate the drawdown while the trade is still active. saving the number to a global variable and writing the data to file according to ticket number. MT4 would always have to be online.

2. get the drawdown by geting the highest high or lowest low from the 1 min chart. the problem here is we have to have the 1 min history for the trade. (i would use this method if i could get the 1 min bars neccessary if they werent already downloaded)

I would like to come up with a nicer way of getting max drawdown.

Any input is appreciated.
Salam harriss,

What did you mean by "drawdown"?
Do you mean the maximum lose one of closed trades has been made?
__________________
There is a fine line between freedom of expression and hate literature.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #60 (permalink)  
Old 04-12-2006, 12:57 AM
Junior Member
 
Join Date: Dec 2005
Posts: 3
harriss is on a distinguished road
drawdown

What i mean by drawdown is, what is the lowest point in the trade. For example, if the trade hit the stoploss, then the stoploss would be the drawdown. Now if the trade ended up on the positive side and was -15 pips at one point then the drawdown would be 15. Lastly, if the trade close at -15 pips but was -30 at one point then the drawdown would be 30.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
candle time, CHinGsMAroonCLK, coders guru, expert advisor, forex, how to code, I_XO_A_H, mechanical trading, trading

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

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-programming/554-how-code.html
Posted By For Type Date
Need an experienced programmer? - Page 2 Post #0 Refback 09-24-2008 07:24 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code this? iscuba11 Metatrader 4 mql 4 - Development course 1 08-03-2007 05:22 PM


All times are GMT. The time now is 12:09 PM.



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