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.
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 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.
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--) "
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.
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.
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.