Thebattlefront Posted July 22 Report Posted July 22 Hi, I wanted to know if it were possible to add the lines using System; using System.Linq; to the advanced paintbar code to use methods for average, sum, etc for lists. Quote
Mike Medved Posted July 22 Report Posted July 22 I added the following code to a paintbar: var a = new List<int>(); a.Add(1); var ave = a.Average(); It compiled and ran fine. Quote
Thebattlefront Posted August 1 Author Report Posted August 1 Ok, i see. So it's already prebuilt into it. I probably made a mistake coding it. I'm still learning. And while you're here could you take a look at my paintbar code for a second and tell me what's going wrong with it? I have a list that contains several objects of the class Pattern. When I run the code, it's supposed to spit out an overall winrate and an overall number of trades on the scan result, and it does. However, when I leave the scan running, it will continue to add the same last value onto the total each second the scan runs, causing the numbers to become really unbalanced. And this only occurs during the case when the last candlestick was a sell signal. I know it sounds strange, but it looks sorta like this when you let the scan run for a while. (The orange bars and sometimes the white bars are the sell candlesticks. You can ignore gray colored numbers. The gray numbers do not change. The orange numbers (and sometimes the whire bars) do change. It's as if the scan continues to add the last trade's profit onto the total, and won't stop doing that until i stop the scan manually). By the way, the reason the white bars change sometimes is because. The white signal is supposed to be an entry candlestick. But sometimes the same entry candlestick can also be a sell candlestick for the last trade. So it's like, two signal in one. "Get out of the last trade" and a "get into the next trade" type of signal, built into the same candlestick. Quote
Mike Medved Posted August 2 Report Posted August 2 It's probably because you're missing the "automaton" part of the paintbar. The paintbar constantly re-runs on the last candle as the new data come in. BUT its "state" is supposed to be constantly restored to the state at the beginning of the candle. See https://www.medvedtrader.com/trader/WebHelp/state_keeping.htm Quote
Thebattlefront Posted August 3 Author Report Posted August 3 (edited) So it says in the trader help section that: PaintbarState struct that can contain any number of value types. It is very important that only value types are included in that struct, not reference types. There are two instances of the struct - CurrentState and SavedState. All the calculation should be performed using the CurrentState, the SavedState is only there for state-keeping. For any objects/classes that you need for the state (that is, reference types), you have to do the state-keeping yourself. That would include defining the current/saved copy of the object and the deep-copying between them in the state-saving and state-restoring functions. We provide a very useful class FIFOQueue that would probably be sufficient for most of your needs. But I don't really know how to do this. I actually have my List<Pattern> variable saved in the PaintbarState struct. It looks like this: private void PaintbarClearState() { CurrentState = new PaintbarState(); ...(some other currentstate variables).... CurrentState.m_listPattern = new List<Pattern> {new pattern("$", new List <double>(), new List <double>(), new List <double>(), new List <double>())}; } and the scan runs mostly fine (except with the incremental problem above). I don't really know how to start with doing the state-keeping on my own. I'm not familiar with the currentstate / save state functions. Is there a chance you could take a look at my paintbar and show me how to do it? Edited August 3 by Thebattlefront Quote
Mike Medved Posted August 3 Report Posted August 3 Is it a huge/complex paintbar/scan? Send it to me I will look at it support@medvedtrader.com The idea with state keeping is that every candle has a state. When you go to next candle, you start with previous candle's state and build on it. When on the last candle, if the previous candle was also last (but not as "complete" as now), your state should revert to the state of the previous candle before processing current candle. If you have a complex list that contains elements that are also lists, you'd need to implement deep clones in order to keep the state... As I said, send me the scan I will take a look. Quote
Thebattlefront Posted August 3 Author Report Posted August 3 (edited) Yeah i have a complex list that contains elements that are also lists. Maybe there's a way I can simplify the code so that I don't need lists inside lists, especially if the method to keep the state is going to be overly complex. I was really just trying to practice with classes and objects to better understand how they work. But it'd be cool to know how to save the states of complex lists too, just because you know, it's always good to learn stuff. Edited August 3 by Thebattlefront Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.