Hello all!
Need some help/ideas. I have a list of Buys in csv: Data, Time (hh:mm), Ticker. I need to get some statistic from a bar I made an entry and test different exit strategy. So I want to create some script that takes csv, read it and go through all trades, finds the entry bar and:
Exactly this is described in KB: http://www.amibroker.com/kb/2014/09/30/gen-backtest-from-a-file/
Hello all
Sorry if it is the duplicate of the post…It is my first post on that site. So when I type previous one, I accidentally click Enter and …it goes to approval or not…
Anyway, I need some help from the community.
I need to read trades from CSV. I’ve found the article http://www.amibroker.com/kb/2014/09/30/gen-backtest-from-a-file/
But as I understand, I must keep symbol I want to check as a Current Symbol. But I would like to go through WatchList and find all my trades in all that symbols and test them. It is very complicated for me to open each symbol and test individually.
So: if ( Name() == sym )
How should I change that condition?
Did you actually try running the AFL on the page that you referenced to see what it does? If so, what problems are you encountering?
I'm getting not what I really want. Let me give some example what I try to do.
I have CSV file:
Symbol,Date,Time
FTFT_1,1/10/2018,11:50:28
FTFT_1,1/25/2018,14:00:45
FTFT_1,12/21/2017,9:45:19
FTFT_1,12/22/2017,14:00:25
FTFT_1,12/22/2017,14:40:54
FTFT_1,12/22/2017,14:46:24
FTFT_1,12/26/2017,9:37:14
KONE_1,11/16/2017,10:11:34
KONE_1,11/16/2017,10:16:54
KONE_1,12/19/2017,09:50:09
KONE_1,12/19/2017,09:55:45
And I want to get some statistic using Explore and backtest different exits. So I need to find symbol, date, time and make a Buy and based on some condition make sell. I tried to do it
t = TimeNum();
//
Buy = Sell = 0;
fh = fopen( file, "r" );
//
position = 0;
if( fh )
{
while( ! feof( fh ) )
{
line = fgets( fh );
// get the ticker symbol from the file
sym = StrExtract( line, 0 );
// if ticker matches current symbol
if ( Name() == sym )
{
// extract data from line of text
trade_datetime = StrToDateTime( StrExtract( line, 1 ) );
time = StrToDateTime( StrExtract( line, 2 ) );
//
if ( dt[count] == trade_datetime[count] )
{
if (t == time) {
position = 1;
Buy = 1;
BuyPrice = C;
Filter = Buy;
AddColumn(V,"V");
AddColumn(MA(V,20),"MA_V");
AddColumn(MA(C,9),"MA_C");
}
}
if (position == 1) {
// Sell condition
}
}
}
//
fclose( fh );
}
else
{
Error( "ERROR: file can not be open" );
}
//```
But it does not work. I tried different ways but got errors or very strange result. What should I fix here?
Hi,
I am using the script in the KB article, http://www.amibroker.com/kb/2014/09/ , to load a list of trades in a CSV. Below is the first few lines of the csv:
Symbol,Trade,Date,Price,Shares
SPXW_20140930_1880p,Short,9/8/2014,2.325,53762
SPXW_20140930_1880p,Cover,9/30/2014,0,53762
SPXW_20140930_1820p,Buy,9/8/2014,1.25,53762
VIX,Buy,9/8/2014,12.66,78988
In the third line, the option trade expires at 0.00 since it is 100 points away from the market. However, on 9/30/2014, the OHLC of the bar os 0.05. When AmiBroker is re-creating the historical file it is using the 0.05 as the last and closing price, not the 0.00 I have written to the csv.
How can I code it so that the backtester will use my value of 0.00 from the csv and not the reported OHLC value of 0.05?
Thanks,
Mike
Use SetOption to turn off Price Bound Checking.
Hello, I'll use this old topic so I don't have to start a new one. Hopefully, the creator will forgive me.
I'm trying to import trades from CSV as per the instructions, the backtest is done, but many trades are missing in the backtest.
For example, 1.8.2022 shows only one trade, but I have more trades in CSV on the same day. See the image below:
Do you know where the problem might be?
I want to find out the exposure of my trades, do you think it's this good and AmiBroker will calculate the exposure for me?
Thank you for any help.