change in coding. - page 2

 
barkes:

I have deleted your last post.

Take note of what you have already been told.

Keith Watford:
Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.

Please remove all the unnecessary empty lines to make it easier for others to read.

 

i have tryed but the problem is the same. there is a one false in the system.

//+------------------------------------------------------------------+

//|                                                     baris.mq4 |

//|                        Copyright 2014, MetaQuotes Software Corp. |

//|                                              http://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2014, MetaQuotes Software Corp."

#property link      "http://www.mql5.com"

#property version   "2.00"

#property strict

extern double LOT=0.01;

extern int Profit=100;

extern int Stoploss=150;

int bars;

bool trade;

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

trade=false;

bars=iBars(Symbol(),PERIOD_D1);

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//---

  }

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

void OnTick()

  {
    // auto lot
    int count = 1;
    static double autoLot = LOT;
    while(AccountBalance() > 100.0*count){
      LOT = autoLot*count;
      count++;
    }

bool tradingHour(){
  bool hour = false;
  if(Hour() >= 10 && Hour() < 22){
    hour = true;
  }
  return hour;
}

if (bars!=iBars(Symbol(),PERIOD_D1)){bars=iBars(Symbol(),PERIOD_D1);trade=true;}

if (trade){
            if(iClose(NULL, PERIOD_D1, 1) > iClose(NULL, PERIOD_D1, 2)){     // Condition for buy order
              OrderSend(Symbol(),OP_BUY,LOT,Ask,2,Bid-Stoploss*Point,0,NULL,0123456,0,clrRed);
            }
            else if(iClose(NULL, PERIOD_D1, 1) < iClose(NULL, PERIOD_D1, 2)){ // Condition for sell order
              OrderSend(Symbol(),OP_SELL,LOT,Bid,2,Ask+Stoploss*Point,0,NULL,0123456,0,clrRed); 
            }
            trade=false;
          }
  int tot=OrdersTotal(); 
  for(int i=0; i<=tot;i++)
  {OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   if (OrderSymbol()==Symbol() &&OrderMagicNumber()==0123456)

      {

       if(OrderType()==OP_BUY){if (Bid>= OrderOpenPrice()+Profit*Point)OrderClose(OrderTicket(),LOT,Bid,2,clrAqua);}
       if(OrderType()==OP_SELL){if (Ask<= OrderOpenPrice()-Profit*Point)OrderClose(OrderTicket(),LOT,Ask,2,clrAqua);}

      }
  }
  }

//+------------------------------------------------------------------+
 

Hello there again;

I have a problem which is about this robot system. i have done all thing and robot is worked now but robot system is writing stoploss in system but is not writing takeprofit while i was doing backtest or real demo system. 

What can I do for it. I marked what I mean in the picture.

//| day open_baris.mq4 |

//| Copyright 2014, MetaQuotes Software Corp. |

//| http://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2014, MetaQuotes Software Corp."

#property link "http://www.mql5.com"

#property version "2.00"

#property strict

extern double LOT=0.01;

extern int Profit=100;

extern int Stoploss=150;

int bars;

bool trade;

//+------------------------------------------------------------------+

//| Expert initialization function |

//+------------------------------------------------------------------+

int OnInit()

{

trade=false;

bars=iBars(Symbol(),PERIOD_M30);

return(INIT_SUCCEEDED);

}

//+------------------------------------------------------------------+

//| Expert deinitialization function |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{

//---



}

//+------------------------------------------------------------------+

//| Expert tick function |

//+------------------------------------------------------------------+

void OnTick()

{
// auto lot
int count = 1;
static double autoLot = LOT;
while(AccountBalance() > 100.0*count){
LOT = autoLot*count;
count++;
}

if (bars!=iBars(Symbol(),PERIOD_M30)){bars=iBars(Symbol(),PERIOD_M30);trade=true;}



if (trade && tradingHour()){
if(iClose(NULL, PERIOD_M30, 1) > iClose(NULL, PERIOD_M30, 2)){ // Condition for buy order
OrderSend(Symbol(),OP_BUY,LOT,Ask,2,Bid-Stoploss*Point,0,NULL,0123456,0,clrRed);
}
else if(iClose(NULL, PERIOD_M30, 1) < iClose(NULL, PERIOD_M30, 2)){ // Condition for sell order
OrderSend(Symbol(),OP_SELL,LOT,Bid,2,Ask+Stoploss*Point,0,NULL,0123456,0,clrRed);
}
trade=false;
}

int tot=OrdersTotal();

for(int i=0; i<=tot;i++)

{OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if (OrderSymbol()==Symbol() &&OrderMagicNumber()==0123456)

{

if(OrderType()==OP_BUY){if (Bid>= OrderOpenPrice()+Profit*Point)OrderClose(OrderTicket(),LOT,Bid,2,clrAqua);}

if(OrderType()==OP_SELL){if (Ask<= OrderOpenPrice()-Profit*Point)OrderClose(OrderTicket(),LOT,Ask,2,clrAqua);}

}

}

}

//+------------------------------------------------------------------+

bool tradingHour(){
bool hour = false;
if(Hour() >= 11 && Minute() >= 30 && Hour() < 12){
hour = true;
}
return hour;
}
Files:
Reason: