Hi,
I ve been on trying to create this trailing stop function for a day now but its not working. Can somebody here please take a look at this and let me know as to what is wrong.
The idea is
1. A buy order is placed with no stop loss or take profit. But the program does have the figures stored in 2 variables.
2. Now when the price reaches either of the levels the trade is closed.
Here is my function that is supposed to do that but its not working.
Values given here are for example only
S1Hold = 5; -----> This is the stoploss value.
TP1Hold = 15 -------> This is the take profit value.
iLots = 1 ---- > Lot size.
iTicket --------> is the Buy Ticket No.
The security is already bought at a price of 10.
I ve been on trying to create this trailing stop function for a day now but its not working. Can somebody here please take a look at this and let me know as to what is wrong.
The idea is
1. A buy order is placed with no stop loss or take profit. But the program does have the figures stored in 2 variables.
2. Now when the price reaches either of the levels the trade is closed.
Here is my function that is supposed to do that but its not working.
Values given here are for example only
S1Hold = 5; -----> This is the stoploss value.
TP1Hold = 15 -------> This is the take profit value.
iLots = 1 ---- > Lot size.
iTicket --------> is the Buy Ticket No.
The security is already bought at a price of 10.
PHP Code
void tsb()
{
if (iTicket > 0)
{
if (OrderSelect(iTicket, SELECT_BY_TICKET,MODE_TRADES))
{
if (Ask < OrderOpenPrice() && Ask <= S1Hold )
while (true)
{
{
OrderClose(OrderTicket(),iLots,Bid,3,CLR_NONE);
}
}
if (Ask > OrderOpenPrice() && Ask >= TP1Hold )
while (true)
{
{
OrderClose(OrderTicket(),iLots,Bid,3,CLR_NONE);
}
}
}
}
}