Login Page - Create Account

Support Board


Date/Time: Sat, 11 Jan 2025 01:05:26 +0000



Post From: Spreadsheet feature request

[2016-10-09 22:24:42]
enemyspy - Posts: 306
You can write the base data and subgraphs to whatever file format you want via Acsil (c++).

I do a lot of data sharing between other custom apps. I pulled some of the code out of the header file I made to do this kind of stuff. Here is a very crude example which contains a custom study a custom study that will somewhat dynamically pull all of the information from the subgraphs. Basically like if you were to copy and paste you spreadsheet data.

It is kind of slow though because it keeps opening and closing the file at every index which is expensive. There are a number of ways that you can customize it to your needs and make it run a lot more efficiently. In its current state you need to input how many subgraphs are in each study By order of ID in the inputs section. If you need to use more studies modify the code to take more inputs. hope it helps get you started:


void FileOutput(const std::vector<float>& SubgraphsOut, const SCString& FilePath,bool Truncate)
{
  std::ofstream output;
  
  //Open the File Output
  if (output.is_open()) output.close();
    
    if(!Truncate) //Configured to use the Append Flag if The Study is not at the 0 index (full recalculation)
    output.open(FilePath.GetChars(), std::ofstream::out | std::ofstream::app);
    else //Uses the Truncate flag at the start of full recalculation. If you always want to append you will need to add some logic that recognizes The most recent entry, and aborts the append to avoid Dups.
    {
      output.open(FilePath.GetChars(), std::ofstream::out | std::ofstream::trunc);
      //Place a Header Writing Function here if you choose.
    }
  
  for (int i = 0; i < SubgraphsOut.size(); i++)
  {
    output << SubgraphsOut[i];
    if (i == SubgraphsOut.size() - 1) output << std::endl;
    else output << ",";
  }
  output.close();
}
SCSFExport scsf_SubGraphsToFile(SCStudyInterfaceRef sc)
{
  /*/Works for Same Chart Only.Code is Untested and Provided on an as is basis. Not Guaranteed to work and is for demonstration purposes only/**/

  SCInputRef s0 = sc.Input[0];
  SCInputRef s1 = sc.Input[1];
  SCInputRef s2 = sc.Input[2];

  if (sc.SetDefaults)
  {
    sc.GraphName = "SubGraphsToFile";
    sc.AutoLoop = 1;
    sc.FreeDLL = 0;

    s0.Name = "Study Input 0 # of subgraphs"; s0.SetInt(0);
    s1.Name = "Study Input 1 # of subgraphs"; s1.SetInt(0);
    s2.Name = "Study Input 2 # of subgraphs"; s2.SetInt(0);
    return;
  }
  
  int & StudyInputCount = (int)sc.GetPersistentInt(0);
  //int & StudyInputCount = (int)sc.GetPersistentInt(0);
  
  if (sc.Index == 0)
  {
    for (int i = 0; i < 3;i++)
    {
      if (sc.Input[i].GetInt() == 0) break;
        
      StudyInputCount++;
    }
  }

  if (sc.GetBarHasClosedStatus(sc.Index)== BHCS_BAR_HAS_CLOSED)
  {
    std::vector<float> SGInputs;
    //BaseData;
    SGInputs.push_back(sc.Open[sc.Index]);
    SGInputs.push_back(sc.High[sc.Index]);
    SGInputs.push_back(sc.Low[sc.Index]);
    SGInputs.push_back(sc.Close[sc.Index]);
    SGInputs.push_back(sc.Volume[sc.Index]);
    SGInputs.push_back(sc.BidVolume[sc.Index]);
    SGInputs.push_back(sc.AskVolume[sc.Index]);
    //Subraphs
    for (int i = 0; i < StudyInputCount; i++)
    {
      for (int j = 0; j < sc.Input[i].GetInt();j++)
      {
        SCFloatArray In;
        sc.GetStudyArrayUsingID(i, j, In);
        SGInputs.push_back(In[sc.Index]);
      }
    }
    FileOutput(SGInputs, "C:\\TradeData\\MyFile.csv",sc.Index==0);
  }

  return;
}

Date Time Of Last Edit: 2016-10-09 22:26:22