Forex Forum - EarnForex
Serving Traders Since 2005
 

Go Back   Forex Forum - EarnForex > MetaTrader > MetaTrader Expert Advisors

MetaTrader Expert Advisors Post and discuss the MetaTrader expert advisors here.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 16th April 2011, 13:02
Default Avatar
Junior Member
 
Join Date: Mar 2011
Location: china
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default why add position's strategy is fail?

Hi gurus here,my ea couldn't add position correctly,before it run add positon's code, it would close the former order,

//here is my sell condition
if (m1<m3-0.00005)
{
ticket1=OrderSend(Symbol(),OP_SELL,1,Bid,5,Ask+105 0*Point,0,"SELL#1",MAGICMA,0,Red);return;
/*it will open continuously 2 orders under "CalculateCurrentOrders(Symbol())<2" but the add position code (as follow)seems don't take effect */
if(Ask>OrderOpenPrice()+300*Point)
{ticket2=OrderSend(Symbol(),OP_SELL,1,Bid,5,Ask+10 50*Point,0,"SELL#2",MAGICMA,0,Green); return; }
//and the TS() as follow : also only run after close one order under "CalculateCurrentOrders(Symbol())<2"
void TS(double ts=550)
{
bool res = false;
int total = OrdersTotal();
for(int pos = OrdersTotal()-1; pos >= 0 ; pos--)
{
if (OrderSelect(pos, SELECT_BY_POS,MODE_TRADES)
&& OrderMagicNumber() == MAGICMA
&& OrderSymbol() == Symbol() )
{
if(OrderType()==OP_BUY)
{
if(Bid-Point*ts>OrderOpenPrice() &&
Bid-Point*ts>OrderStopLoss())
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*ts,OrderTakeProfit(),0);
}
}
else if(OrderType()==OP_SELL)
{
if(Ask+Point*ts<OrderOpenPrice() &&
Ask+Point*ts<OrderStopLoss())
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Poi nt*ts,OrderTakeProfit(),0);
}
}
}
}
}
and the my TS() function would appear similar state only take effect after close one order.

I guess this error is connect with the cycle control,but I am not sure for it .guys who can help me,appreciating.
Reply With Quote
  #2 (permalink)  
Old 16th April 2011, 21:15
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,542
Thanks: 18
Thanked 20 Times in 16 Posts
Default

Once again, please attach EA as a file or at least use [highlight="MQL5"][/highlight] tags to insert code.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #3 (permalink)  
Old 18th April 2011, 09:58
Default Avatar
Junior Member
 
Join Date: Mar 2011
Location: china
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the whole code is the same as the add.mq4
attchment here are some new parts.
the core question is the open order and TS order couldn't take effects when meets codition,all of them only run after close one order under "CalculateCurrentOrders(Symbol())<2" but under"CalculateCurrentOrders(Symbol())<1" all of them couldn't run at all.
Attached Files
File Type: mq4 q.mq4 (1.6 KB, 4 views)
Reply With Quote
Reply

Bookmarks


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 On


Similar Threads
Thread Thread Starter Forum Replies Last Post
why close order fail and how to limit order n.o.? univetsity MetaTrader Expert Advisors 2 22nd March 2011 10:23
EMA-4-MTF-Strategy Forexcube Trading Systems and Strategies 25 11th December 2009 21:54
The 4/12/63 Strategy bobo1 Trading Systems and Strategies 2 7th July 2009 23:26
Government Rescue Plans Fail To Raise Market's Spirits FXexpert Forex News 0 15th February 2009 16:11
Yen Rises as Stocks Fall on Concern U.S. Rescue Plan Will Fail Enivid Forex News 0 11th February 2009 08:55


All times are GMT. The time now is 03:33.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Inactive Reminders By Icora Web Design

SEO by vBSEO 3.3.2