How can I tell my EA to close a trade if a profit is not hit after 12 candles. I am trading on the 1Hour timeframe and I only want the trade to be open for 24 hours. If it is not in profit, close trade.
The function fnGetOpenOrderInfo can be used to get the information you need:
(1) How long the trade has been opened
(2) If the trade is profitable
The fnGetOpenOrderInfo function is found in the Trade menu of the Function’s Toolbox:
To get the time the trade has been opened, select INFO_OPEN_MINUTES for the InfoType parameter, and give it a nice name like “TradeOpenMinutes”:
To get the prfot of the trade, select INFO_PROFIT for the InfoType parameter, ang give it a name like “TradeProfit”:
Now these two values can be used in a Logic Element. If the logic evaluates to True, the Trade is closed using the fnCloseOrder function:
The final drawing looks something like this:
VTS EA Package: Download and load this ZIP file into VTS
To get notified about the latest questions and answers, follow us!