Download MetaTrader 5
To add comments, please log in or register
All MQL5.community events are grouped together. Have a look at the Wall!
Vivek Vyas
203
Vivek Vyas 2014.05.10 17:32 
This is the code-error"354:1;'\end_of_program' - unbalanced left parenthesis"
//-------------------------------------------------------------
//  Etasoft Inc. Forex EA and Script Generator version 4.1   EA
//-------------------------------------------------------------
// Keywords: MT4, Forex EA builder, create EA, expert advisor developer

#property copyright "Copyright © 2011, Etasoft Inc. Forex EA Generator v4.1"
#property link      "http://www.forexgenerator.com/"

#include <stdlib.mqh>
#include <WinUser32.mqh>

// exported variables
extern double SellLots15 = 0.1;
extern double BuyLots16 = 0.1;


// local variables
double PipValue=1;    // this variable is here to support 5-digit brokers
bool Terminated = false;
string LF = "\n";  // use this in custom or utility blocks where you need line feeds
int NDigits = 4;   // used mostly for NormalizeDouble in Flex type blocks
int ObjCount = 0;  // count of all objects created on the chart, allows creation of objects with unique names
int current = 0;

bool FirstTime22 = true;
bool FirstTime21 = true;


int init()
{
    NDigits = Digits;
    
    if (false) ObjectsDeleteAll();      // clear the chart
    
    
    Comment("");    // clear the chart
}

// Expert start
int start()
{
    if (Bars < 10)
    {
        Comment("Not enough bars");
        return (0);
    }
    if (Terminated == true)
    {
        Comment("EA Terminated.");
        return (0);
    }
    
    OnEveryTick25();
    
}

void OnEveryTick25()
{
    if (true == false && false) PipValue = 10;
    if (true && (NDigits == 3 || NDigits == 5)) PipValue = 10;
    
    TechnicalAnalysis14();
    TechnicalAnalysis13();
    
}

void TechnicalAnalysis14()
{
    if (iCustom(NULL, NULL, "SnakeForce",24,1,0 < 0)
    {
        CloseOrder23();
        CheckLastOrderType22();
        
    }
}

void CloseOrder23()
{
    int orderstotal = OrdersTotal();
    int orders = 0;
    int ordticket[30][2];
    for (int i = 0; i < orderstotal; i++)
    {
        OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
        if (OrderType() != OP_BUY || OrderSymbol() != Symbol() || OrderMagicNumber() != 1)
        {
            continue;
        }
        ordticket[orders][0] = OrderOpenTime();
        ordticket[orders][1] = OrderTicket();
        orders++;
    }
    if (orders > 1)
    {
        ArrayResize(ordticket,orders);
        ArraySort(ordticket);
    }
    for (i = 0; i < orders; i++)
    {
        if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)
        {
            bool ret = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 4, Red);
            if (ret == false)
            Print("OrderClose() error - ", ErrorDescription(GetLastError()));
        }
    }
    
}

void CheckLastOrderType22()
{
    int orderType = -1;
    datetime lastCloseTime = 0;
    int cnt = OrdersHistoryTotal();
    for (int i=0; i < cnt; i++)
    {
        if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
        if (OrderSymbol() == Symbol() && lastCloseTime < OrderCloseTime())
        {
            lastCloseTime = OrderCloseTime();
            orderType = OrderType();
        }
    }
    if (orderType == OP_BUY || FirstTime22)
    {
        FirstTime22 = false;
        IfOrderDoesNotExist19();
        
    }
}

void IfOrderDoesNotExist19()
{
    bool exists = false;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
        {
            exists = true;
        }
    }
    else
    {
        Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    }
    
    if (exists == false)
    {
        IfOrderDoesNotExist20();
        
    }
}

void IfOrderDoesNotExist20()
{
    bool exists = false;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
        {
            exists = true;
        }
    }
    else
    {
        Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    }
    
    if (exists == false)
    {
        SellOrderFlex15();
        
    }
}

