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+TrailingStop*Point,OrderTakeProfit(),Red);

return (0);

}
}
}

}

}

 

Try this :

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);

}

}

}

}

}

Hope this help

 

hello Firedave,

thank you for your answer.

I tried it, but still the same problem : unbalenced parenthesis

 
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

 

Help : someone must have the solution.

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.

 
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

 

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.

 

Counting parenthesis

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

 

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(),...,orderTakeProfit(),...))

count: ......1 2............ 3 2.................. 3 2...................... 3 2.. 1 0

DS

Reason: