change in coding ver2.

 

Hello there;

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:
 
//| 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()

{
bool OrderSendResult;
// 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;}
/* Sizin Kodunuz
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;
}
*/ 
// Düzeltilmil Kod
if (trade && tradingHour()){
if(iClose(NULL, PERIOD_M30, 1) > iClose(NULL, PERIOD_M30, 2)){ // Condition for buy order
OrderSendResult=OrderSend(Symbol(),OP_BUY,LOT,Ask,2,Bid-Stoploss*Point,Ask+Profit*Point,NULL,0123456,0,clrRed);
}
else if(iClose(NULL, PERIOD_M30, 1) < iClose(NULL, PERIOD_M30, 2)){ // Condition for sell order
OrderSendResult=OrderSend(Symbol(),OP_SELL,LOT,Bid,2,Ask+Stoploss*Point,Bid-Profit*Point,NULL,0123456,0,clrRed);
}
trade=false;
}

int tot=OrdersTotal();

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

{
OrderSendResult=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

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

{

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

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

}

}

}

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

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

Hello there;

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.

@ barkes

 

Well, if I want to operate on M15 only at 11:15 am I need to change which code.

Thanks...

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