void SellOrderFlex15()
{
    double SL = NormalizeDouble(iCustom(NULL, NULL, "Donchian Channels - Generalized version1",200,3,-2,0,1000,1,0), NDigits);
    if (iCustom(NULL, NULL, "Donchian Channels - Generalized version1",200,3,-2,0,1000,1,0) == 0) SL = 0;
    double TP = NormalizeDouble(iCustom(NULL, NULL, "Donchian Channels - Generalized version1",200,3,-2,0,1000,0,0)-25*Point, NDigits);
    if (iCustom(NULL, NULL, "Donchian Channels - Generalized version1",200,3,-2,0,1000,0,0)-25*Point == 0) TP = 0;
    int ticket = -1;
    if (true)
    ticket = OrderSend(Symbol(), OP_SELL, SellLots15, Bid, 4, 0, 0, "My Expert", 1, 0, Red);
    else
    ticket = OrderSend(Symbol(), OP_SELL, SellLots15, Bid, 4, SL, TP, "My Expert", 1, 0, Red);
    if (ticket > -1)
    {
        if (true)
        {
            OrderSelect(ticket, SELECT_BY_TICKET);
            bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Red);
            if (ret == false)
            Print("OrderModify() error - ", ErrorDescription(GetLastError()));
        }
            
    }
    else
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
}

void TechnicalAnalysis13()
{
    if (iCustom(NULL, NULL, "SnakeForce",24,0,0 > 0)
    {
        CloseOrder24();
        CheckLastOrderType21();
        
    }
}

void CloseOrder24()
{
    int orderstotal = OrdersTotal();
    int orders = 0;
    int ordticket[30][2];
    for (int i = 0; i < orderstotal; i++)
    {
        OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
        if (OrderType() != OP_SELL || OrderSymbol() != Symbol() || OrderMagicNumber() != 1)
        {
            continue;
        }
        ordticket[orders][0] = OrderOpenTime();
        ordticket[orders][1] = OrderTicket();
        orders++;
    }
    if (orders > 1)
    {
        ArrayResize(ordticket,orders);
        ArraySort(ordticket);
    }
    for (i = 0; i < orders; i++)
    {
        if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)
        {
            bool ret = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 4, Red);
            if (ret == false)
            Print("OrderClose() error - ", ErrorDescription(GetLastError()));
        }
    }
    
}

void CheckLastOrderType21()
{
    int orderType = -1;
    datetime lastCloseTime = 0;
    int cnt = OrdersHistoryTotal();
    for (int i=0; i < cnt; i++)
    {
        if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
        if (OrderSymbol() == Symbol() && lastCloseTime < OrderCloseTime())
        {
            lastCloseTime = OrderCloseTime();
            orderType = OrderType();
        }
    }
    if (orderType == OP_SELL || FirstTime21)
    {
        FirstTime21 = false;
        IfOrderDoesNotExist17();
        
    }
}

void IfOrderDoesNotExist17()
{
    bool exists = false;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
        {
            exists = true;
        }
    }
    else
    {
        Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    }
    
    if (exists == false)
    {
        IfOrderDoesNotExist18();
        
    }
}

void IfOrderDoesNotExist18()
{
    bool exists = false;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
        {
            exists = true;
        }
    }
    else
    {
        Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    }
    
    if (exists == false)
    {
        BuyOrderFlex16();
        
    }
}

void BuyOrderFlex16()
{
    double SL = NormalizeDouble(iCustom(NULL, NULL, "Donchian Channels - Generalized version1",200,3,-2,0,1000,0,0), NDigits);
    if (iCustom(NULL, NULL, "Donchian Channels - Generalized version1",200,3,-2,0,1000,0,0) == 0) SL = 0;
    double TP = NormalizeDouble(iCustom(NULL, NULL, "Donchian Channels - Generalized version1",200,3,-2,0,1000,1,0)+25*Point, NDigits);
    if (iCustom(NULL, NULL, "Donchian Channels - Generalized version1",200,3,-2,0,1000,1,0)+25*Point == 0) TP = 0;
    int ticket = -1;
    if (true)
    ticket = OrderSend(Symbol(), OP_BUY, BuyLots16, Ask, 4, 0, 0, "My Expert", 1, 0, Blue);
    else
    ticket = OrderSend(Symbol(), OP_BUY, BuyLots16, Ask, 4, SL, TP, "My Expert", 1, 0, Blue);
    if (ticket > -1)
    {
        if (true)
        {
            OrderSelect(ticket, SELECT_BY_TICKET);
            bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Blue);
            if (ret == false)
            Print("OrderModify() error - ", ErrorDescription(GetLastError()));
        }
            
    }
    else
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
}



int deinit()
{
    if (false) ObjectsDeleteAll();
    
    
}
euclid
34
euclid 2014.05.10 18:12  

Offending lines:

if (iCustom(NULL, NULL, "SnakeForce",24,1,0 < 0)

and

if (iCustom(NULL, NULL, "SnakeForce",24,0,0 > 0)
Vivek Vyas
203
Vivek Vyas 2014.05.11 08:15  
euclid:

Offending lines:

and



Thank you euclid for your kind help!!Now the code runs perfect!!
/
To add comments, please log in or register