Hello, hoping someone may be able to help out with this. I have a
trading system that cycles through a number of unique conditions, to
look for a Buy. Each condition also has a specific associated profit
target. I am trying to dump the true profit target to an external file,
any time there is a Buy. Right now I am using LastValue( ) to do that,
and maybe that is where the problem lies - because it does not work. The
file is always empty.
Below is a much simplified version. The part in red is where the problem
is. Right now I am using this in backtesting. And save for the Fput
subroutine, the system otherwise works fine. But in order to convert
this to a live auto trading system, I need to be able to isolate and
dump the correct Profit Target to file, so that I can pull it during the
subsequent exit subroutines.
Any input much appreciated:
// Enter a Long Position if any one of 500 Conditions are true.
// Conditions are generated from another algorithm. Only one Condition
can
// be true on any bar. Each Condition has an associated Profit Target.
// Whenever we enter a Position, dump the ProfitTarget to file.
for(i=1; i < 500 + 1; ++i)
{
TestCondition = VarGet( "Condition" + i );
Profit = VarGet( "Profit" + i );
Buy = Buy || TestCondition;
ProfitTarget = IIf(TestCondition , Profit, ProfitTarget);
// if we bought, dump the profit target that we used, to file:
if(LastValue(Buy) > 0)
{
ProfitNum = LastValue(ProfitTarget);
ProfitStr = NumToStr(ProfitNum);
fh = fopen( "F:\\ProfitDump.txt", "w");
if( fh )
{
fputs( ProfitStr, fh );
}
fclose( fh );
}
}