NexusFi: Find Your Edge


Home Menu

 





Write data to file


Discussion in Sierra Chart

Updated
      Top Posters
    1. looks_one puma with 7 posts (1 thanks)
    2. looks_two Nicolas11 with 4 posts (17 thanks)
    3. looks_3 WarEagle with 2 posts (1 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
      Best Posters
    1. looks_one Nicolas11 with 4.3 thanks per post
    2. looks_two LDog with 4 thanks per post
    3. looks_3 swandro with 2 thanks per post
    4. looks_4 puma with 0.1 thanks per post
    1. trending_up 6,772 views
    2. thumb_up 25 thanks given
    3. group 5 followers
    1. forum 14 posts
    2. attach_file 1 attachments




 
Search this Thread

Write data to file

  #1 (permalink)
 
WarEagle's Avatar
 WarEagle 
Pensacola, FL
 
Experience: Advanced
Platform: SierraChart
Broker: IB
Trading: Futures, Stocks, Options
Posts: 30 since Apr 2010
Thanks Given: 56
Thanks Received: 25

I am new to SC, and love it so far. The biggest obstacle is going to be learning a new programming language and C++ is certainly a challenge for me. I am pretty good with EasyLanguage and I am coming from MultiCharts (and before that TradeStation) where I wrote a lot of my own custom stuff.

There is really only one indicator that I need right off the bat so I am hoping someone may know how to do this or point me to it if it already exists somewhere. I use a second program that does not connect to my real time data feed but will update with ASCII data files. So in MC I would simply write the data (Date, Time, Open, High, Low, Close) from a chart to a file that would be named with whatever symbol and resolution was on the chart. Each time a bar closed the file would be updated with the new data. Here is the EL code:

 
Code
Inputs: filename("C:\Trading\Data\");
Vars: fn(""), type(""), Interval(2), Prices("");

Interval = bartype_ex;

If Interval = 1 then type = "tick.csv";
If Interval = 2 then type = "min.csv";
If Interval = 3 then type = "hr.csv";
If Interval = 11 then type = "range.csv";

Prices = ELDateToString(Date) & "," & NumToStr(T,0) & "," & NumToStr(O,2) & "," & NumToStr(H,2) & "," & NumToStr(L,2) & "," & NumToStr(C,2); 

fn = filename & GetSymbolName & "_" & NumToStr(BarInterval,0) & type;

If CurrentBar = 1 then FileDelete(fn);

FileAppend(fn,Prices + NewLine);
The output file will be "CLM3_1min.csv" if its applied to a 1 minute chart of CL. I looked through the built in and custom indicators included with SC and did not see anything that looked like it would do this. Any help or suggestions are appreciated.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Futures True Range Report
The Elite Circle
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Are there any eval firms that allow you to sink to your …
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
36 thanks
NexusFi site changelog and issues/problem reporting
25 thanks
The Program
20 thanks
GFIs1 1 DAX trade per day journal
19 thanks
  #3 (permalink)
 swandro 
England
 
Experience: Advanced
Platform: SierraChart
Posts: 70 since Jul 2009
Thanks Given: 9
Thanks Received: 80


There is a study you can add to the chart called "Write Bar Data to File". Here is a link to the documentation.

Technical Studies Reference - Sierra Chart

You have some control over the format. It updates realtime but beware that it does not write the current bar until it is completed (which I think is fair enough).

If this does not meet your needs, I am certain that a user has posted to the SC forum a piece of ACSIL code that does the job. I think this was done before SC created their study.

Give it a go anyway.

Reply With Quote
Thanked by:
  #4 (permalink)
 
WarEagle's Avatar
 WarEagle 
Pensacola, FL
 
Experience: Advanced
Platform: SierraChart
Broker: IB
Trading: Futures, Stocks, Options
Posts: 30 since Apr 2010
Thanks Given: 56
Thanks Received: 25

Wow, I have no idea how I missed that study. I must have only looked in the user contributed section. That should be perfect, thanks!

Started this thread Reply With Quote
Thanked by:
  #5 (permalink)
 
puma's Avatar
 puma 
zurich
 
Experience: Advanced
Platform: Sierra ahRrrr CQG ...
Trading: Bund, ES, ...
Posts: 964 since Aug 2010
Thanks Given: 7,273
Thanks Received: 1,507

I can not find this old / original "write to file"- study.

I need the last Bar updated and written to a file.

The official version does not update the last bar.

Can someone please post the link to the original version ?

Thank you very much

Follow me on Twitter Reply With Quote
  #6 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

Hi,

I'm aware that the last message is many months old.

The code of SC's "Write Bar Data To File" study is available in Studies6.cpp, and can probably be adapted so that the study also save the last bar.

Nicolas

Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

Here is the code that I personally use (compiled with Microsoft Visual Studio Express 2012 for Windows Desktop):

 
Code
#include <iostream>
#include <string>
#include <fstream>
#include "sierrachart.h"

SCDLLName("Write Bar Data To File 2");

SCSFExport scsf_WriteBarDataToFile2(SCStudyGraphRef sc) {

	SCInputRef OutputFile = sc.Input[0];

	if(sc.SetDefaults)
	{
		sc.GraphName="Write Bar Data To File 2";
		sc.StudyDescription="Write Bar Data To File 2";
		sc.FreeDLL = 0;

		sc.GraphRegion = 0;

		OutputFile.Name = "File Path";
		SCString OutputFileDefaultName;
		OutputFileDefaultName.Format("D:\\SierraChart1\\Data\\%s#CB.csv", sc.Symbol.GetSubString(2,0));
		OutputFile.SetString(OutputFileDefaultName);

		return;
	}

	std::ofstream file(OutputFile.GetString(), std::ios::out | std::ios::trunc);

	if (!file) {
		SCString Buffer;
		Buffer.Format("Unable to open file %s", OutputFile.GetString());
		sc.AddMessageToLog(Buffer, 1);
		return;
	}

	file << "Date, Open, High, Low, Close, Volume" << std::endl;

	for (int Index=0; Index < sc.ArraySize; Index++)
	{

		int year,month,day;
		SCDateTimeMS BaseDateTimeIn = sc.BaseDateTimeIn[Index];
		BaseDateTimeIn.GetDateYMD(year, month, day);
		SCString DateString;
		DateString.Format("%d/%02d/%02d", year, month, day);

		int ValueFormat = sc.BaseGraphValueFormat;

		char *formatString ;
		formatString = "%s, %s, %s, %s, %s, %.0f";

		float OpenValue  = sc.Open[Index];
		float HighValue  = sc.High[Index];
		float LowValue   = sc.Low[Index];
		float CloseValue = sc.Close[Index];

		SCString BarDataString;
		BarDataString.Format(formatString,
			DateString.GetChars(),		
			sc.FormatGraphValue(OpenValue, ValueFormat).GetChars(),
			sc.FormatGraphValue(HighValue, ValueFormat).GetChars(),
			sc.FormatGraphValue(LowValue, ValueFormat).GetChars(), 
			sc.FormatGraphValue(CloseValue, ValueFormat).GetChars(),
			sc.Volume[Index]);

		file << BarDataString << std::endl;
	}		

	file.close();
	SCString Buffer;
	Buffer.Format("Quotes of %s saved in file %s", sc.Symbol, OutputFile.GetString());
	sc.AddMessageToLog(Buffer, 0);

	return;
}

Visit my NexusFi Trade Journal Reply With Quote
  #8 (permalink)
 
puma's Avatar
 puma 
zurich
 
Experience: Advanced
Platform: Sierra ahRrrr CQG ...
Trading: Bund, ES, ...
Posts: 964 since Aug 2010
Thanks Given: 7,273
Thanks Received: 1,507

great gift, TY Nicolas

I will try your code over the next weekend


Follow me on Twitter Reply With Quote
  #9 (permalink)
 
puma's Avatar
 puma 
zurich
 
Experience: Advanced
Platform: Sierra ahRrrr CQG ...
Trading: Bund, ES, ...
Posts: 964 since Aug 2010
Thanks Given: 7,273
Thanks Received: 1,507


Nicolas11 View Post
Here is the code that I personally use (compiled with Microsoft Visual Studio Express 2012 for Windows Desktop):

Hi Nicolas11,

can you post the DLL please.

I have trouble compiling it and don't have Visual Studio on this PC.

TY

Follow me on Twitter Reply With Quote
  #10 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769


@puma,

Enclosed.

Nicolas

Attached Files
Elite Membership required to download: WriteBarDataToFile2.dll
Visit my NexusFi Trade Journal Reply With Quote




Last Updated on November 28, 2016


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts