Forex
Google
New signals service!

Go Back   Forex Trading > Discussion Areas > Metatrader 4


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 Thread Tools Display Modes
  #1 (permalink)  
Old 07-02-2006, 10:12 PM
Junior Member
 
Join Date: Jun 2006
Posts: 23
DaytrSuccess is on a distinguished road
need help coding a simple trailing stop

hello,

I am a newbie for this.

I tried to code a simple trailing stop but something is wrong.
When I compile the result is : unbalenced parenthesis (at the end.)

Please tell me the mistake(s) and if you are kind enough to explain : use simple words I am not a native english speaker.

Thank you.

Here is rhe code :
-----------------------------------
int start()
{
int cnt, totalOrders;
totalOrders = OrdersTotal();

if (totalOrders>0) // open orders identified
{
for (cnt=1;cnt<totalOrders;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if ((OrderType() == OP_BUY) && ((Bid-OrderOpenPrice())>TrailingStop))
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify((OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),YellowGreen);
return(0);
}
}
else ((OrderType() == OP_SELL) && (OrderOpenPrice()-Ask)>(TrailingStop))
{
if ((OrderStopLoss()>Ask+TrailingStop*Point) ||(OrderStopLoss()=0))
{
OrderModify((OrderTicket),OrderOpenPrice(),Ask+Tra ilingStop*Point,OrderTakeProfit(),Red);
return (0);
}
}
}
}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-02-2006, 11:31 PM
firedave's Avatar
Senior Member
 
Join Date: Nov 2005
Location: Jakarta, Indonesia
Posts: 416
firedave is on a distinguished road
Try this :

PHP Code:
int start()
{
int cnttotalOrders;
totalOrders OrdersTotal();

if (
totalOrders>0// open orders identified
{
for (
cnt=1;cnt<totalOrders;cnt++)
{
OrderSelect(cntSELECT_BY_POSMODE_TRADES);
if ((
OrderType() == OP_BUY) && ((Bid-OrderOpenPrice())>TrailingStop))
{
if(
OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),YellowGreen); 
return(
0);
}
}
else ((
OrderType() == OP_SELL) && (OrderOpenPrice()-Ask)>(TrailingStop))

if ((
OrderStopLoss()>Ask+TrailingStop*Point) || (OrderStopLoss()=0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Tra ilingStop*Point,OrderTakeProfit(),Red);
return (
0);
}
}
}
}

Hope this help
__________________
David Michael H
"Trader helps traders with sincerity, honesty and integrity"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-03-2006, 02:34 PM
Junior Member
 
Join Date: Jun 2006
Posts: 23
DaytrSuccess is on a distinguished road
hello Firedave,

thank you for your answer.

I tried it, but still the same problem : unbalenced parenthesis
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-03-2006, 02:39 PM
elihayun's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 350
elihayun is on a distinguished road
Quote:
Originally Posted by DaytrSuccess
hello Firedave,

thank you for your answer.

I tried it, but still the same problem : unbalenced parenthesis
why not u count the left parenthesis and right parenthesis to see if they match.

OrderModify((OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),YellowGreen);

It can't be more simple than that
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-03-2006, 06:08 PM
Junior Member
 
Join Date: Jun 2006
Posts: 23
DaytrSuccess is on a distinguished road
Smile Help : someone must have the solution.

Quote:
Originally Posted by elihayun
why not u count the left parenthesis and right parenthesis to see if they match.

OrderModify((OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),YellowGreen);

It can't be more simple than that
hello Elihayon,

Thank you for your answer.

Did you count my parenthesis ? I suppose you didn't. They match.

The last line is the problem according to the compiler. I wrote : "at the end"

I tried a lot of things about those parenthesis. When the compiler finds nothing else he states : "unbalanced parenthesis..." at the last caracter !! where nothing is written.

If someone has an idea please help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 07-03-2006, 06:21 PM
elihayun's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 350
elihayun is on a distinguished road
Quote:
Originally Posted by DaytrSuccess
hello Elihayon,

Thank you for your answer.

Did you count my parenthesis ? I suppose you didn't. They match.

The last line is the problem according to the compiler. I wrote : "at the end"

I tried a lot of things about those parenthesis. When the compiler finds nothing else he states : "unbalanced parenthesis..." at the last caracter !! where nothing is written.

If someone has an idea please help.
Well, I DID count them
look
OrderModify((OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),YellowGreen);

U have 2 (( after OrderModify and only 1 to close it );
U have 2 lines like that

I know that the compiler gives u a wrong line where the error lies, but this is how compilers work, and here is not the place to discuss why
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-05-2006, 02:56 PM
Junior Member
 
Join Date: Jun 2006
Posts: 23
DaytrSuccess is on a distinguished road
problem parenthesis solved

Hello elihayun,

you are right thank you.

I already did post a reply to say ty.
Don't know what happened to it, it has disappeared.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 07-08-2006, 05:55 PM
Member
 
Join Date: Mar 2006
Posts: 33
dr_richard_gaines is on a distinguished road
Counting parenthesis

Quote:
Originally Posted by elihayun
why not u count the left parenthesis and right parenthesis to see if they match.

OrderModify((OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),YellowGreen);

It can't be more simple than that
Hi

Can you go over how you count parentheis..

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 07-08-2006, 10:29 PM
Member
 
Join Date: Apr 2006
Posts: 36
DollarShort is on a distinguished road
Counting parenthesis

I find it best to do it this way:

Start with one for the first left paren, then add one for each left paren and subtract one for each right paren. If they are balenced you should end with zero.

OrderModify((OrderTicket(),OrderOpenPrice(),...,or derTakeProfit(),...))
count: ......1 2............ 3 2.................. 3 2...................... 3 2.. 1 0


DS
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

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
ATR Trailing Stop - Help Boiseboy Indicators - Metatrader 4 53 07-26-2008 03:57 AM
Can someone add a simple Trailing Stop to this EA? fibofan Expert Advisors - Metatrader 4 7 05-21-2007 10:08 PM


All times are GMT. The time now is 10:39 PM.



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