Hello,
I am having problems with part of my code. the breakeven part of the code is working how it should, however the takeprofit modify part is not working correctly.
Here is what I want the following code to perform.
If I have more then 1 open order I want the loop to modify all orders to the new orders takeprofit value.
recentpricebuy() is a function that obtains the most recent price's orderopenprice.
recentpricesell() is the same function except for sell orders.
I am having problems with part of my code. the breakeven part of the code is working how it should, however the takeprofit modify part is not working correctly.
Here is what I want the following code to perform.
If I have more then 1 open order I want the loop to modify all orders to the new orders takeprofit value.
recentpricebuy() is a function that obtains the most recent price's orderopenprice.
recentpricesell() is the same function except for sell orders.
Inserted Code
void MonitorTrades()
{
int ticket;
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
{
if (OrderType()==OP_BUY)
{
if (Bid >= (OrderOpenPrice()+(BreakEven*Point)) && OrderStopLoss()<OrderOpenPrice())
{
ticket = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+(BreakEvenProfit*Point),OrderTakeProfit(),0,CLR_NONE);
if (ticket>0 && ShowAlerts==true) Alert("Breakeven set on ", OrderSymbol(), " ticket no ", OrderTicket());
}
if (OrderTakeProfit()<recentpricebuy()+(TakeProfit*Point))
{
ticket = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),recentpricebuy()+(TakeProfit*Point),0,CLR_NONE);
if (ticket>0 && ShowAlerts==true) Alert("TakeProfit set on ", OrderSymbol(), " ticket no ", OrderTicket());
}
}
if (OrderType()==OP_SELL)
{
if (Ask <= (OrderOpenPrice()-(BreakEven*Point)) && OrderStopLoss()>OrderOpenPrice())
{
ticket = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-(BreakEvenProfit*Point),OrderTakeProfit(),0,CLR_NONE);
if (ticket>0 && ShowAlerts==true) Alert("Breakeven set on ", OrderSymbol(), " ticket no ", OrderTicket());
}
if (OrderTakeProfit()>recentpricesell()-(TakeProfit*Point))
{
ticket = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),recentpricesell()-(TakeProfit*Point),0,CLR_NONE);
if (ticket>0 && ShowAlerts==true) Alert("TakeProfit set on ", OrderSymbol(), " ticket no ", OrderTicket());
}
}
}
}
}