Creating other classes and Object reference exception
Creating other classes and Object reference exception
02 Aug 2016, 20:51
HI All
I am using cAlgo and Visual Studio.
I want to incorporate logic and other objects in other classes.
I have a number of issues:
1) when i try to access MarketSeries.High[i] or .Low[i] i get a nullpointer exception as if the static method is not recognized. The compilation has no wornings or errors. In cAlgo i get object reference not set to an object.
It happens also for the method Print("");
Is there something i have to add in the other classes i use to make sure this doesnt happen?
2)From cAlgo, although doesnt give any error and compiles fine, i dont get the code complition help like for the rest of the API. So a method from my own class would not autocomplete. I dont midn too much as i work on the classes from Visual Studio. It is only annoying.
The class is like this:
I am going mad trying to understand what do i need to add to avoid MarketSeries to give me the nullpointerexception thanks
class Candy:Robot { private double High, Low, Open, Close, Size, Center, QuarterUp, QuarterDwn; List<CandyType> candyQualities; public Candy(int i) { candyQualities = new List<CandyType>(); // try { Print("candle index "+i+" initialized"); AnalyzeCandle(i); } catch (Exception e) { Print("{0} ", e.StackTrace); } } public void AnalyzeCandle(int i){ High = MarketSeries.High[i]; Low = MarketSeries.Low[i]; Open = MarketSeries.Open[i]; Close = MarketSeries.Close[i]; Size = Math.Abs(High - Low); Center = High - (High-Low)/2; QuarterUp = High - (High - Center) / 2; QuarterDwn = High - Size*3/4; } }
Replies
egi.messito
03 Aug 2016, 16:51
Solved by passing
StrategyTest st = new StrategyTest(MarketData.GetSeries(TimeFrame));
But i can still not Print(""); from another class
what do i need to initiate in the other class to be able to Print?
@egi.messito
egi.messito
03 Aug 2016, 17:08
Solved:
Need to pass (this) in the custome class to get the Printing function into the log.
this is the easier way other then using reflection...
public class CustomClass { private MyRobot _robot; public CustomClass(MyRobot robot) { _robot = robot; } public void Print(string message) { _robot.PrintToLog(message) } }
So in my code:
StrategyTest st = new StrategyTest(MarketData.GetSeries(TimeFrame), this); st.doSomething();
@egi.messito
egi.messito
02 Aug 2016, 21:24
RE:
At a more basic level
this would crash - why i cannot use Print and MarketSeries in the custom class?
@egi.messito