unexpected token error

 

can some help me with this error

extern int TakeProfit=750;
extern int TrailingStop=100;
extern int StopLoss = 100;


// check open possitions and place sl, tp

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

}

}

}
}

 

Replace

if ((OrderType() == OP_BUY) && ((Bid-OrderOpenPrice())>TrailingStop))
to

if (OrderType() == OP_BUY && Bid-OrderOpenPrice()>TrailingStop*Point)

 

Replace: else ((OrderType() == OP_SELL) && (OrderOpenPrice()-Ask)>(TrailingStop))


With: else


it doesn't like a double Conditional-If


Once you fix that you have to fix "=" with "==" in

if ((OrderStopLoss()>Ask+TrailingStop*Point) ||(OrderStopLoss()==0))


And also add a "(" to the following after OrderTicket:

OrderModify((OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),Red);

 
FXtrader2008:



Replace: else ((OrderType() == OP_SELL) && (OrderOpenPrice()-Ask)>(TrailingStop))


With: else


it doesn't like a double Conditional-If


Once you fix that you have to fix "=" with "==" in

if ((OrderStopLoss()>Ask+TrailingStop*Point) ||(OrderStopLoss()==0))


And also add a "(" to the following after OrderTicket:

OrderModify((OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),Red);


thank you for helping me i am still 50% rookie

Roger i have replace it as you have said thank you


FXTrader you say that it doent like a double condition -if

is it before the else


OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_BUY && Bid-OrderOpenPrice()>TrailingStop*Point)
{

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

}

if i understand correctly that the EA is confuse about the else and does not know if it is for the first if or second if

is that correct

should i just take out the else and say

if ((OrderType() == OP_SELL) && (OrderOpenPrice()-Ask > TrailingStop))
 

I did not check your algorithm --- you will have to do that


Let me clarify my "it doesn't like a double Conditional-If" comment


The Conditional-If format is:


if(some logic equation)

{

Block 1 operators (are executed if logic equation is true)

}

else

{

Block 2 operators (are executed if logic equation is false)

}


You cannot redefine the original logic equation later in the same Conditional-If sequence --- that is what i meant when I said "it doesn't like a double conditional-if".


Most likely you will have to create one more Condition-If operator to handle the " ((OrderType() == OP_SELL) && (OrderOpenPrice()-Ask)>(TrailingStop))" logic statement if it is important to your algorithm.



I can appreciate your frustration in debugging the syntax. I too encountered a lot of frustration in the beginning. Here is how I managed to overcome that ever present challenge:


1. I create all my code in the Notepad++ text editor (freeware at Download.com). It has special features that highlight matching parentheses, matching braces etc, and does other color highlighting of text to help you keep your code organized. (be sure to select "C++" from the drop down menu under "Language")


2. I then copy only a few lines at a time into a separate EA that I use for finding syntax errors and then compile it ---- this is how I found your errors. By adding only a few lines at a time to the separate EA with subsequent compiling each time you keep the opportunity for errors to only a few lines. You, of course have to enter a complete "conditional-if" sequence at a time otherwise you will get unbalanced brace errors . If you have nested "conditional'if" statement, you will have to build them pieces at a time. Get the 1st tier set compiled correctly before nesting a 2nd tier set inside the 1st tier --- keeping the brace balance correct at all times of course.


3. Also, be sure to refer to the (LN xxx, Col xx) indicator in the lower right corner of the MetaEditor, it tells you the current location of the cursor, and you can match that up with the location indicated in the error message.


4. Once the code passes muster in the separate EA I copy and paste it into the EA I am creating.


Cheers!

 
FXtrader2008:

I did not check your algorithm --- you will have to do that


Let me clarify my "it doesn't like a double Conditional-If" comment


The Conditional-If format is:


if(some logic equation)

{

Block 1 operators (are executed if logic equation is true)

}

else

{

Block 2 operators (are executed if logic equation is false)

}


You cannot redefine the original logic equation later in the same Conditional-If sequence --- that is what i meant when I said "it doesn't like a double conditional-if".


Most likely you will have to create one more Condition-If operator to handle the " ((OrderType() == OP_SELL) && (OrderOpenPrice()-Ask)>(TrailingStop))" logic statement if it is important to your algorithm.



I can appreciate your frustration in debugging the syntax. I too encountered a lot of frustration in the beginning. Here is how I managed to overcome that ever present challenge:


1. I create all my code in the Notepad++ text editor (freeware at Download.com). It has special features that highlight matching parentheses, matching braces etc, and does other color highlighting of text to help you keep your code organized. (be sure to select "C++" from the drop down menu under "Language")


2. I then copy only a few lines at a time into a separate EA that I use for finding syntax errors and then compile it ---- this is how I found your errors. By adding only a few lines at a time to the separate EA with subsequent compiling each time you keep the opportunity for errors to only a few lines. You, of course have to enter a complete "conditional-if" sequence at a time otherwise you will get unbalanced brace errors . If you have nested "conditional'if" statement, you will have to build them pieces at a time. Get the 1st tier set compiled correctly before nesting a 2nd tier set inside the 1st tier --- keeping the brace balance correct at all times of course.


