[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Help with Static vars



PureBytes Links

Trading Reference Links

I'm trying to learn Static vars 
The example I'm using is to form a 'Latch' type function, similar to
FLIP, for use in RT trading.   (see dicussion last week in the
amibroker-at group). 

 
The goal is to 'latch' a condition as true, once it has occurred,
regardless if the condition becomes false later in the curent bar
For example, if price > prior close.  The normal FLIP doesn't work in
RT, as the condtion may vary during the bars life, and flip() only
"latches" at bar close time.

So here's the original code example using flip..
--
LongEntry = C > Ref(H,-1) ; 
LongExit = C < Ref(L,-1) ;

/* The following 'Flip' doesn't work in RT.  
It will vary with the condition, until the bar closes */

inlong = Flip(Longentry,longexit);   

Plot(inlong,"",colorGreen,styleArea,0,10);
PlotShapes(IIf(Longentry,shapeUpTriangle,shapeNone),colorLime);
PlotShapes(IIf(Longexit,shapeDownTriangle,shapeNone),colorRed);
Title = Name() + " In long entry = " + inlong  ;
--

And here's my attempt with using static vars to latch 'inlong' = true
 on the 1st occurance of the signal. 
But it doesn't work right .. the static var doesn't seem to getting
set.. or at least that's the appearance. 

--
_SECTION_BEGIN("RT-FLIP");
LongEntry = C > Ref(H,-1) ; 
LongExit = C < Ref(L,-1) ;
if (Longentry[BarCount-1] = True)       
        {       
        StaticVarSet("aaa",True);
        }
if (Longexit[BarCount-1] = True) 
        {
        StaticVarSet("aaa",False);
        }
Longlatch = (Longentry OR StaticVarGet("aaa"));

inlong = Flip(Longlatch ,longexit);    
/* This should be true, until we get a new longexit ) */

Plot(inlong,"",colorGreen,styleArea,0,10);
PlotShapes(IIf(Longentry,shapeUpTriangle,shapeNone),colorLime);
PlotShapes(IIf(Longexit,shapeDownTriangle,shapeNone),colorRed);

SignalText = WriteIf(inlong,EncodeColor(colorLime) + " IN LONG TRADE","");
Title = Name() + " longentry = " + Longentry  + " StVar= " + 
StaticVarGet("aaa")  + signaltext;
_SECTION_END();

--- 
I suspect I'm getting hung up in my use of barcount and/or my use of
the braces in the IF statements. 

Any help would be appreciated.   


Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.16.10/624 - Release Date: 1/12/2007 2:04 PM