In my back testing I am limiting my trade timings between 9am to before 3:30pm, you can see the statement below. But during back testing there are couple of trades executed even after 15:30. One example is shown below. Why it is happening? and how I can overcome this discrepancy?
hr = hour();
mi = minute();
TradeTime = (hr > 9) and (hr <= 15 and mi < 30);
buy = TradeTime and buy-rule;
short = TradeTime and sell-rule;
Symbol Trade Entry Exit Perf Profit Shares Pos. value Nb bars Perf/Bar MAE MFE Scale In Scale Out Exit type
First, your time rule prevents you from buying or selling any position if the number of minutes is lower than 30.
Plot "TradeTime" on a chart to get a visual confirmation.
You should use instead:
st1 = 9 * 60;
st2 = 15 * 60 + 30;
stnow = hour() * 60 + minute();
TradeTime = stnow > st1 and stnow < st2;
Regarding the trade that occurred after "15:30". This could happen because an order can be initiated at "15:30" or before and executed few bars after that.
Update your trading system, select "Settings -> Capital" then set a lower value for "Orders are valid for...".
Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.