I am trying to get a handle on how the OptF factors are used. I am running into issues getting them to work inside of a function called within asset/algo loops. I am beginning to believe that the OptF is out of scope when you are in a called function. However the asset/algo is still known.

What am I missing here? Should the OptF factors always be called within the scope of run()? It appears the printf statement in run() is picking them up when Bar==1.

I have looked the documentation here but this is just not making sense to me.
https://manual.zorro-project.com/optimalf.htm


Code
 EUR/USD:TRND:L   Lots=0   OptimalF=0.000 OptimalFShort=0.000 OptimalFLong=0.000
 EUR/USD:TRND:S   Lots=0   OptimalF=0.000 OptimalFShort=0.000 OptimalFLong=0.000
V 2.257 on Thu 20-04-09 23:17:26
Test: testOptF EUR/USD 2010
Assets AssetsFix
Read testOptF.fac

 EUR/USD:TRND OptF=1.000 OptFLong=2.000 OptFShort=3.000
 EUR/USD:TRND:L   Lots=0   OptimalF=0.000 OptimalFShort=0.000 OptimalFLong=0.000
 EUR/USD:TRND:S   Lots=0   OptimalF=0.000 OptimalFShort=0.000 OptimalFLong=0.000
 EUR/USD:TRND:L   Lots=0   OptimalF=0.000 OptimalFShort=0.000 OptimalFLong=0.000
 EUR/USD:TRND:S   Lots=0   OptimalF=0.000 OptimalFShort=0.000 OptimalFLong=0.000
 EUR/USD:TRND:L   Lots=0   OptimalF=0.000 OptimalFShort=0.000 OptimalFLong=0.000
 EUR/USD:TRND:S   Lots=0   OptimalF=0.000 OptimalFShort=0.000 OptimalFLong=0.000


Code
testOptF.fac
EUR/USD:TRND        1.000  0.52    3/7     100.0
EUR/USD:TRND:L      2.000  0.00    0/5       2.6
EUR/USD:TRND:S      3.000  0.52    3/2      97.4




Code
/// testOptF.c

function tradeTrend(int sl)
{
	if(sl==1) //goLong
	{
		Margin = 0.5 * OptimalFLong * Capital * sqrt(1 + ProfitClosed/Capital);
		printf("\n %s:%s:L   Lots=%i   OptimalF=%.3f OptimalFShort=%.3f OptimalFLong=%.3f",Asset,Algo,Lots, OptimalF,OptimalFShort,OptimalFLong);
		enterLong();
	}
	else if(sl==0) //goShort
	{
		Margin = 0.5 * OptimalFShort * Capital * sqrt(1 + ProfitClosed/Capital);
		printf("\n %s:%s:S   Lots=%i   OptimalF=%.3f OptimalFShort=%.3f OptimalFLong=%.3f",Asset,Algo,Lots,OptimalF,OptimalFShort,OptimalFLong);
		enterShort();
	}
}

function run()
{
	set(PARAMETERS+FACTORS+LOGFILE+PLOTNOW);
	StartDate = 20100101;
	EndDate = 20100105;
	BarPeriod = 1440;
	LookBack = 0;
	Capital = 5000;
	Verbose = 1;
	
	if (Bar == 1)
	{	
		while(asset(loop("EUR/USD")))
		{
			while(algo(loop("TRND")))
			{
				if(Test)
					printf("\n %s:%s OptF=%.3f OptFLong=%.3f OptFShort=%.3f\n\n", Asset,Algo, OptimalF, OptimalFLong, OptimalFShort);
			}
		}
	}

	while(asset(loop("EUR/USD")))
	{
		while(algo(loop("TRND")))
		{
			if(Algo == "TRND") 
				tradeTrend(1); //goLong
			if(Algo == "TRND") 
				tradeTrend(0); //goShort
		}	
	}
}