//+------------------------------------------------------------------+ //| Smart Trailer.mq4 | //| Echelon | //| ebukaume@gmail.com | //+------------------------------------------------------------------+ #property copyright "Echelon" #property link "ebukaume@gmail.com" //--- input parameters extern int WhenToStartTrailing=60; extern int PipsToTrail=10; double Rhigh ; double Rlow ; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { for (int i=OrdersTotal()-1; i>=0; i--) int CurrentTime = TimeHour(TimeCurrent()); int OpenTime = TimeHour(OrderOpenTime()); int count = CurrentTime - OpenTime { OrderSelect(i, SELECT_BY_POS,MODE_TRADES); if(OrderSymbol()==Symbol()) if(Period()==PERIOD_H1) if(OrderType()==OP_BUY) { Rhigh=High[iHighest(Symbol(),PERIOD_H1,MODE_HIGH,count(),0]; if(Rhigh-OrderOpenPrice >= (WhenToStartTrailing*Point)) if((Low[iHighest(Symbol(),PERIOD_H1,MODE_HIGH,count(),0]-(PipsToTrail*Point)) > OrderStopLoss) OrderModify(OrderTicket(),OrderOpenPrice(),Low[iHighest(Symbol(),PERIOD_H1,MODE_HIGH,count,0]-(PipsToTrail*Point),OrderTakeProfit(),0,CLR_NONE); } if(OrderType()==OP_SELL) { Rlow=Low[iLowest(Symbol(),PERIOD_H1,MODE_LOW,count(),0] if(OrderOpenPrice-Rlow >= WhenToStartTrailing*Point) if((High[iLowest(Symbol(),PERIOD_H1,MODE_HIGH,count(),0]+(PipsToTrail*Point) < OrderStopLoss)|| OrderStopLoss = 0) OrderModify(OrderTicket(),OrderOpenPrice(),High[iLowest(Symbol(),PERIOD_H1,MODE_HIGH,count,0]+(PipsToTrail*Point),OrderTakeProfit(),0,CLR_NONE); } } return(0) } //+------------------------------------------------------------------+
ebukaume: It fails to compile and returns the error "'\end_of_program' - unbalanced left parenthesis".
You reposted while I was replying. Why didn't you EDIT your original post.
Play videoPlease edit your post.
For large amounts of code, attach it.for (int i=OrdersTotal()-1; i>=0; i--) int CurrentTime = TimeHour(TimeCurrent()); int OpenTime = TimeHour(OrderOpenTime()); int count = CurrentTime - OpenTime { OrderSelect(i, SELECT_BY_POS,MODE_TRADES);
Why are you getting the TimeCurrent multiple times in a for loop?- Why is there a brace ("{") not connected to something?
- The for loop has ended, (i == -1) so the OrderSelect will ALWAYS fail.
- What are Function return values ? How do I use them ? - MQL4 forum
OrderSelect(i, SELECT_BY_POS,MODE_TRADES); if(OrderSymbol()==Symbol()) if(Period()==PERIOD_H1) if(OrderType==OP_BUY) { Rhigh=.. if(Rhigh- if((Low[i OrderModify(OrderTi return(0); } if(OrderType==OP_SELL) {
You check if the selected order is the chart symbol, and EA is on the H1, and the type is a buy before modifying. This means you modify ALL buy orders for the current symbol, but you modify ALL sell orders. Incompatible with every other EA and manual trading. Learn to use magic numbers. Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forumRhigh=High[iHighest(Symbol(),PERIOD_H1,MODE_HIGH, count(), 0]; 1 2? 33 33 2?1 unbalanced left parenthesis 2
OrderModify(OrderTicket(), OrderOpenPrice(), 1 22 22 Low[iHighest(Symbol(),PERIOD_H1,MODE_HIGH,count,0]-(PipsToTrail*Point), 3 4? 55 4? 3 2 2 OrderTakeProfit(),0,CLR_NONE); 22 1 // unbalanced left parenthesis 4
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Please I need with the below lines of mql4 codes. It fails to compile and returns the error "'\end_of_program' - unbalanced left parenthesis".
//--- input parameters
extern int WhenToStartTrailing=60;
extern int PipsToTrail=10;
double Rhigh ;
double Rlow ;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
for (int i=OrdersTotal()-1; i>=0; i--)
int CurrentTime = TimeHour(TimeCurrent());
int OpenTime = TimeHour(OrderOpenTime());
int count = CurrentTime - OpenTime
{
OrderSelect(i, SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol())
if(Period()==PERIOD_H1)
if(OrderType==OP_BUY)
{
Rhigh=High[iHighest(Symbol(),PERIOD_H1,MODE_HIGH,count(),0];
if(Rhigh-OrderOpenPrice >= (WhenToStartTrailing*Point))
if((Low[iHighest(Symbol(),PERIOD_H1,MODE_HIGH,count(),0]-(PipsToTrail*Point)) > OrderStopLoss)
OrderModify(OrderTicket(),OrderOpenPrice(),Low[iHighest(Symbol(),PERIOD_H1,MODE_HIGH,count,0]-(PipsToTrail*Point),OrderTakeProfit(),0,CLR_NONE);
return(0);
}
if(OrderType==OP_SELL)
{
Rlow=Low[iLowest(Symbol(),PERIOD_H1,MODE_LOW,count(),0];
if(OrderOpenPrice-Rlow >= WhenToStartTrailing*Point)
if((High[iLowest(Symbol(),PERIOD_H1,MODE_HIGH,count(),0]+(PipsToTrail*Point) < OrderStopLoss)|| OrderStopLoss = 0)
OrderModify(OrderTicket(),OrderOpenPrice(),High[iLowest(Symbol(),PERIOD_H1,MODE_HIGH,count,0]+(PipsToTrail*Point),OrderTakeProfit(),0,CLR_NONE);
return(0);
}
return(0);
}