• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Serializing Objects

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Serializing Objects

    I want to serialize some objects i get when i run a backtest but I am having some problems reading back. I was wondering if there are any good examples of how to do this.

    I created an object and use the constructors along the lines of this link
    http://www.codeproject.com/Articles/...zation-using-C

    I dont get any errors writing or reading but when I try to assign myObject the serialized info I get an "Unable to find assembly" error.

    any idea

    Code:
    TimeSobject newTimeObject = new TimeSobject();
    newTimeObject.barCount= CurrentBar;
    newTimeObject.closePx = 9999;
    Print("serilization srted");
    		Stream stream = File.Open(Cbi.Core.UserDataDir.ToString() + "Cereal.osl", FileMode.Create);
    			
    			    BinaryFormatter bin = new BinaryFormatter();
    			    bin.Serialize(stream, newTimeObject);
    			
    		stream.Close();	
    		Print("serilization complete");
    		
    			newTimeObject = null;
    			
    		stream = File.Open(Cbi.Core.UserDataDir.ToString() + "Cereal.osl", FileMode.Open);
    			Print("serilization 1");
    			    bin = new BinaryFormatter();
    Print("serilization 2");
    			    newTimeObject = (TimeSobject)bin.Deserialize(stream);  //Error here!
    	Print("serilization 3");		
    				stream.Close();	
    			Print("serilization 4");
    			Print(newTimeObject.closePx.ToString() + " is the close price from serilzation");
    And my class

    Code:
    public TimeSobject(SerializationInfo info, StreamingContext ctxt)
    {
        //Get the values from info and assign them to the appropriate properties
        barCount = (int)info.GetValue("barCount", typeof(int));
        closePx = (double)info.GetValue("ClosePX", typeof(double));
    }
            
    //Serialization function.
    public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
    {
        //You can use any custom name for your name-value pair. But make sure you
        // read the values with the same name. For ex:- If you write closePx as "ClosePX"
        // then you should read the same with "ClosePX"
        info.AddValue("barCount", barCount);
        info.AddValue("ClosePX", closePx);
    }

    #2
    Hello eurostoxx trader,

    Thank you for your post.

    Would you be able to provide the full strategy .cs file to test on our end? If so, please attach the .cs file for the strategy to your response. Or if you wish please send it to support[at]ninjatrader[dot]com with 'ATTN: Patrick - 1022204' in the subject line.
    Patrick H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by guvenators, Today, 05:18 PM
    1 response
    13 views
    0 likes
    Last Post NinjaTrader_ShawnB  
    Started by LANwarr1or, Today, 03:00 PM
    2 responses
    8 views
    0 likes
    Last Post LANwarr1or  
    Started by Newtrader101, Today, 02:53 PM
    2 responses
    10 views
    0 likes
    Last Post Newtrader101  
    Started by JuanPabloQuevedo, Today, 02:53 PM
    2 responses
    9 views
    0 likes
    Last Post JuanPabloQuevedo  
    Started by samir, Today, 03:16 PM
    2 responses
    14 views
    0 likes
    Last Post samir
    by samir
     
    Working...
    X