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

EL question - static variables - clarification



PureBytes Links

Trading Reference Links


I want to clarify my prior question.

In the following code, I want the variables ThirtyMinHi, ThirtyMinLo, WentLong, WentShort to be what I call "static".
For example, if I set WentLong in bar 45 of an intraday chart and don't do anything after it, at bar 100 (for example) I want to be able to just get the value of WentLong and not have to reference the bar on which I set it (or worry about keeping track 
of that).

How can I do this in EL?

You can see my code below:

Thx,

Cash


Variables: ThirtyMinHi(0), ThirtyMinLo(99999);
Variables: WentLong(0), WentShort(0);

If FirstBarOfDay then
begin
	ThirtyMinHi = 0;
	ThirtyMinLo = 99999;
end;

If (time <= 1000) then
{ if it's before 10:00am then update the 1st Thirty minutes of the 
day high and low}
begin
	ThirtyMinHi = MaxList(H, ThirtyMinHi); WentLong = 0;
	ThirtyMinLo = MinList(L, ThirtyMinLo); WentShort = 0;
end
else
begin
	If (time <= 1530) then
	{ if it's after 10:00am and before 3:30pm then check to see if we should put in an order }
	begin
		{ If we haven't already gone long and the price is right, go long }
		If ((WentLong = 0) and (C > ThirtyMinHi+.25)) then
		begin
			buy("Above Thirty Min Hi") at close;
			WentLong = 1; { indicate we went long today }
		end;

		{ If we haven't already gone short and the price is right, go long }
		If ((WentShort = 0) and (C < ThirtyMinLo -.25)) then begin
			sell("Below Thirty Min Lo") at close;
			WentShort = 1; { indicate we went short today }
		end;
	end;

	{ check to see if we need to close any open positions }
	if MarketPosition = 1 then
	begin
		if L < ThirtyMinLo then exitlong;
	end;
	if MarketPosition = -1 then
	begin
		if H > ThirtyMinHi then exitshort;
	end;
end;

{ close all open positions at the end of the day }
If LastBarOfDay then
begin
	ExitLong;
	ExitShort;
end;



Date sent:      	Fri, 10 Aug 2001 11:14:53 -0700
From:           	cash@xxxxxxxxxxx
To:             	omega-list@xxxxxxxxxx
Subject:        	EL question - static variables?

> In easy language, if I want a variable that I can set it a bar and 
> remains the same until I change it, how would I do that?
> 
> If I have a variable MyNum and use this statement
> 
> Variables MyNum(0);
> If BarNumber = 10 then MyNum = Close;
> 
> that will set  MyNum to be the close of the 10th bar
> 
> Then later I want to use the value, how do I get MyNum?
> 
> If I'm anywhere but the 10th bar, MyNum will equal 0.
> 
> Is there a way that I can define a variable to be static or not need to 
> use a bar number?
> 
> Thx,
> 
> Cash
> 
> 
> throughout a strategy
> 
> "Buy Low, Sell High"
> (If this statment is used for financial gain, I am entitled to 10% of all profits. ;) )
> 




"Buy Low, Sell High"
(If this statment is used for financial gain, I am entitled to 10% of all profits. ;) )