need help! EA does not work!

 
int PrevBars;
double tp_buy_ord1,sl_buy_ord1,tp_sell_ord1,sl_sell_ord1,pipekolly,pipekolly1,tp_buy_ord2,tp_sell_ord2,tp_doubled,price_ord1,roundpipekolly;

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

// exported variables
extern bool FiveDigitBroker1 = false;
extern bool ClearAllObjects1 = false;



// 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

datetime BarTime1 = 0;


int init()
{
    PrevBars=iBars(Symbol(),Period());
    NDigits = Digits;
    
    if (ClearAllObjects1) ObjectsDeleteAll();      // clear the chart
    
    
    Comment("");    // clear the chart
}

// Expert start
int start()
{
    if (Bars < 10)
    {
        Comment("Not enough bars");
        return (0);
    }
    
    OnEveryNewBar1();
    
}

void OnEveryNewBar1()
{
    if (BarTime1 < Time[0])
    {
        // we have a new bar opened
        BarTime1 = Time[0]; // keep the new bar open time      
        
        SellOrder1();
        BuyPendingOrder1();
        BuyOrder1();
        SellPendingOrder1();
        
    }                    
}


void SellOrder1()
{

                      pipekolly= MathAbs(iClose(Symbol(),Period(),1)-iOpen(Symbol(),Period(),1))*10000;
                      roundpipekolly= MathRound(pipekolly);
              
                      if(15>pipekolly>4.5)
                      {
                            if(iClose(Symbol(),Period(),1)>iOpen(Symbol(),Period(),1))//BULLISH
                            {
    int ticket = -1;
          pipekolly1= pipekolly/10000;
          tp_doubled=pipekolly1*2;
          tp_sell_ord1=iOpen(Symbol(),Period(),1);
          sl_sell_ord1=tp_sell_ord1+tp_doubled; 
          tp_sell_ord2=sl_sell_ord1+pipekolly1;
          price_ord1=iClose(Symbol(),Period(),1);
    if (true)
    ticket = OrderSend(Symbol(),OP_SELL,0.04,Bid,0,sl_sell_ord1,tp_sell_ord1,PrevBars+"-SELL",0,0,CLR_NONE);
    else
    ticket = OrderSend(Symbol(),OP_SELL,0.04,Bid,0,sl_sell_ord1,tp_sell_ord1,PrevBars+"-SELL",0,0,CLR_NONE);
    if (ticket > -1)
    {
        if (true)
        {
            OrderSelect(ticket, SELECT_BY_TICKET);
            bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), roundpipekolly, roundpipekolly, 0, Blue);
            if (ret == false)
            Print("OrderModify() error - ", ErrorDescription(GetLastError()));
        }
            
    }
    else
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
              //if(15>pipekolly>4.5);
                      }
                      else if(pipekolly>15)
                      {
                      Alert("Profit is more than 15pip, Farrokh say STOP!");
                      }
                      else if(pipekolly<4.5)
                      {
                      Alert("Profit is less than 4.5 pip. Farrokh says STOP!");
                      }        
                            //if(iClose(Symbol(),Period(),1)>iOpen(Symbol(),Period(),1));
                            }
}

void BuyPendingOrder1()
{
                        //codhaye marbut b khodam baraye if
                      pipekolly= MathAbs(iClose(Symbol(),Period(),1)-iOpen(Symbol(),Period(),1))*10000;
                      roundpipekolly= MathRound(pipekolly);
              
                      if(15>pipekolly>4.5)
                      {
                            if(iClose(Symbol(),Period(),1)>iOpen(Symbol(),Period(),1))
                            {
                            
    int expire = TimeCurrent() + 60 * 0;
    if (0 == 0) expire = 0;

       int ticket = OrderSend(Symbol(),OP_BUYSTOP,0.08,sl_sell_ord1,0,price_ord1,tp_sell_ord2,PrevBars+"-SELL",0,0,CLR_NONE);
    if (ticket == -1)
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
    
              //if(15>pipekolly>4.5);
                      }
                      else if(pipekolly>15)
                      {
                      Alert("Profit is more than 15pip, Farrokh say STOP!");
                      }
                      else if(pipekolly<4.5)
                      {
                      Alert("Profit is less than 4.5 pip. Farrokh says STOP!");
                      }
                            //if(iClose(Symbol(),Period(),1)>iOpen(Symbol(),Period(),1));
                            }
}


                            
void BuyOrder1()
{
                      pipekolly= MathAbs(iClose(Symbol(),Period(),1)-iOpen(Symbol(),Period(),1))*10000;
                      roundpipekolly= MathRound(pipekolly);
              
                      if(15>pipekolly>4.5)
                      {
                            if(iClose(Symbol(),Period(),1)<iOpen(Symbol(),Period(),1))//BEARISH BAR
                            {

    int ticket = -1;
    
          pipekolly1= pipekolly/10000;
          tp_doubled=pipekolly1*2;
          tp_buy_ord1=iOpen(Symbol(),Period(),1); //Bid-pipekolly;
          sl_buy_ord1=tp_buy_ord1-tp_doubled;
          tp_buy_ord2=sl_buy_ord1-pipekolly1;
          price_ord1=iClose(Symbol(),Period(),1);
    if (true)
    ticket = OrderSend(Symbol(),OP_BUY,0.04,Ask,0,sl_buy_ord1,tp_buy_ord1,PrevBars+"-BUY",0,0,CLR_NONE);
    else
    ticket = OrderSend(Symbol(),OP_BUY,0.04,Ask,0,sl_buy_ord1,tp_buy_ord1,PrevBars+"-BUY",0,0,CLR_NONE);
    if (ticket > -1)
    {
        if (true)
        {
            OrderSelect(ticket, SELECT_BY_TICKET);
            bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), roundpipekolly, roundpipekolly, 0, Blue);
            if (ret == false)
            Print("OrderModify() error - ", ErrorDescription(GetLastError()));
        }
            
    }
    else
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
                  //if(15>pipekolly>4.5);
                      }
                      else if(pipekolly>15)
                      {
                      Alert("Profit is more than 15pip, Farrokh say STOP!");
                      }
                      else if(pipekolly<4.5)
                      {
                      Alert("Profit is less than 4.5 pip. Farrokh says STOP!");
                      }
                            //if(iClose(Symbol(),Period(),1)<iOpen(Symbol(),Period(),1));
                            }
}

