All your for loops are missing an end bracket except the last one. stick the closing brackets before the for loop closing bracket like:
//---- Function First Take Profit for(i=0;i<Total;i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES==true)) { if(PipsVal>=TakeProfit && NextTP<1) { if(OrderType()==1) OrderClose(Ticket,CloseLots,Ask,3,DarkViolet); else OrderClose(Ticket,CloseLots,Bid,3,DarkViolet); NextTP=1; } }//<--place the closing brackets here } //---- End Function
btw, you're not going to get the pip val the way your going about it.
This and anything else like it will not get you the pip differnce:
PipsVal=Ask-OrderOpenPrice()*Point;
You will get a decimal that is very small. way less than 1 every single time.
You need to place this function, a real function(I notice you call your loops functions) at the top of page(right below Intern Vars if you like):
{
if(Digits==2) return(MathAbs((val1-val2) * 100));
if(Digits==3) return(MathAbs(MathRound((val1-val2) * 100)));
if(Digits==4) return(MathAbs((val1-val2) * 10000));
if(Digits==5) return(MathAbs(MathRound((val1-val2) * 10000)));
return(0);
}
Then call it in your loops like: PipsVal=GetPipDiff(Ask,OrderOpenPrice());
Thank's a lot for your time. Sorry I'm a very beginer in coding. I try but I recieved an error.
val1, val2: variable not defined
I want a pip counter.
If my trade profit, the counter give the number of pip I profit. 1, 2, 3....
If my trade loss, the counter give the number of pip I lost. -1, -2, -3...
Please help me!
pgforex
Hi,
I'm a NewBee at this perhaps like yourself. I have been having the same ongoing and very frustrating such problems as well. One thing that is helping me get a handle on it was JellyBean’s tip that if you have the syntax &/or punctuation the usage that is incorrect anywhere in the program, then it is not going to flag the specific error correctly and show you exactly where and what the problem is )< 8) While the help file in the MQL4 Editor seems to cover most of the subjects, I find it tends to be rather sparse. For example, there is nothing in it that I could find about the proper and improper usage of syntax & punctuation; without which it is impossible to write a correct program that will compile and run properly in this beast.
JB also informed me about the MQL4 ‘reference book’ that was available and I got the link from Rosh: one of the SysOps here: https://book.mql4.com//
It gives more complete info and explanations, and actually has info on punctuation. It does not have a ‘search’ function’’ though which impairs it’s ’Help’ capacities significantly. Good luck on finding the info on punctuation & syntax. I found it once, but have troubles finding it again: there is no ‘book marking’ capacity with the ‘Help book’ either )< 8)
Frankly I am not very impressed with the MQL programming language. It hardly qualifies as a ‘high level’ programming language’’ It’s more like a DOS command line interface/interpreter from over 30 years ago that fails and falls flat on its face if you don’t use the EXACT coding with things like leaving out or putting in a punctuation mark, or the wrong one, or in the wrong place; or don’t use a Capital letter and use lower case instead. Duh!
There is a very good reason why they have GUIs now. I’m not impressed by what I have heard about MQL5 so far either, but at least it is supposed to be ‘object oriented’.
Good Luck, we both need it! LoL
Ï'm not sure if it's good.
I use this software to get a tick: http://www.fx1.net/mt4tick.php
I try this code but I get only 1 tick. I don't know if it work.
if(Digits==2) { PipsVal=MarketInfo(Symbol(),MODE_TICKSIZE)*100; } if(Digits==4) { PipsVal=MarketInfo(Symbol(),MODE_TICKSIZE)*10000; }
Thank's
pgforex
btw, you're not going to get the pip val the way your going about it.
This and anything else like it will not get you the pip differnce:
You will get a decimal that is very small. way less than 1 every single time.
You need to place this function, a real function(I notice you call your loops functions) at the top of page(right below Intern Vars if you like):
{
if(Digits==2) return(MathAbs((val1-val2) * 100));
if(Digits==3) return(MathAbs(MathRound((val1-val2) * 100)));
if(Digits==4) return(MathAbs((val1-val2) * 10000));
if(Digits==5) return(MathAbs(MathRound((val1-val2) * 10000)));
return(0);
}
Then call it in your loops like: PipsVal=GetPipDiff(Ask,OrderOpenPrice());
//+------------------------------------------------------------------+ //| 0.00012 == 1.2 pips | //+------------------------------------------------------------------+ //---- These are adjusted for 5 digit brokers. double pips2points = 1, pips2dbl, // = Point slippagePoints; // = SlippagePips * pips2points; //---- int init() { pips2dbl = Point; if (Digits == 3 || Digits == 5) { pips2points *= 10; pips2dbl *= 10; } slippagePoints = SlippagePips * pips2points; } /* This MUST be AFTER OrderSelect() and you do not handle the case of there being NO orders. double CountBE = OrderOpenPrice(); double CloseLots = OrderLots() / 2; int Total = OrdersTotal(); int Ticket = OrderTicket(); */ //double CloseLots = OrderLots() / 2; double LotStep = MarketInfo( Symbol(), MODE_LOTSTEP ); double CloseLosts = MathFloor( OrderLots()/2 / LotStep )*LotStep; ... // PipsVal=Ask-OrderOpenPrice()*Point; PipsVal=( Ask-OrderOpenPrice() )/pips2points; ... //if(OrderType()==1) OrderClose(Ticket,CloseLots,Ask,3,DarkViolet); if(OrderType()==OP_SELL) OrderClose(Ticket,CloseLots,Ask,3*pips2points,DarkViolet);
I've change all the code, but I have the same problem.
unbalanced bracket or something like that
I think of my second code in my life is better than the first, but I don't know if it work's.
In reality I have 2 problems with my code. I have a part of the code than I want to execute
only once, but I don't know to do that.
First, is a bracket bug:
//+------------------------------------------------------------------+ //| | //| Copyright © 2009, Pascal Gignac | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, Pascal Gignac" #property link "" //---- Input Parameters extern int TakeProfit = 20; extern int FirstTarget = 15; extern int FirstStop = 1; extern int StopLoss = 20; extern int EMA_Period1 = 5; extern int EMA_Period2 = 10; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { int cnt, ticket, total, EMA_1, EMA_2; double CloseLots; //---- for(cnt = 0; cnt < total; cnt++) { if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES==true)) if(OrderType() == OP_SELL && OrderSymbol() == Symbol()) { CloseLots = OrderLots() / 2; EMA_1 = iMA(Symbol(),0,EMA_Period1,0,MODE_EMA,PRICE_CLOSE,0); EMA_2 = iMA(Symbol(),0,EMA_Period2,0,MODE_EMA,PRICE_CLOSE,0); //---- Max Stop Loss OP_SELL if(Bid >= (OrderOpenPrice()+(StopLoss*Point)) { OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); return(0); } //---- Modify when hit First Target if(Bid <= OrderOpenPrice()-(FirstTarget*Point)) { OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - (FirstStop*Point),0, 0, Blue); return(0); } //---- Take Profit half position if(Bid <= OrderOpenPrice()-(TakeProfit*Point) { OrderClose(OrderTicket(),CloseLots, Bid,3,Green); return(0); //---- Take Profit second half position when EMA crosse } if(EMA_1 > EMA_2) { OrderClose(OrderTicket(),OrderLots(),Bid,3,Lime); return(0); } } else //---- Sinon OP_BUY //---- Max StopLoss on OP_BUY { if(Ask <= (OrderOpenPrice()-(StopLoss * Point))) { OrderClose(OrderTicket(),OrderLots(),Ask,3,Red); return(0); } //---- Modify when hit First Target if(Ask >= OrderOpenPrice()+(FirstTarget*Point)) { OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+(FirstStop*Point),0,0, Blue); return(0); } //---- Take Profit half position if(Ask >= OrderOpenPrice()+(TakeProfit*Point)) { OrderClose(OrderTicket(),CloseLots, Ask,3,Green); return(0); } //---- Take Profit second half position when EMA crosse if(EMA_1 < EMA_2) { OrderClose(OrderTicket(),OrderLots(),Ask,3,Lime); return(0); } return(0); } } } //---- return(0); } //+------------------------------------------------------------------+
Second, execute this only once:
This part if is a Sell Order //---- Take Profit half position if(Bid <= OrderOpenPrice()-(TakeProfit*Point) { OrderClose(OrderTicket(),CloseLots, Bid,3,Green); return(0); } This part if is a Buy Order //---- Take Profit half position if(Ask >= OrderOpenPrice()+(TakeProfit*Point)) { OrderClose(OrderTicket(),CloseLots, Ask,3,Green); return(0); }
Thank's
pgforex
for(cnt = 0; cnt < total; cnt++) { if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES==true)) { // Missing open bracket if(OrderType() == OP_SELL && OrderSymbol() == Symbol()) {These won't work on a 5 Digit broker:
if(Bid <= OrderOpenPrice()-(TakeProfit*Point) { OrderClose(OrderTicket(),CloseLots, Bid,3,Green);
Hello WHRoeder, I tried to add missing bracket, but don't work. error: end_of_program' - unbalanced left parenthesis
I'm very very beginner. Can you explain me the bug on 5 Digit. Have tried your answer above, but don't work for me.
And just for fun, I explan my strategy and tell me if my code do that.
I open orders myself without stoploss and take profit.
EA detect my order
I set TakeProfit, FirstTarget and StopLoss in EA
If order hit StopLoss: Close Order
If order hit FirstTarget: Modify Order ---> Move StopLoss to Open Price + 1
If order hit TakeProfit: Close Order ---> Only half position for quick profit and let run the other half for big profit (I don't know how execute this only once per trade!)
If fast EMA crosse slow EMA above: Close second half position on Sell order
If fast EMA crosse Slow EMA below: Close second half position on Buy order
Thank's for your help!
pgforex
//+------------------------------------------------------------------+ //| | //| Copyright © 2009, Pascal Gignac | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, Pascal Gignac" #property link "" //---- Input Parameters extern int TakeProfit = 20; extern int FirstTarget = 15; extern int FirstStop = 1; extern int StopLoss = 20; extern int EMA_Period1 = 5; extern int EMA_Period2 = 10; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { int cnt, ticket, total, EMA_1, EMA_2; double CloseLots; //---- for(cnt = 0; cnt < total; cnt++) { if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES==true)) if(OrderType() == OP_SELL && OrderSymbol() == Symbol()) { CloseLots = OrderLots() / 2; EMA_1 = iMA(Symbol(),0,EMA_Period1,0,MODE_EMA,PRICE_CLOSE,0); EMA_2 = iMA(Symbol(),0,EMA_Period2,0,MODE_EMA,PRICE_CLOSE,0); //---- Max Stop Loss OP_SELL if(Bid >= (OrderOpenPrice()+(StopLoss*Point)) { OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); return(0); } //---- Modify when hit First Target if(Bid <= OrderOpenPrice()-(FirstTarget*Point)) { OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - (FirstStop*Point),0, 0, Blue); return(0); } //---- Take Profit half position if(Bid <= OrderOpenPrice()-(TakeProfit*Point) { OrderClose(OrderTicket(),CloseLots, Bid,3,Green); return(0); //---- Take Profit second half position when EMA crosse } if(EMA_1 > EMA_2) { OrderClose(OrderTicket(),OrderLots(),Bid,3,Lime); return(0); } } else //---- Sinon OP_BUY //---- Max StopLoss on OP_BUY { if(Ask <= (OrderOpenPrice()-(StopLoss * Point))) { OrderClose(OrderTicket(),OrderLots(),Ask,3,Red); return(0); } //---- Modify when hit First Target if(Ask >= OrderOpenPrice()+(FirstTarget*Point)) { OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+(FirstStop*Point),0,0, Blue); return(0); } //---- Take Profit half position if(Ask >= OrderOpenPrice()+(TakeProfit*Point)) { OrderClose(OrderTicket(),CloseLots, Ask,3,Green); return(0); } //---- Take Profit second half position when EMA crosse if(EMA_1 < EMA_2) { OrderClose(OrderTicket(),OrderLots(),Ask,3,Lime); return(0); } return(0); } } } //---- return(0); } //+------------------------------------------------------------------+
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, anybody can help me? This is my very first code. I know absolutly nothing in c/c++ or mql4.
I have this error: end_of_programme' - ending bracket '}' expected
Thank's
pgforex