Please help me...
Is there any way that we could open/close order with market price?
Is there any way that we could open/close order with market price?
I have the following code to manage my open trades in MT3. So far no problem, and functioning well. Hope this helps:
=================================================================
For cnt=1 to TotalTrades
{
mode=OrderValue(cnt,VAL_TYPE);
If mode=OP_BUY then
{
If (Bid-OrderValue(cnt,VAL_OPENPRICE))>(TS) then
{
If OrderValue(cnt,VAL_STOPLOSS)<(Bid-TS) then
{
ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),
Bid-TS,OrderValue(cnt,VAL_TAKEPROFIT),Yellow);
Exit;
};
};
};
If mode=OP_SELL then
{
If (OrderValue(cnt,VAL_OPENPRICE)-Ask)>(TS) then
{
If OrderValue(cnt,VAL_STOPLOSS)>(Ask+TS) then
{
ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),
Ask+TS,OrderValue(cnt,VAL_TAKEPROFIT),White);
Exit;
};
};
};
If mode>OP_SELL then
{
// check how long it exists in the trading terminal. Time is counted in seconds:
// 10 minutes = 600 seconds, 30 minutes = 1800, 1 hour = 3600, 1 day = 86400
If (Minute>58) then
{
DeleteOrder(OrderValue(cnt,VAL_TICKET),RED);
Exit;
};
};
=============================================================
=================================================================
For cnt=1 to TotalTrades
{
mode=OrderValue(cnt,VAL_TYPE);
If mode=OP_BUY then
{
If (Bid-OrderValue(cnt,VAL_OPENPRICE))>(TS) then
{
If OrderValue(cnt,VAL_STOPLOSS)<(Bid-TS) then
{
ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),
Bid-TS,OrderValue(cnt,VAL_TAKEPROFIT),Yellow);
Exit;
};
};
};
If mode=OP_SELL then
{
If (OrderValue(cnt,VAL_OPENPRICE)-Ask)>(TS) then
{
If OrderValue(cnt,VAL_STOPLOSS)>(Ask+TS) then
{
ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),
Ask+TS,OrderValue(cnt,VAL_TAKEPROFIT),White);
Exit;
};
};
};
If mode>OP_SELL then
{
// check how long it exists in the trading terminal. Time is counted in seconds:
// 10 minutes = 600 seconds, 30 minutes = 1800, 1 hour = 3600, 1 day = 86400
If (Minute>58) then
{
DeleteOrder(OrderValue(cnt,VAL_TICKET),RED);
Exit;
};
};
=============================================================
Thanks for your reply.
Do we have any easy way to open/close as market order instead of ModifyOrder and delete order?
Do we have any easy way to open/close as market order instead of ModifyOrder and delete order?
Sorry, perhaps I misunderstood. The above logic is to manage open orders by modifying the SL/TP level, i.e., trailing stops, or deleting an open orders which have been pending for 1hr. If you want to open/close order, simply use SetOrder/CloseOrder commands.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I am using FxDirectDealer is based on MT3. My expert advisor want to close the buy trade at the specific open price.
1. Does the CloseOrde have a return value on MT3? So we could know if the open order has been closed or not?
2. Can we CloseOrder with current market price?
3. If we can not use a close order to close the buy order, can we use the SellOrder(OP_SELLSTOP) with a higher than current market stop price to garunteen that we close the buy order?
Thanks a lot!!!