I have coded a simple EA to manage my stoploss and takeprofit. I am a manual trader. I did this because it is a hassle for me to every time have to set the takeprofit and stoploss. I have attached my code. Thanks in advance.
Inserted Code
extern int StopLoss = 10;
extern int TakeProfit = 50;
double point;
int init()
{
if (Digits==2)point=0.01;
if (Digits==3)point=0.01;
if (Digits==4)point=0.0001;
if (Digits==5)point=0.0001;
return(0);
}
int deinit()
{
return(0);
}
int OrderCount(int type)
{
int buycnt,sellcnt;
for (int i=OrdersTotal()-1;i>=0;i--)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if (OrderSymbol()==Symbol())
{
if (OrderType()==OP_BUY)buycnt=buycnt+1;
if (OrderType()==OP_SELL)sellcnt=sellcnt+1;
}
}
}
if (type==0)return(buycnt);
else if (type==1)return(sellcnt);
else if (type==3)return(buycnt+sellcnt);
else return(0);
}
//--------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------
void verifyStoploss()
{
double buystoploss, sellstoploss, buyTakeprofit, sellTakeprofit;
buystoploss=Bid-StopLoss*point;
buyTakeprofit=Ask+TakeProfit*point;
sellstoploss=Ask+StopLoss*point;
sellTakeprofit=Bid-TakeProfit*point;
if (OrderCount(0)>0 && (OrderStopLoss() < Point || OrderTakeProfit() < Point) ) //if they are not set
{
OrderModify(OrderTicket(), OrderOpenPrice(), buystoploss, buyTakeprofit, OrderExpiration(), CLR_NONE);
Sleep(3000);
}
if (OrderCount(1)>0 && (OrderStopLoss() < Point || OrderTakeProfit() < Point) )
{
OrderModify(OrderTicket(), OrderOpenPrice(), sellstoploss, sellTakeprofit, OrderExpiration(), CLR_NONE);
Sleep(3000);
}
}
int start()
{
verifyStoploss();
return(0);
}