My original message was posted in the user contributed section but no one answer. Therefore, I post it again here to see anyone can give me some tips on how should I program my code.
I got problem in converting my coding for IOG use with backtesting work. Can someone hints me how to do it?
My original coding is using minute bar with a series of stop selling and buying price calculated at the end of each bar for next bar use. The EntryPrice of different transaction is calculated base on the historical price including last bar's close. It works perfect for my simple strategy when backtesting. Below is part of my coding without IOG.
Code: Select all
if condition3 and condition7 then begin
Sell short ("Open Short") NumContract contracts next bar EntryPrice1 stop;
end;
if condition3 then begin
Sell ("Close Long") from entry ("Open Long") next bar EntryPrice2 stop;
Sell ("Close Long A") from entry ("Open Long A") next bar EntryPrice2 stop;
end;
if condition4 and condition7 then begin
Buy ("Open Long") NumContract contracts next bar EntryPrice4 stop;
end;
if condition4 then begin
Buytocover("Close Short") from entry ("Open Short") next bar EntryPrice5 stop;
end;
if condition5 and condition7 then begin
Buy ("Open Long A") NumContract contracts next bar EntryPrice6 stop;
end;
There is no problem when I use IB demo account to test it. However, when I test in real, problems come. First thing is the slip which can be solved by using limit order. Second thing become a problem, IB inform me that I got too high cancellation rate. This is because my EntryPrice is set far above and below the current trading price, my strategy is trying to capture market abnormal so only 1 or 2 trading will occur every day but I submitted a new order with a new EntryPrice every minute. Therefore, I need to change my coding, below is my new coding.
Code: Select all
if condition3 and condition7 and Last <= EntryPrice1 then begin
Sell short ("Open Short") NumContract contracts next bar EntryPrice1 limit;
end;
if condition3 and Last <= EntryPrice2 then begin
Sell ("Close Long") from entry ("Open Long") next bar EntryPrice2 limit;
Sell ("Close Long A") from entry ("Open Long A") next bar EntryPrice2 limit;
end;
if condition4 and condition7 and Last >= EntryPrice4 then begin
Buy ("Open Long") NumContract contracts next bar EntryPrice4 limit;
end;
if condition4 and Last >= EntryPrice5 then begin
Buytocover("Close Short") from entry ("Open Short") next bar EntryPrice5 limit;
end;
if condition5 and condition7 and Last >= EntryPrice6 then begin
Buy ("Open Long A") NumContract contracts next bar EntryPrice6 limit;
end;
However, my conditions also depends on historically execution of the trade, I need to have the backtesting work properly in order to get the future execution correct. In my coding, because the keyword "Last" cannot use in backtesting. I cannot make the backtesting work correctly. Does any can hint me how can I do that? I cannot use bar magnifier because my instrument is custom instrument. I believe it should be very easy just I am not good in programming and MC only.