Zeek, My first question would be: Why are you using static variables? AmiBroker will not allow you to enter a Buy if you are already Short, unless you override that behavior. So, I don't see a need for any of what you are trying to do.
Have you changed the default backtester mode? Or, perhaps you have selected the checkbox "Reverse entry signal forces exit" in the AA Settings. Leave the backtester mode at its default and unselect the "Reverse ..." checkbox from the settings window. Then, just write your vanilla Buy/Sell and Short/Cover code without any concern for what the other is doing. AmiBroker will sort it out based on which signals occur first. As an example, run a backtest on the following; Once with the "Reverse ..." checkbox selected and again with it unselected: WeekDay = DayOfWeek(); Short = WeekDay == 1; Cover = 0; Buy = WeekDay == 3; Sell = 0; Notice that in one case you get both buys and shorts. In the other you get only a single signal (whichever occurred first). As for what is being done "wrong". It's not so much wrong as pointless. Making a call to StaticVarGet without storing the resulting value has no purpose (that I'm aware of), yet your code is doing that twice. Also, given that the value being stored is just the value of readily available arrays, I don't see why you need to store anything at all. Why not just use Flip() as in my previous post, or BarsSince(), or Ref()? Finally, if you are using the same AFL over multiple symbols, a short position in one symbol will affect the logic of the remaining symbols since you are not discriminating between statics among the different symbols (i.e. you are using a single static variable rather than one per symbol). Based on what I've read so far in your previous posts, I'm guessing that unselecting the "Reverse ..." checkbox will solve all your problems. Mike --- In [email protected], "gregg55554" <zeekin...@...> wrote: > > thanks Mike for your reply, > > a) can you tell me what is wrong with the code, so I don't make the same > mistake again in the future. I tried to replicate code I had seen for > staticvars. > > b) In terms of what I am trying to do. I am trying to write a staticvar that > detects when there is a short trade. and then set it in my buy condition not > to have a buy if "onshort" == 1. so when staticvar "onshort" equals 1 then > no buys will occur. > I would use the exrem function but as I understand it, it is not very good in > the backtester?? So Marcin suggested I use a staticvar. > > Can you help please > zeek > > > --- In [email protected], zeek ing <zeeking57@> wrote: > > > > I think I am having a little problem with my static var code. I expected to > > see in an exploration with the variable "onshort" a value of 1 when a short > > trade is on. Instead all I see is zeros in the exploration. I am not sure > > why. there are two parts to the code. If anyone can tell me what is wrong > > with this code it would be appreciated. thanks > > > > ///part a-- > > StaticVarGet("onshort"); > > > > > > > > if( IsNull( StaticVarGet("onshort"))) StaticVarSet("onshort",0); > > > > Onshort= StaticVarGet("onshort"); > > > > > > > > //part b--- > > > > if (LastValue(Short)) > > > > > > > > {StaticVarSet("onshort",1);} > > > > if (LastValue(Cover)) > > > > > > > > {StaticVarSet("onshort",0);} > > > > > > > > StaticVarGet("onshort"); > > >
