| / | Forum |
|
Huckleberry
2010.02.20 03:43
Hello to you all. Compilier tells me left paraenthesis expected, then tells me unexpected. Same with tokens, the need more assignments,etc. Can someone give me a hand? Problems are in the Closing Orders. Cheers double ATR; double Slippage; double StopLoss; double TakeProfit; double Lots; //--------Trade Criteria------------- extern double Open_Level_ATR ; extern double Close_level_ATR ; //------------------------------------ int start() { //1L (L = left brace) if (Ask > (High[iHighest(NULL,0,MODE_HIGH,10, 1)])==true) { //2L ATR = iATR(NULL,0,20,1); //GV calculation for exit { //3L if (OrdersTotal() == 0) { //4L int Buy = OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point); } //4L 1R (R = right brace) //------------------------------- else { //5L 1R if (Bid < (Low[iLowest(NULL,0,MODE_LOW,10, 1)])==true) { //6L 1R ATR = iATR(NULL,0,20,1); //GV calculation for exit { //7L 1R if (OrdersTotal() == 0) { //8L 1R int Sell = OrderSend(Symbol(),OP_SELL,Lots,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point); } //8L 2R return(0); } //8L 3R } //8L 4R } //8L 5R } //8L 6R } //8L 7R //------------- Closing Orders ----------------- double Amount; double total; for(Amount=0; Amount < total; Amount++) { //9L 7R OrderSelect(Amount, SELECT_BY_POS, MODE_TRADES); if(OrderType() == OP_BUY && //Any open LONG position? OrderSymbol()==Symbol()) //What is the symbol? { //10L 7R // if (OrderType()==OP_BUY) //If long position is opened // { //11L 7R if (OrderSelect(OrderOpenPrice) - (ATR*2) = true); // { //12L 7R OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue); //Position closed } //12L 8R else { //13L 8R for(Amount=0; Amount < total; Amount++) { //14L 8R OrderSelect(Amount, SELECT_BY_POS, MODE_TRADES); if(OrderType() == OP_SELL && //Any open SHORT position? OrderSymbol()==Symbol()) //What is the symbol? { //15L 8R if(OrderType()==OP_SELL); //If SHORT position is opened { //16L 8R if OrderSelect() = OrderOpenPrice() + ATR*2; //Should it be closed? { //17L 8R OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); // Position closed } //17L 9R return(0); //Exit Algorithm } //17L 10R } //17L 11R } //17L 12R } //17L 13R } //17L 14R // } //17L 15R |
|
It is sometimes necessary to perform identical operations with a group of files. If you have a list of files included into a group, then it is no problem. However, if you need to make this list yourself, then a question arises: "How can I do this?" The article proposes doing this using functions FindFirstFile() and FindNextFile() included in kernel32.dll. |
2030 |
gordon
2010.02.20 07:09
From your code (and your R/L braces comments) it seems u don't understand the concepts of blocks, nested blocks, proper indentation and generally how to use braces. I recommend u re-read about compound operators and about Conditional Operator 'if - else' in the book. I'll try to give some pointers: In the following code: if (Ask > (High[iHighest(NULL,0,MODE_HIGH,10, 1)])==true) '>' has the same precedence as '==' so the expression would be evaluated from left to right. Hence this expression can be simplified and is equal to this: if (Ask > High[iHighest(NULL,0,MODE_HIGH,10, 1)]) In the following code: int start() { //1L (L = left brace) if (Ask > (High[iHighest(NULL,0,MODE_HIGH,10, 1)])==true) { //2L ATR = iATR(NULL,0,20,1); //GV calculation for exit { //3L if (OrdersTotal() == 0) { //4L int Buy = OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point); } //------------------------------- else { //5L 1R There is no need to open a new block after 'ATR=iATR...', it serves no purpose (hence no need to indent the line after it). Braces are not needed around a single expression (int Buy = ...), that just 'wastes' lines. Indentation should 'fit' the blocks and emphasis their structure. So the code should look like this: int start() { if (Ask > High[iHighest(NULL,0,MODE_HIGH,10, 1)]) { ATR = iATR(NULL,0,20,1); if (OrdersTotal() == 0) int Buy = OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point); } else { In your code the 'else' refers to if (OrdersTotal == 0 )... In the fixed code 'else' refers to if (Ask > High[...) which I assume is what u meant. BTW - I assume u have a reason to calculate the ATR at that point in the code (if not, then that line shouldn't be there), Notice that each indentation level begins with an 'open' brace and finishes with a 'close' brace. If your code was properly indented, then u would have seen immediately where u had missing braces. If you understand my example, u can very easily fix the rest of the code. |
|
WHRoeder
2010.02.20 18:15
for(Amount=0; Amount < total; Amount++) { OrderSelect(Amount, SELECT_BY_POS, MODE_TRADES); if(OrderType() == OP_SELL && OrderSymbol()==Symbol()) { if(OrderType()==OP_SELL); { if OrderSelect() = OrderOpenPrice() + ATR*2; { OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); } return(0); } } } } }This also will not work. Once you close position 0 position 1 becomes 0, etc and you skip every other position. // v rename amount to something else, that's not an amount. for(int index = OrdersTotal() - 1; index >= 0; index--) if ( OrderSelect(index, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == MagicNumber // my magic number && OrderSymbol() == Symbol() ) { // and period and symbol // v Delete semi // v putting brackets on same line reads easier, more compact. if(OrderType()==OP_SELL) { // v missing open paren/delete semi/comparison is == not = // v Do not compare doubles with == // v Do you mean OrderClose() <= OrderOpenPrice() + ATR*2 ei Bid below 2 atr if OrderSelect() = OrderOpenPrice() + ATR*2; { OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); // ^ Test for failure and print errors } return(0); // < delete process all } // Sell } // For |
|
Huckleberry
2010.02.20 20:52
gordon wrote >>
From your code (and your R/L braces comments) it seems u don't understand the concepts of blocks, nested blocks, proper indentation and generally how to use braces. I recommend u re-read about compound operators and about Conditional Operator 'if - else' in the book. I'll try to give some pointers: In the following code: '>' has the same precedence as '==' so the expression would be evaluated from left to right. Hence this expression can be simplified and is equal to this: In the following code: There is no need to open a new block after 'ATR=iATR...', it serves no purpose (hence no need to indent the line after it). Braces are not needed around a single expression (int Buy = ...), that just 'wastes' lines. Indentation should 'fit' the blocks and emphasis their structure. So the code should look like this: In your code the 'else' refers to if (OrdersTotal == 0 )... In the fixed code 'else' refers to if (Ask > High[...) which I assume is what u meant. BTW - I assume u have a reason to calculate the ATR at that point in the code (if not, then that line shouldn't be there), Notice that each indentation level begins with an 'open' brace and finishes with a 'close' brace. If your code was properly indented, then u would have seen immediately where u had missing braces. If you understand my example, u can very easily fix the rest of the code. Hello Gordon Many thanks. Many. The first part where I thought it was OK, your guidence shorten the code and cleaned it up. I stumbled thru the first few lines of the closing order block and it cleaned up. But have a look at todays thread " Down from 18 errors to 5. Little help please. " I have a few questions . Thanks again |
|
Huckleberry
2010.02.20 21:04
WHRoeder wrote >>
This also will not work. Once you close position 0 position 1 becomes 0, etc and you skip every other position. Hello WHRoeder Thank you for your reply and your help. I have just opened this thread again, to find you made some further guidance and I appreciate the help. I will put the info to good use. If you could take a look at the thread I posted today "Down from 18 errors to 5. Little help please", could this be what was confuseing me? The fix and clean up for the Closing Orders did not seem to be clear to me. Thanks again. It is the help that you, Gordon, CB, and so many more I have made contact with, that makes this site so friendly and worthwhile to attend. Cheers |
|
Huckleberry
2010.02.20 23:50
Hello WHRoeder, Forgive me for copying your solution straight from the post. I have expanded the code so that it will also close out the Sell Orders. I gave a brief discription, due to you were asking if such and such was to do this or that. double MagicNumber;
for(int index = OrdersTotal() - 1; index >= 0; index--) if (
OrderSelect(index, SELECT_BY_POS) // Only my orders w/
&& OrderMagicNumber() == MagicNumber // my magic number
&& OrderSymbol() == Symbol() ) { // and period and symbol
// v Delete semi
// v putting brackets on same line reads easier, more compact.
if(OrderType()==OP_SELL) {
// v missing open paren/delete semi/comparison is == not =
// v Do not compare doubles with ==
// v Do you mean OrderClose() <= OrderOpenPrice() + ATR*2 ei Bid below 2 atr
if OrderSelect ()= OrderOpenPrice() - ATR*2; //The Buy entry was breakout to the up side.
//Eventually it will reverse. When it does reverse, do this:
//OrderSelect=OrderOpenPrice - (ATR*2)
//There is more to this code.
//Additional Buy Entries at (ATR/2) consistently, until reverse
//in trend. Yes there are many loseing trades with this strategy.
//Runs close to Richard Dennis, Turtle trade.
//Let the winner run.
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
// ^ Test for failure and print errors
}
return(0); // < delete process all
} // Sell
} // For
//-------------------------------------
else {
if (OrderType() == OP_BUY) {
if OrderSelect() = OrderOpenPrice() + ATR*2; {
OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue);
}
return(0);
}
}
} |
|
Ais
2010.02.20 23:54
|
|
Huckleberry
2010.02.21 00:18
Hello Again Ais, Thanks for the info as always. I did insert as instructed with no help. Not more errors. The total errors that exist has not changed. There are 19 errors. 18 of which (9 and 9) with the "if OrderSelect() = OrderOpenPrice() - (ATR*2);" // 9 errors here "if OrderSelect() = OrderOpenPrice() +(ATR*2); // 9 more errors here And one error when using 'else'. ??? Not sure from my understanding. One code gives me 5 errors. The other gives me 19. Both codes have their own merits. With all errors confined to the same lines includeing the 'else'. Cheers to all |
|
Huckleberry
2010.02.21 00:33
Hello to all the have helped, Thanks for all your efforts. Just to let you know, the code will have more. Such as blocks for errors, position sizing, comments, and alerts. My idea was to put this together a piece at a time. I am hoping not to screw it up when the extras are added to it. If you believe I am going about it wrong, please inform me. Regards |
|
Ais
2010.02.21 00:49
|
|
Huckleberry
2010.02.21 01:32
Hello Ais That's a different approach. It has the eary lessons from the MQL4 book. I will have a go with this and get back. Thank you Regards |