Symbol Currency Property of Signal Object

Dear all,

I’m currently doing custom signal processing in CBT mid-level.

When I’m evaluating each signal I need to calculate the position size of the signal in dollars (base currency).
Since I have symbols in different currencies, I need to get the Fxrate for symbol signal being processed.
From reading the manual it seems to me that only trade object has Fx rate available via GetPrice method.

Probably I’m missing something is there another way to achieve this?

Thanks in advance

Regards,
pm

cur = GetFnData(“Currency”);

3 Likes

Thanks @portfoliobuilder, that is one possible way to do it, if I add the actual Fx rates to AFL itself.

I was wondering, though, if I could get the actual Fx rate directly in CBT part.

thanks again,
pm

Yes only Trade object (like open position) has direct access to FxRate. Before opening trade you need to use signal.Symbol , retrieve currency using GetFnDataForeign() and then use Foreign() to retrieve actual price.

An alternative, faster method is to store currency in static variable in first phase.
Something along these lines:

cur = GetFnData("Currency");
if( cur != "" AND cur != "USD" )
{
   StaticVarSet( "Fx" + cur, Foreign( cur + "USD", "C" ) );
}

SetCustomBacktestProc("");

if (Status("action") == actionPortfolio) 
{
    bo = GetBacktesterObject();	//  Get backtester object
    bo.PreProcess();	//  Do pre-processing (always required)

    for (i = 0; i < BarCount; i++)	//  Loop through all bars
    {
        for (sig = bo.GetFirstSignal( i ); sig; sig = bo.GetNextSignal( i ) )
        {	
			cur = GetFnDataForeign( "Currency", sig.Symbol );
			
			entryfxrate = 1;
			
			if( cur != "" AND cur != "USD" )
			{
				fxrates = StaticVarGet( "Fx" + cur );
				entryfxrate = fxrates[ i ];
			}
			
              // do your custom signal processing
        }	
        
        bo.ProcessTradeSignals( i );	//  Process trades at bar (always required)
    }	  
      
    bo.PostProcess();	//  Do post-processing (always required)
}
5 Likes

Thanks for all the suggestions ,

I’ll use that approach.

Regards,
pm

Hi,

I do have a newbee question, if that is all right. On above code, static variable has been defined as

StaticVarSet( "Fx" + cur, Foreign( cur, "C" ) );

instead of

StaticVarSet( cur, Foreign( cur, "C" ) );

Would you please elaborate on what is the reason ?

Many thanks,

Kind regards,

AD

My code is intended for original poster experience level (i.e. Advanced).

In the code I store currency data in static variables for speed so they can be later retrieved faster. So say store EURUSD rates in “FxEUR” static. Static variables are orders of magnitude faster than Foreign call.

But if you are beginner you should keep things simple and don’t use such things.

Dear TJ,

It is noted well.

Many thanks,

Kind regards,

AD

Thomaz
I have to use fixed FX rates in Preferences > Currencies as I use multiple databases some without FX data others with differing symbols for the same FX rate.

Is it possible to retrieve these fixed FX Rates from the preferences table in AFL or do I need to replicate this table as Variables within the AFL code?

Thanks

richard