Change Code Expert Adv.

 

Hello Everybody;

I have a expert which has to be code. my problem is the robot doesn't put Tp on target when opening a trade. When the price reaches the target, it closes. also not in SL. Is there anyone to help.

Files:
 
Baris Kesgin: I have a expert which has to be code. my problem is the robot doesn't put Tp on target when opening a trade. When the price reaches the target, it closes. also not in SL. Is there anyone to help.

The code is implementing a Virtual T/P and not a real server-side T/P. It also is not implementing S/L (virtual or real).

If you are looking for someone to make changes to your code, then consider filling out a job request in the Freelance section.

 
Baris Kesgin:

Hello Everybody;

I have a expert which has to be code. my problem is the robot doesn't put Tp on target when opening a trade. When the price reaches the target, it closes. also not in SL. Is there anyone to help.

You have sent this piece of code privately before and we have sent it to you in a working condition.


//New Codes;
bool ticket;
ticket=OrderSendResult=OrderSend(Symbol(),OP_BUY,LOT,Ask,2,0,Ask+Profit*Point,NULL,0123456,0,clrRed);
ticket=OrderSendResult=OrderSend(Symbol(),OP_SELL,LOT,Bid,2,0,Bid-Profit*Point,NULL,0123456,0,clrRed);

//old code posted by email
//| 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
input int   StartTimeHour=11;
input int   StartTimeMinute=15;

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_M15)){bars=iBars(Symbol(),PERIOD_M15);trade=true;}
/* Sizin Kodunuz
if (trade && tradingHour()){
if(iClose(NULL, PERIOD_M15, 1) > iClose(NULL, PERIOD_M15, 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_M15, 1) < iClose(NULL, PERIOD_M15, 2)){ // Condition for sell order
OrderSend(Symbol(),OP_SELL,LOT,Bid,2,Ask+Stoploss*Point,0,NULL,0123456,0,clrRed);
}
trade=false;
}
*/
// Düzeltilmis Kod
if (trade && tradingHour()){
if(iClose(NULL, PERIOD_M15, 1) > iClose(NULL, PERIOD_M15, 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_M15, 1) < iClose(NULL, PERIOD_M15, 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()==StartTimeHour && (Minute() >= StartTimeMinute && Minute()<=StartTimeMinute))
{
hour = true;
trade=true;
}
return hour;
}

bool ticket;
ticket=OrderSendResult=OrderSend(Symbol(),OP_BUY,LOT,Ask,2,0,Ask+Profit*Point,NULL,0123456,0,clrRed);
ticket=OrderSendResult=OrderSend(Symbol(),OP_SELL,LOT,Bid,2,0,Bid-Profit*Point,NULL,0123456,0,clrRed);
}
trade=false;
 
my route is different. This is not it. The codes you sent are different.
Reason: