''\end_of_program' - unbalanced left parenthesis' ERROR is driving me crazy !

 

Hi,

I'm (trying to) add this code into an existing program. If I compile it without the code listed below, it’s just fine. But no matter what I do with this section of code I ALWAYS get the same error '\end_of_program' - unbalanced left parenthesis . I've tried adding some in parenthesis, as well as removing some. In some instances it creates a lot more errors, but I can add in right (and left for that matter) parenthesis ' ( & ) ' as well as right and left brackets: ' { & } ' and I still get the same error! Its driving me crazy! )< 8) I've tried 'Reming it all out' with /* ...... */ as well and it complies just fine. I know that every bracket or parentheses needs to have it corresponding mirrored partner, but I can't find any instances of it. Sometimes when I add one in to try and fix it, the part of code that I am adding in with the 'extra' bracket or parenthesis the new section of code that I have added in is fine, but it makes for numerous other errors at the end of the program which has to do with saving error logs etc to files. I'm wondering what the number at the end of the error message after the file name and location: (794, 2) are and what they are indicative of? Perhaps this will provide a clue as to what and where the problem lies? I just went through it and individually 'rammed out' each line individually with ‘//’. I get the same error until I rem out any of the right brackets ‘}’ Then I get 1 error [ ‘(‘ – function definition unexpected‘ in the line “void Write|(string String)” (767, 11) with the ‘pipeline’ (the vertical line) representing where the cursor goes to. After that there are 5 identical errors (on different lines) : “ ‘Handle’ – variable not defined

Thanks to any and all for any assistance that you are able to give me.

=============================================================


