I actually set up a loop with the same sell entry and exit conditions to set the shorton variable right b4 my buy code and that seems to work. SO no longer a chicken and egg. ALthough it took me forever to figure that out.
But that is how u learn. --- In [email protected], "Mike" <sfclimb...@...> wrote: > > If you are trying to preserve a value between passes of the code, try looking > at StaticVarSet, StaticVarGet. > > If you are talking about within a single pass of the code, then you have a > chicken and egg circular reference and will need to rethink your code. > > You may find the use of intermediate variables helpful to store partial logic > that gets used in multiple places. Or, you may need to write a loop to handle > the setting for all of shorton, Buy and Sell on a bar by bar basis. > > Again, some kind of example would be helpful. The code that you have provided > so far does not show why you can't just move the Buy assignmant below the > code that sets shorton. > > Mike > > --- In [email protected], "noah.bender" <knowabender@> wrote: > > > > my theory was initially to reference the shorton.But I am running into > > problems. I have tried using the ref function and the barcount function > > with no luck. > > > > It seems the code always reverts back to the initialization value of zero. > > It is really frustrating. And I can't move the calculation of shorton > > before the buy code. > > > > the code has > > shorton=0; > > > > the buy = condition a b and c and shorton=1 > > > > // shorton only gets set here > > if (xyz ) > > > > > > so how do i reference the shorton being 1 in the buy code without > > automatically reverting to zero because of the initialization > > --- In [email protected], "Mike" <sfclimbers@> wrote: > > > > > > No. That is not correct. > > > > > > It is the same variable being used both inside and outside of the loop. > > > It will have whatever value was last set on it regardless of whether the > > > value was set from within the loop or not. > > > > > > Based on your sample code, the first reference to shorton within the loop > > > will see a value of zero, due to the initialization made before the loop. > > > Since the last line of your loop then sets shorton to one, all subsequent > > > references (even after the loop completes) will see a one unless you > > > again change the value. > > > > > > You might want to post a complete sample and ask for help. It doesn't > > > have to be your holy grail system, just reproduce the problem in a > > > simplified script and post that. > > > > > > Mike > > > > > > --- In [email protected], "noah.bender" <knowabender@> wrote: > > > > > > > > i think i found the answer to my question by using a loop. If I am a > > > > correct when using a loop as long as the variable is with in the loop > > > > as long as the loop is running then it will not use value of the > > > > variable from out side the loop. > > > > > > > > for example > > > > shorton =0 ; > > > > for (i=o......) > > > > ( > > > > code referencing shorton > > > > > > > > shorton =1; > > > > ) > > > > as long as the loop keeps runnning the shorton variable code in the > > > > begining will reference the code in the loop and not the code in that > > > > set shorton =0; before the loop. > > > > > > > > is that correct?? > > > > > > > > thanks > > > > > > > > --- In [email protected], Noah Bender <knowabender@> wrote: > > > > > > > > > > i am trying to call a variable in the code that gets set later on in > > > > > the > > > > > code, i see i can't do that. so i set the variable to 0. the problem > > > > > is that > > > > > the variable later on gets set to 1 and I want to call the variable > > > > > when it > > > > > is set to 1 and I can't seem to do that. > > > > > basically looks like this > > > > > > > > > > global Shorton; > > > > > Shorton=0; > > > > > Buy = (BarsSince(signalBar) < waitPeriod) Shorton==0; > > > > > .............. > > > > > //later on in code > > > > > shorton=1; > > > > > the problem is that later on sometimes the shorton gets set to 1. > > > > > which is > > > > > what I want the buy code to reference. but it automatically > > > > > references the > > > > > shorton as 0 because that is what it is set at the beginning. > > > > > I also can't put the buy code after the shorton is set, it will screw > > > > > up my > > > > > code for the short side. > > > > > > > > > > Is there anyway to call the value when it is 1 and not 0 > > > > > > > > > > I am using an intraday chart. > > > > > can anyone help me??? > > > > > > > > > > > > > > >
