Navigation´╝ÜHome > Content >

TrendSignEA_v0.1.mq4

Time: 2016-10-01 | Download file:TrendSignEA_v0.1.mq4

//===========================================================================================================================================//

#property copyright ""
#property link      ""

#include 
#include 
//===========================================================================================================================================//
// exported variables
extern double BuyLots6 = 0.1;
extern int BuyStoploss6 = 20;
extern int BuyTakeprofit6 = 30;
extern double SellLots16 = 0.1;
extern int SellStoploss16 = 20;
extern int SellTakeprofit16 = 30;
//===========================================================================================================================================//
// 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;

datetime BarTime4 = 0;
datetime BarTime12 = 0;
//===========================================================================================================================================//
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);
    }
    
    OnEveryTick1();
    
}
//===========================================================================================================================================//
void OnEveryTick1()
{
    if (true == false && true) PipValue = 10;
    if (true && (NDigits == 3 || NDigits == 5)) PipValue = 10;
    
    TechnicalAnalysis2();
    TechnicalAnalysis10();
    
}
//===========================================================================================================================================//
void TechnicalAnalysis2()
{
    if (iCustom(NULL, NULL, "trendsignal",3,3500000,0,false,0,1) > 0)
    {
        OncePerBar4();
        
    }
}
//===========================================================================================================================================//
void OncePerBar4()
{
    
    if (BarTime4 < Time[0])
    {
        // we have a new bar opened
        BarTime4 = Time[0]; // keep the new bar open time
        IfOrderDoesNotExist5();
        
    }
}
//===========================================================================================================================================//
void IfOrderDoesNotExist5()
{
    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() == 0)
        {
            exists = true;
        }
    }
    else
    {
        Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    }
    
    if (exists == false)
    {
        BuyOrder6();
        
    }
}
//===========================================================================================================================================//
void BuyOrder6()
{
    double SL = Ask - BuyStoploss6*PipValue*Point;
    if (BuyStoploss6 == 0) SL = 0;
    double TP = Ask + BuyTakeprofit6*PipValue*Point;
    if (BuyTakeprofit6 == 0) TP = 0;
    int ticket = -1;
    if (true)
    ticket = OrderSend(Symbol(), OP_BUY, BuyLots6, Ask, 2, 0, 0, "My Expert", 0, 0, Blue);
    else
    ticket = OrderSend(Symbol(), OP_BUY, BuyLots6, Ask, 2, SL, TP, "My Expert", 0, 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()));
    }
}
//===========================================================================================================================================//
void TechnicalAnalysis10()
{
    if (iCustom(NULL, NULL, "trendsignal",3,3500000,0,false,1,1) > 0)
    {
        OncePerBar12();
        
    }
}
//===========================================================================================================================================//
void OncePerBar12()
{
    
    if (BarTime12 < Time[0])
    {
        // we have a new bar opened
        BarTime12 = Time[0]; // keep the new bar open time
        IfOrderDoesNotExist14();
        
    }
}
//===========================================================================================================================================//
void IfOrderDoesNotExist14()
{
    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)
    {
        SellOrder16();
        
    }
}
//===========================================================================================================================================//
void SellOrder16()
{
    double SL = Bid + SellStoploss16*PipValue*Point;
    if (SellStoploss16 == 0) SL = 0;
    double TP = Bid - SellTakeprofit16*PipValue*Point;
    if (SellTakeprofit16 == 0) TP = 0;
    int ticket = -1;
    if (true)
    ticket = OrderSend(Symbol(), OP_SELL, SellLots16, Bid, 2, 0, 0, "My Expert", 1, 0, Red);
    else
    ticket = OrderSend(Symbol(), OP_SELL, SellLots16, Bid, 2, 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()));
    }
}
//===========================================================================================================================================//
int deinit()
{
    if (false) ObjectsDeleteAll();
    
    
}
//===========================================================================================================================================//

Recommend