Hello,
I am trying to write a code to export a csv file to be used by Interactive Brokers BasketTrader. I have two issues that I am unable to solve on my own. I would appreciate your help with those.
/// Example System
Buy = RSI(2) < 20 AND Close > MA(Close, 200);
Sell = RSI(2) > 80;
Short = RSI(2) > 80 AND Close < MA(Close, 200);
Cover = RSI(2) < 20;
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
LmtPrice = IIf(Buy, Close * 0.93, IIf(Short, Close * 1.07, 0));
StpPrice = IIf(Buy, Close * 0.83, IIf(Short, Close * 1.17, 0));
Action = WriteIf(Buy, "BUY", WriteIf(Short, "SELL", "0"));
/// Exploration
Filter = Buy OR Short;
AddtextColumn(Action, "Action");
AddColumn(LmtPrice, "LmtPrice");
AddColumn(StpPrice, "StpPrice");
/// Writing a csv file
fh = fopen( "c:\\AmibrokerDataExport\\Example.csv", "w");
if( fh )
{
fputs("Symbol,SecType,Exchange,Date,Action,TimeInForce,OrderType,UsePriceMgmtAlgo,LmtPrice,QuantityValue\n", fh);
fputs(Name() + "," + "STK,SMART/AMEX," + Date() + "," + Action + "," + "GTC,LMT,true," + StrFormat("%.2f", LmtPrice) + "," + StrFormat("%.0f", 100), fh);
fclose( fh );
}
- The first issue comes with the following line. I do not get why WriteIf does not recognise the Buy or Short case and displays the third case 0.
Action = WriteIf(Buy, "BUY", WriteIf(Short, "SELL", "0"));
- The second issue is related with the csv exportation. The present code gives just one line, for the last day in range of the last symbol evaluated (there is no buy or short signal for that day and symbol).
Could you give me some orientation to keep working? I would need the code to provide a csv list that
a) contains only the lines corresponding to buy or short signals for b) all the symbols in the exploration list.
Thank you in advance for your help.
Regards.