Two Trading Loops
Author: thetraderman
Creation Date: 4/12/2011 12:24 PM
profile picture

thetraderman

#1
Eugene, Cone,

I'm starting a new thread since this topic is different from the stop loss issue I mentioned previously. I'm not sure if this is a typical problem for automated trading but this is my dilemma. My system essentially running two loops across all the bars it received by WL. The first loop analyses the bars and comes up with trading signals based on the information it has. Finally when the next bar comes in, the process is repeated only now with information including the new bar. The problem is when let’s say bar 100 comes in I get a buy signal which is all well and good. The script goes ahead and does the buy. Then a few minutes later (assuming we are using minute bars), the trading signal changes and now the buy arrow is moved to a new and better position (price) which peeking to the nth degree. The same goes for the sell signal.

So obviously my back testing results is unjustifiably great. Which leads me to two questions, is there something I can do to tell WL to use the original signal rather than change it to an updated signal when a new bar comes in? Also if we were trading live how does WL handle it? Does the position log show the true buy/sell signals or is all guess work as to what really got traded.
I can’t really break up the two loops because of the way the script was designed. I’m hoping there is some sort of way WL allows one to handle this type of situation. I can't believe I'm the first to deal with this type of problem. As always you support is really appreciated.

Thanks.
profile picture

Cone

#2
QUOTE:
is there something I can do to tell WL to use the original signal rather than change it to an updated signal when a new bar comes in?
If you give WL the same signal for the same bar, then it will give you the same trade. You have to realize that each time the script is run, the Wealth-Lab engine is starting fresh. It doesn't remember trades from a previous run. You can use any method available to you in C# for recalling variables from a previous execution - disk, global memory, or even WealthScript class-level variables.

Anyway, this discussion is a good clue as to why you're having trouble with stop orders - almost surely the code is not properly managing/cleaning up positions from different trading loops.
profile picture

thetraderman

#3
I actually was investigating the same thoughts you had. I would really love to have a means of using static global arrays such as DataSeries but C#/WL doesn't support it. I tried different variations but the only thing I can manage to maintain as static global variables are int's or doubles. I read somewhere that one would need to write a class and maintain the global variables there. I'm fairly new to C# but well versed in C. Unfortunately the two are similar but not similar enough to make my job easy. If you know of something I can use I would appreciate it. Maybe a member of the forum can point me to the right direction?
profile picture

Eugene

#4
You can maintain an instance of any class as a global variable, making sure you didn't forget about boxing/unboxing it. See GetGlobal example in the QuickRef.
profile picture

Cone

#5
Wouldn't WealthScript's Set/GetGlobal functions help? See the examples in the QuickRef (F11).

profile picture

thetraderman

#6
Great! Thanks, I'll try it.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).