void SellPendingOrder1()
{

                      pipekolly= MathAbs(iClose(Symbol(),Period(),1)-iOpen(Symbol(),Period(),1))*10000;
                      roundpipekolly= MathRound(pipekolly);
              
                      if(15>pipekolly>4.5)
                      {

                            if(iClose(Symbol(),Period(),1)<iOpen(Symbol(),Period(),1))//bar Ghermez
                            {
                            
    int expire = TimeCurrent() + 60 * 0;
    if (0 == 0) expire = 0;

       int ticket = OrderSend(Symbol(),OP_SELLSTOP,0.08,sl_buy_ord1,0,price_ord1,tp_buy_ord2,PrevBars+"-BUY",0,0,CLR_NONE);
    if (ticket == -1)
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
                  //if(15>pipekolly>4.5);
                      }
                      else if(pipekolly>15)
                      {
                      Alert("Profit is more than 15pip, Farrokh say STOP!");
                      }
                      else if(pipekolly<4.5)
                      {
                      Alert("Profit is less than 4.5 pip. Farrokh says STOP!");
                      }
                            //if(iClose(Symbol(),Period(),1)<iOpen(Symbol(),Period(),1));
                            }
                            
}


int deinit()
{
    if (ClearAllObjects1) ObjectsDeleteAll();
    
    
}

 
farrokhfa:

Perhaps you could mention in what way the EA "does not work", does not compile ? crashes when run ? will not open trades ? opens too many trades ? incorrect MM ? what exactly "does not work" mean ?
 
RaptorUK:
Perhaps you could mention in what way the EA "does not work", does not compile ? crashes when run ? will not open trades ? opens too many trades ? incorrect MM ? what exactly "does not work" mean ?


it doesn't open trades and the smiley is upset :(.
 
farrokhfa:

it doesn't open trades and the smiley is upset :(.

You have to enable live trading in Expert advisors parameters
 
RaptorUK:
Perhaps you could mention in what way the EA "does not work", does not compile ? crashes when run ? will not open trades ? opens too many trades ? incorrect MM ? what exactly "does not work" mean ?

This makes no sense . . .

if(15 > pipekolly > 4.5)

Read this thread: https://www.mql5.com/en/forum/141790


Why do this ?

if(iClose(Symbol(),Period(),1)>iOpen(Symbol(),Period(),1))//BULLISH

when this is the same and faster ?

if( Close[1]) > Open[1] ) //BULLISH


What is the point of this ?

if (0 == 0) expire = 0;

when do you think 0 is not equal to 0 ?

and this . . .

if (true)

when is true ever not true ? why is the if needed ?

 
RaptorUK:

This makes no sense . . .

Read this thread: https://www.mql5.com/en/forum/141790


Why do this ?

when this is the same and faster ?


What is the point of this ?

when do you think 0 is not equal to 0 ?

and this . . .

when is true ever not true ? why is the if needed ?


I took care of everything you mentioned:

if(15>pipekolly && pipekolly>4.5)
if(Close[1]>Open[1])

and also deleted that two if but it does not open trades.

 

FWIW sometimes I use

various forms of

if (true) {
if (false) {
 
when debugging. To make a block of code always/never fire. Advantage over using multi-line comments is that it works with different nested levels, it works if multi-line comments already present in the code block... easy to find them and deactivate them with a single word change (compared to multi-line comments unless you dont use multi-line comments for anything else), when finished testing. However given other errors in the code this might not be the case!This is just a personal style thing for me, that I've found useful over the years (with C its even shorter - if(0) or #if 0 ) and I dont always use it, mainly if temporarily deactivating a large block of code that already has multi-line comments..
 
farrokhfa:

I took care of everything you mentioned:

and also deleted that two if but it does not open trades.

What happens when you run it in the Strategy Tester ?
 
RaptorUK:
What happens when you run it in the Strategy Tester ?


No order took palce and result is zero.
 

Your OrderModify() will fail . . .

bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), roundpipekolly, roundpipekolly, 0, Blue);

roundpipekolly comes from here . . .

pipekolly= MathAbs(iClose(Symbol(),Period(),1)-iOpen(Symbol(),Period(),1))*10000;
roundpipekolly= MathRound(pipekolly);

and looks like it is in pips or points . . . TP and SL in your OrderModify() need to be prices and can't be the same value.

 
farrokhfa:

No order took palce and result is zero.
And what messages do you get in the log/journal tab ?