3. Also, be sure to refer to the (LN xxx, Col xx) indicator in the lower right corner of the MetaEditor, it tells you the current location of the cursor, and you can match that up with the location indicated in the error message.


4. Once the code passes muster in the separate EA I copy and paste it into the EA I am creating.


Cheers!







thank you for your help i will try it. it sounds very good

i wish there is some one who can fine tune us rookies

we some time get stuck with a program and the i go and look at a lot of EA's.

that some times bring confusion. i have done the course by coders guru in forex-tsd but it can only take you so far

what i miss is a step by step debugger. i have done programming in dbase and they had a step by step debugger.

can i ask help from you if im stuck. i dont want you to write the EA from me but give me help if i am stuck.


johan

 

Johan, you are not that far behind me in learning the MQL4. I first encountered MT4 and MQL4 about 2 years ago, and spent a couple months learning it by revising existing EA's, then I got stuck on a syntax error that I could not resolve and took an 18 month hiatus. During that hiatus I worked on developing some trade rules. I started coding the trade rules a little over two months ago. When I started coding my trade rules into an EA I developed ways and means to keep the syntax error resolution to something that is manageable. Therefore instead of writing a bunch of code and then trying to correct all the syntax errors in it at one time, I developed the small step by small step technique to keep the lines of code where errors can appear to a minimum. It may seem tedious to do it the way I outlined in the earlier post, but in the long run is it's a real time saver and it makes you self-sufficient.


In reality, the compiler is your friend. It finds the errors and gives you a pretty good clue where they are located most of the time, and what type of error it is. If you compile only a few lines at a time it really narrows the area where the error can be located if the compiler is not giving you a good location clue.


My only previous programming experience occurred 35+ years ago in college with Fortran and key punch cards.

 
FXtrader2008:

Johan, you are not that far behind me in learning the MQL4. I first encountered MT4 and MQL4 about 2 years ago, and spent a couple months learning it by revising existing EA's, then I got stuck on a syntax error that I could not resolve and took an 18 month hiatus. During that hiatus I worked on developing some trade rules. I started coding the trade rules a little over two months ago. When I started coding my trade rules into an EA I developed ways and means to keep the syntax error resolution to something that is manageable. Therefore instead of writing a bunch of code and then trying to correct all the syntax errors in it at one time, I developed the small step by small step technique to keep the lines of code where errors can appear to a minimum. It may seem tedious to do it the way I outlined in the earlier post, but in the long run is it's a real time saver and it makes you self-sufficient.


In reality, the compiler is your friend. It finds the errors and gives you a pretty good clue where they are located most of the time, and what type of error it is. If you compile only a few lines at a time it really narrows the area where the error can be located if the compiler is not giving you a good location clue.


My only previous programming experience occurred 35+ years ago in college with Fortran and key punch cards.



thank you i remember fortran

thank you for your help with that notepad - it does make it easier

can you tell me where can i get a list and explantion of fault

for instance what is a "unbalance left parenthesis"

 

I'm not aware of an existing list of common syntax error. I did a quick search on the search engine but turned up nothing.


The unbalance parenthesis is one of the harder syntax errors to resolve if you have several hundred lines of code because the unmatched parenthesis can be near the beginning of the EA and the compiler often indicates that the unbalanced aspect occurs on the last line.


Just a few days ago I turned my functioning EA (from a syntax perspective, not an algorithmic perspective) into a non-functioning one by introducing an unbalanced parenthesis. It took me an hour to find it.


In conclusion, "technique" is very important, because we are bound to make errors, but by adopting a code writing technique it really helps with resolving the syntax errors.


I just learned about Notepad++ a little over a week ago via this forum, before that I had been using a standard text editor.

 
FXtrader2008:

I'm not aware of an existing list of common syntax error. I did a quick search on the search engine but turned up nothing.


The unbalance parenthesis is one of the harder syntax errors to resolve if you have several hundred lines of code because the unmatched parenthesis can be near the beginning of the EA and the compiler often indicates that the unbalanced aspect occurs on the last line.


Just a few days ago I turned my functioning EA (from a syntax perspective, not an algorithmic perspective) into a non-functioning one by introducing an unbalanced parenthesis. It took me an hour to find it.


In conclusion, "technique" is very important, because we are bound to make errors, but by adopting a code writing technique it really helps with resolving the syntax errors.


I just learned about Notepad++ a little over a week ago via this forum, before that I had been using a standard text editor.




thanks for your help

i know u are very busy

i have found the problem and have fixed it

and i am following your programming skills so i am adding to the EA

this EA is an trail stop EA - so what i want to do is just do my buy and sells manually and the Ea must

place SL, TP and trail it for me

know i am stuck with the SL function


where to put it

it find first the open orders and the should see if it is a buy or a sell

if buy OrderModify(OrderStopLoss()=OrderOpenPrice()-StopLoss,OrderTakeProfit(),0,Blue)

in with sell just the +

will this work

Reason: