Sorry if I offended you (sleep deprivation you know..). Let me know how it goes for you. Happy to help out more. Regards, GRANT
İlhan Ketrez wrote: > Dear Grant, > > Thank you for making me feel like a child :) > > And thank you for your detailed e-mail. It seems useful but I don't have > enough time now to examine in depth. > > As you mentioned, I need to make some modifications I guess. I will post > here as soon as I make it work for me. > > Bes regards, > Ilhan Ketrez > > > 01.07.2008 tarihinde *Grant Noble* <[EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]>> yazmış: > > Quit your whining. It took me the best part of 2 years to get > accurate profit & margin calculations. > It didn't help that there was a bug in fx profit calculations > involving leverage but Thomasz fixed > that a few releases ago (ta :)). Along the way I realised that not > all brokers calculate margin the > same way - my broker actually has three different calculations > depending on the type of stop used. > Some base margin on CCY1, some on CCY2. Also margin, as a symbol > information property, is defined > statically whereas I needed to define it dynamically at order time > based on entry price. Therefore I > needed CBT code which I was able to create with the help of another > participant on this forum (g'day > Aron). You too will probably need something like this. Amibroker > support is tip-top but working out > how to set backtest preferences for your broker is your job. > > I'll attach some code I use. I #include it in all my systems. Note > that is uses ATC so you'll have > to retrieve this data within your system code. Note also that this > code is partially obsolete (since > that bug was sorted out). Will it do exactly what you want? Probably > not, you'll need to tweak > depending upon your use. I need to do more work on it but I've been > busy with twin babies. Hope it > helps. G > > /* > Grant's FX preferences > */ > SetOption("FuturesMode", > True); // = use > MarginDeposit and PointValue in calculations > SetOption("InitialEquity", 10000 > ); // Initial equity $ > SetOption("MaxOpenPositions", 4 > ); // Max number of positions > SetOption("CommissionMode", > 3); // 3 = $ per share/contract > SetOption("CommissionAmount", > 0); // Commission amount > SetOption("AccountMargin", > 100); // Account > margin, 100 = no margin > SetOption("PriceBoundChecking", True > ); // Price to stay in bar range ? > SetOption("UsePrevBarEquityForPosSizing", True ); // Use last > known bar for position sizing ? > SetOption("ActivateStopsImmediately", False); // > Intraday stops ? > SetOption("Allowsamebarexit", > True); // Allow same bar exit for > profit stops ? > SetOption("Allowpositionshrinking", True); // > Take partial trades if equity available ? > SetOption("InterestRate",0); > // > Set interest rate earned for free cash, zero to evaluate system > SetOption("UseCustomBacktestProc", True); // > Use Custom backtest for reporting ? > SetOption("MinShares", > 1); // > Min number shares one > SetOption("MinPosValue", > 0); // Min > position value to make trade worthwhile, 0 = no limit > SetTradeDelays(0,0,0,0); > // > Trade delays applied by the backtester > > lotsize = StrToNum( ParamList("Lot size", "100000|10000|1000", 0) > ); // default lot 100000 > leverage = Param("Leverage rate", 50, 1, 100, > 1); // default > leverage 50:1 > base = ParamList("Base currency","AUD|CAD|CHF|EUR|GBP|USD", > 0); // default base currency AUD > > ccy2 = StrRight( Name(), 3 > ); // eg. EURJPY > gives JPY > TickSize = IIf( ccy2 == "JPY", 0.01, 0.0001 ); // > the minimum price move of symbol > RoundLotSize = > 1; > > // whole contracts only > contracts = > 1; > // > contracts to acquire > SetPositionSize( contracts, spsShares > ); // spsShares = size expressed in > shares/contracts > > fxRate = IIf( ccy2 == base, 1, Ref( Foreign( StrFormat( ccy2 + base > ), "Close" ), -1 ) ); // eg. > close of JPYAUD yesterday > pv = lotsize * fxRate; // the amount of profit > generated by one contract for a one point increase > in price > md = pv * Close * 1 / leverage; // the amount of money required to > open single contract position [IG > margin - no stop] > > // note: ATC code produces future leak warning when code is Checked > by editor.. > AddToComposite( pv, "~spec_" + Name(), "O", atcFlagDeleteValues + > atcFlagCompositeGroup + > atcFlagEnableInExplore + atcFlagEnableInBacktest ); // store daily > point value in composite > AddToComposite( md, "~spec_" + Name(), "C", atcFlagCompositeGroup + > atcFlagEnableInExplore + > atcFlagEnableInBacktest ); // store daily margin deposit in composite > > SetCustomBacktestProc(""); // no external backtest procedure > if ( Status("action") == actionPortfolio) { > bo = GetBacktesterObject(); // get backtester object > // > // set correct MarginDeposit & PointValue on entry signal days > // > bo.PreProcess(); // do > pre-processing (always required) > for (i = 1; i < BarCount; i++) // loop through all bars > { > for (sig = bo.GetFirstSignal(i); sig; sig = > bo.GetNextSignal(i)) // loop through all signals at > this bar > { > if( sig.IsEntry() ) // is it an entry signal > (buy/short) ? > { > pv = Foreign( "~spec_" + sig.Symbol, > "O" ); // entry day point value > md = Foreign( "~spec_" + sig.Symbol, > "C" ); // entry day margin deposit > _TRACE( StrFormat( "Ticker=" + > sig.Symbol + " PointValue=%1.0f pv=%1.0f MarginDeposit=%1.0f > md=%1.0f", sig.PointValue, pv[i], sig.MarginDeposit, md[i] ) ); > sig.PointValue = > pv[i]; // set symbol PointValue > sig.MarginDeposit = > md[i]; // set symbol MarginDeposit > } > } > bo.ProcessTradeSignals(i); // process trades at bar > (always required) > } > bo.PostProcess(); // do post-processing (always required) > } > // > > İlhan Ketrez wrote: > > Dear friends, > > > > Before registering the mailgroup, I was quite frustated regarding the > > customer support for Amibroker. Now I observe that Tomasz is very > busy > > with the new technological developements of the software and > replies the > > related questions mostly. I appreciate his great effort and magical > > software. > > > > In my recent e-mails, I believe that I emphasize an important point > > about forex backtesting in Amibroker. Currently, I see that it is > > impossible to truly backtest multiple forex pairs with the standard > > backtester interface. Below, I am trying to explain in detail. > > > > - For EURUSD and XXXUSD pairs everything is OK. > > - When the second unit is not USD, problem arises. I'm taking the > EURJPY > > as my example. Brokers calculate the profit-loss of these trades > in JPY > > (using the pointvalue * pricechange formula) and then converts to > USD, > > using the USDJPY pair as you know. > > - In Amibroker, when we set the currency as JPY and indicate > USDJPY in > > the settings, it calculates the profit-losses correctly. > > - In this case, it takes also the margin deposit scalar in JPY. > > - Hence, all the traded contract quantities increase to extreme > values > > and all the backtest becomes incorrect. > > > > How can we (do you) overcome this hindrance? > > > > Thanks in advance and best regards, > > Ilhan > > > > > > > > > > > > > > ---------- Yönlendirilmiş ileti ---------- > > Kimden: *İlhan Ketrez* <[EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]> > > <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>> > > Tarih: 27 Haziran 2008 Cuma 15:28 > > Konu: Re: [amibroker] Portfolio backtest in forex > > Kime: [email protected] > <mailto:[email protected]> <mailto:[email protected] > <mailto:[email protected]>> > > > > > > > > Thanks Tomasz, > > > > Curreny setting in the symbol information window is OK. > > > > The settings in the Tools->Preferences->Currencies windos are > also OK. > > > > When we change the currency, the currency of the margin deposit also > > changes. That is the problem. > > In forex accounts all of the margins are (Say) 1000 USD. > > Hence, in the current situation it becomes 1000 CHF. (Small Problem, > > average in last years is around 1.4) > > If the pair is USDJPY, it becomes 1000 JPY. (Greater problem > average in > > last years is around 110) > > > > As a result, almost all of the results become insignificant, starting > > with exposure, total profit/loss calculations. > > > > > > Please note that, unit profit-loss calculation is correct. Infact > > everything else seem to be correct. > > > > I understand the need for setting the margindeposit currency to the > > active currency to make trade in different markets. > > > > One temporary solution can be making an approach by adjusting the > > position size accordingly But the real, exact solution can only be > > achieved by defining a seperate currency setting for the margin > deposit. > > > > I am waiting for your comments. > > > > Best regards, > > Ilhan > > > > > > 2008/6/27, Tomasz Janeczko <[EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]> > > <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>>: > > > > Hello, > > > > You need to define CURRENCY (symbol->information) for that > pair to > > match the deposit currency. > > You also need to setup currency tables in > Tools->Preferences->Currencies > > > > Best regards, > > Tomasz Janeczko > > amibroker.com <http://amibroker.com> <http://amibroker.com/> > > > > ----- Original Message ----- > > *From:* İlhan Ketrez <mailto:[EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]>> > > *To:* [email protected] > <mailto:[email protected]> <mailto:[email protected] > <mailto:[email protected]>> > > *Sent:* Thursday, June 26, 2008 4:24 PM > > *Subject:* [amibroker] Portfolio backtest in forex > > > > > > Hello, > > > > While the currency for the margin deposit is not USD, how > can we > > perform a correct portfolio backtest in XXXYYY where YYY > is not > > USD such as EURCHF? > > > > Thanks in advance. > > Ilhan > > > > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > No virus found in this incoming message. > > Checked by AVG. > > Version: 8.0.101 / Virus Database: 270.4.3/1527 - Release Date: > 6/30/2008 6:07 PM > > ------------------------------------ > > Please note that this group is for discussion between users only. > > To get support from AmiBroker please send an e-mail directly to > SUPPORT {at} amibroker.com <http://amibroker.com> > > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG: > http://www.amibroker.com/devlog/ > > For other support material please check also: > http://www.amibroker.com/support.html > Yahoo! Groups Links > > > mailto:[EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]> > > > > > > > ------------------------------------------------------------------------ > > > No virus found in this incoming message. > Checked by AVG. > Version: 8.0.101 / Virus Database: 270.4.3/1527 - Release Date: 6/30/2008 > 6:07 PM ------------------------------------ Please note that this group is for discussion between users only. To get support from AmiBroker please send an e-mail directly to SUPPORT {at} amibroker.com For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG: http://www.amibroker.com/devlog/ For other support material please check also: http://www.amibroker.com/support.html Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/amibroker/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/amibroker/join (Yahoo! ID required) <*> To change settings via email: mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
