Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.
From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.
Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
Elite Section
Get access to private discussions, specialized support, indicators and trading systems reported every week.
Advanced Elite Section
For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
GetLastOpenTime function gets OpenTime of the last order with predefined type.
The function makes a search of open trades and the history.
-1 means there are no orders found.
This is a very informative thread..Please do not stop..Continue teaching us who are new to this programming...
How do i code this procedure???
1. I want to open 3 trades in 3 different chart only after checking that there is not trade open at the moment then ...
2. I want to check the PL and if it is greater then 0, it will close all open and pending orders.
3. Then I want to open the same 3 trades in the opposite directions.
Thanks
ok.
1. I want to open 3 trades in 3 different chart only after checking that there is not trade open at the moment then ...
3. Then I want to open the same 3 trades in the opposite directions.
Code:
int Magic = ...
int BuyCnt = 0;
int SellCnt = 0;
int cnt = OrdersTotal();
for (int i=0; i < cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderMagicNumber() != Magic) continue;
int type = OrderType();
if (type == OP_BUY) BuyCnt++;
if (type == OP_SELL) SellCnt++;
}
if (BuyCnt > 0 || SellCnt > 0) return;
//OrderSend(OP_BUY, ...
//OrderSend(OP_SELL, ...
Run this code on 3 different charts you need.
2. I want to check the PL and if it is greater then 0, it will close all open and pending orders.
Code:
if (AccountProfit() > 0)
{
DeleteOrders();
CloseOrders();
}
void CloseOrders()
{
int cnt = OrdersTotal();
for (int i=cnt-1; i >= 0; i--)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
int type = OrderType();
if (type == OP_BUY)
{
RefreshRates();
OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 3);
}
if (type == OP_SELL)
{
RefreshRates();
OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 3);
}
}
}
void DeleteOrders()
{
int cnt = OrdersTotal();
for (int i=cnt-1; i >= 0; i--)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
int type = OrderType();
if (type == OP_BUYSTOP || type == OP_SELLSTOP || type == OP_BUYLIMIT || type == OP_SELLLIMIT)
{
OrderDelete(OrderTicket());
}
}
}