for OrderSelect(LosingTrade, SELECT_BY_POS, MODE_TRADES);
{
Error = GetLastError()
if (Error != 0) Write ("Error reading losing order" + OrderTicket() + ": " + ErrorDescription(Error) + " = " + MarketInfo(OrderSymbol() + (OrderProfit()+OrderSwap())))
{
Error = GetLastError()
if (Error != 0) Write("Error accessing losing order " + DoubleToStr(BuyProfits[Order][1], 0) + ": " + ErrorDescription(Error) + " (A" + Error + ") Lots:" + OrderLots() + MarketInfo(OrderSymbol() + MODE_TRADES)
{
while (OrderProfit()+OrderSwap() =< MaximumLoss) && (OrderCloseTime=0);
}
OrderClose(LosingTrade, OrderLots(), 1, Red);

Error = GetLastError()
if (Error != 0) Write("Error closing losing order " + OrderTicket() + ": " + ErrorDescription(Error) + " (T" + Error + ") Lots:" + OrderLots() + " Ask:" + MarketInfo(OrderSymbol(), MODE_TRADES)
}
LosingTrade++;
}
break

 

What language do you program? It's not MQL4.

 


Error = GetLastError()
if (Error != 0) Write ("Error reading losing order" + OrderTicket() + ": " + ErrorDescription(Error) + " = " + MarketInfo(OrderSymbol() + (OrderProfit()+OrderSwap())))

Looks like the is one " ) " to many here at the end of the line.

 
DougRH4x:

for OrderSelect(LosingTrade, SELECT_BY_POS, MODE_TRADES);
{
Error = GetLastError()
if (Error != 0) Write ("Error reading losing order" + OrderTicket() + ": " + ErrorDescription(Error) + " = " + MarketInfo(OrderSymbol() + (OrderProfit()+OrderSwap())))
{
Error = GetLastError()
if (Error != 0) Write("Error accessing losing order " + DoubleToStr(BuyProfits[Order][1], 0) + ": " + ErrorDescription(Error) + " (A" + Error + ") Lots:" + OrderLots() + MarketInfo(OrderSymbol() + MODE_TRADES)
{
while (OrderProfit()+OrderSwap() =< MaximumLoss) && (OrderCloseTime=0);
}
OrderClose(LosingTrade, OrderLots(), 1, Red);

Error = GetLastError()
if (Error != 0) Write("Error closing losing order " + OrderTicket() + ": " + ErrorDescription(Error) + " (T" + Error + ") Lots:" + OrderLots() + " Ask:" + MarketInfo(OrderSymbol(), MODE_TRADES)
}
LosingTrade++;
}
break

Hi Doug

Although you are struggling with an unbalanced parenthesis error, the code you show has many other basic errors. I will give some examples:

- In the first line, the for statement is incomplete. It is not clear what you intend to be the body of the for loop. An example showing the syntax is:

for( i=0; i<NumToLoop; i++ )
{
}

I show the { } because this is how I construct my own code. I always enter parentheses in matching pairs before I enter the contents so I reduce my unbalanced parentheses errors.


- All the lines Error = GetLastError have no final semicolon. They should be

Error = GetLastError();


- There is no function Write() in MQL4. You should use Print() to print to the journal, Alert() to pop up an alert or Comment() to show it on the chart. Usually people use Print() for printing error messages. Look at the help (or the Dictionary tab in the editor) for the syntax.


- Your while() statement has no body. Example

while( OrderProfit() + OrderSwap() =< MaximumLoss && OrderCloseTime() == 0 )
{
   ...
}

Note the parentheses and I've changed = to == assuming that is what you intended.


There are other errors, but that's enough for now.


I suggest you try a simpler task for practice. I also sugget you read the MLQ4 book from front to back, which I did to learn. I can't attach it for some reason, but it is available from various sources. Search this and other MLQ4-based sites for MQl4BookEnglish.chm.


Sorry to be brutal, but I mean to be helpful.


Cheers

Jellybean

 

Hi Everyone,

Thanks for all of your help and suggestions, I haven’t tried them out yet to see if I can overcome the problem, but they are all GREATLY appreciated.

As is likely obvious, I am a total newbie at this and have very little programming experience of any sort and what I did have was decades ago.

As to which language that I am programming in, I am using the Meta Editor in the MT4 platform. Everything except the 'close losing trades' routine was already written. I even copied and pasted it all into MS Word and searched and highlighted both the Left and Right parenthesis. Initially it showed that there was a difference of 3 between them. Even with that and getting the same # of Right and Left, I still couldn’t make it work.

Thanks for the tip on starting with a matching pairs of () & {} when I code. I found the same suggestion in searching the MQL4 forums that was from a year or so ago by someone else that was having this exact same problem and it certainly makes sense.

FYI: PipMaker is a Martinegale scalper and if adjusted for it, it makes a LOT of trades very quickly: both winning and losing. The Martingale aspect of it has some adjustments available. The problem with it was the fact that it didn’t close out the losing trades (quickly) Thus my addition of the ‘Close Losing Trades ‘ routine.

This should make it a very profitable EA. If you have the desire to try it, with the losing trades closed out early, it should be VERY profitable on any currency pair and time frame.

Once again, thanks to everyone for all of your help!

Kind regards,

DougRH4x

 

Hi JB,

Initially I did have the conditional 'while' line as the Boolean '==', but it seemed that either way would work and produce the same result.

I don't sense any 'brutality' in your response. They are all helpful as I know nothing about this. As I posted in the other similar instance of this problem in the forms, perhaps my first learning project should be one that checks and finds errors like I am having troubles with. LoL But frankly I wouldn’t even know how to start on such a program.

I was going to wait until MT/MQL5 came out before I started to learn ForEx programming. but I started on modifying this one, which I thought would be relatively easy and simple, as opposed to writing a complete program from scratch the first time because I NEED to make some money quickly and can’t wait any longer. Especially now after I had so many problems with what was only a few lines of my own code added, I wouldn't have come up with anything that even worked, let alone was profitable for quite some time.

(8 >) Prosperous trading JB (< 8)

 

I used the built in help dictionary a LOT in trying to do this. It was definitely helpful in many aspects, but I couldn't really find anything definitive on the syntax of using the correct punctuation on things like: “( & )”, “{ & }” and ", & ;"

 
DougRH4x:

Hi JB,

Initially I did have the conditional 'while' line as the Boolean '==', but it seemed that either way would work and produce the same result.

I don't sense any 'brutality' in your response. They are all helpful as I know nothing about this. As I posted in the other similar instance of this problem in the Forums, perhaps my first learning project should be one that checks and finds errors like I was having troubles with. LoL But frankly I wouldn’t even know how to start on such a program.

I started on modifying this one, which I thought would be relatively easy and simple, as opposed to writing a complete program from scratch the first time because I NEED to make some money quickly. Especially now after I had so many problems with what was only a few lines of my own code added, I wouldn't have come up with anything that even worked, let alone was profitable for quite some time.

(8 >) Prosperous trading JB (< 8)

Hi Doug

It's a bit off topic for this forum, but one thing you just said alarms me - "because I NEED to make some money quickly." The only people I know that are successful started small, very small, until they knew their strategy and techniques were profitable in the long term. For example, firstly trade on a demo account until you achieve three consecutive profitable months. This will usually take longer than three months to achieve. Then trade with real money but minimum order sizes until you achieve three consecutive profitable months. Then gradually increase the risk to your acceptable level.

Trying to make money in a hurry often causes people to trade with larger risk than they should and always causes emotions to cloud sensible decision making. Even with EAs you need to make good decsions about validating it, when to run it and when to walk away. Get rich SLOWLY.

Finally, adding a routine to exit losing trades earlier will increase the number of losses and alter the %win/%loss ratio. The EA may well be less profitable as a result. If you get it working make sure you verify the performance using the system tester and then live on a demo account over a substantial time. Real money lost is very hard to win back.

All the best

Jellybean

 

Hi again JB,

I understand and will do forward testing on a demo account until I either prove it's profitability or reject it as being a loser. It does make a lot of trades that start off very small and some of them build up to much higher amounts before getting closed out. The downfall of this EA is that it doesn't close out the losers at all, but tries to hang onto them and reverse them into profitability as opposed to dumping them while they loss is still quite small . I'm fairly confident that in spite of the high number of losers, that if they are closed out early, the winners will far outnumber them in both volume and amount.

Unfortunately initially I didn't take the good advice that I heard everywhere of practicing on a demo account for at least 6 months and until I was consistently making profits before doing live trading. My first day of live trading I doubled my account just by looking at and watching the trends and the flow. This only served to sucker me in and I spent the rest of the week trying to hang onto it. I also made the mistake of 'getting married' to a trade that had gone south and tried to wait it out but it never reversed and I lost a LOT on that trade. Being a ‘know it all’ can be very expensive at times, in more ways that one!

I have a commercial EA that I am trying to make money with while I learn to be an effective technical trader. It scalps on 4 currency pairs and makes long term trades on another pair. Unfortunately the Long Term pair is basically just using scalping as well, only at a much higher (S/L) level. It has the S/L placed so that it should never take a loss as the S/L is positioned such that it will never get below this amouunt which is based on long term historical data. It placed a trade that went south badly and now has ~ 60% of my meager Live trading account drawn down )< 8) I have changed the S/L to a MUCH lower level and it is making money now on the long term pair. It is right more often than wrong, but when it loses now, it only loses a relatively small amount rather than the huge amount it used to on this pair. Because of my initial foolish approach I have basically blown all of the money I had to get started with this and am now trying to slowly build my live trading account up now. I don't bother with the 4 small Scalper pairs as it hardly makes anything when right and the quantity and size of the losses leaves them all in a net loss position.

 

Hi Doug

Another mark of a fine trader is the way they learn from their experience. You are obviously on the right track.

Cheers

Jellybean

 

Jellybean

wrote >>

Hi Doug

There is no function Write() in MQL4. You should use Print() to print to the journal, Alert() to pop up an alert or Comment() to show it on the chart. Usually people use Print() for printing error messages. Look at the help (or the Dictionary tab in the editor) for the syntax.

Hi JB,

I went through and changed most of the error notifications from 'Write' to 'Alerts'. However, at the end of the program where it is writing to the Log file, according to the MQL4 dictionary, the variety of commands for diferent types of data are:

int FileWrite( int handle, ...)

int FileWriteInteger( int handle, int value, int size=LONG_VALUE)

int FileWriteArray( int handle, object array[], int start, int count)
int FileWriteDouble( int handle, double value, int size=DOUBLE_VALUE)

int FileWriteString( int handle, string value, int length)

With the first one saving the data in the ASCII CSV format and the rest being Binary.

I'm not sure what they mean by the 'File Handle' though, it seems to be indicative of the file name??

Likewise I'm not really sure what the pupose and function of the 'Void.??????' command at the beginning of some sections is for and what it accompishes and does?

I haven't changed the "For, While ...' loop yet, but my Meata Editor keeps crahsing and I need to reboot but have to get some ZZZzzzs first and will try it later.

I've implemented most of the info from the helpful feedback, but so far I am still getting the exact same error message )< 8)

Over the years I have found a number of instances where there has been a lot of heavy editing done on one section and the data and information that is shown on the screen is NOT in sync with what the actual info is and that there are some control/formating codes that aren't show on the screen that are causing problems. Before MicroSoft became dominant and 'Word' became the defacto standard powereful word processor, the best word processor was called 'Word Perfect' It had a very nice feature that allowed the user to change these so that they were shown on the screen or not so that when these problems arose, one could check them out and fix them. A good current example of this is with HTML documents.

If I still can't get it to work and I will re-enter the problem code, likely initially without the error messages, and then delete the old problem section and see if that helps. The fact that when I make some changes to the 'Close Losing Trades' section that I am adding, that sometimes that section will be OK but subsequent code will be messed up confirms that this program doesn't have the best of structures as for the most part each section should be completely compartimenatlized to avoid these sorts of problems.

'Once more unto thy breach....

with the later two writing to a binary file and 'handle' being the name of the (log) file I assume.

I'm wondering if when I use the created variable 'LosingTrade', if I don't have specific info to insert right after it, if I should be using 'LosingTrade()' instead?

I have implemented most of the changes that

Reason: