Login Page - Create Account

Support Board


Date/Time: Tue, 07 May 2024 04:36:46 +0000



Post From: Price/Study Overlay study question

[2013-06-12 05:51:50]
TastyRisk - Posts: 119
Try this: it will combine the data from two studies.

I made it to use the open of study#1, and the "fill blank" data from study#2. This is the choice in "auto mode"; but if you choose "N= non auto select" in the settings; then you can combine your two overlays which each have different settings.

It might work for you?... It will try to use the data from study #1. If that data array is empty then it will take the data from study #2. For sure you must "fill blanks" on your second input study.

See picture below about study #1 & study #2.



#include "sierrachart.h"

SCDLLName("Studies951")

SCSFExport scsf_OverlaysCombinedMultiplier(SCStudyInterfaceRef sc)
{
  SCSubgraphRef StudyValue = sc.Subgraph[0];

  SCInputRef Stdy1 = sc.Input[0];
  SCInputRef Stdy2 = sc.Input[1];
  SCInputRef PreviousStudies = sc.Input[2];
  SCInputRef DrawZeros = sc.Input[3];
  SCInputRef Multiplier = sc.Input[4];

  
  SCFloatArray Study1Array;
  SCFloatArray Study2Array;

  if (sc.SetDefaults)
  {
    sc.GraphName = "OverlaysCombinedMultiplier";
    
    sc.StudyDescription = "//// Two studies should be applied before this one; Study Overlay OHLC & Study/Price Overlay. //// This study will show the Open of the first study. However; If there is no current trade data for this chart -then the last trade data from the second study is used instead. //// Choosing Auto Select Studies = Yes will automatically select the two studies prior to this one & use SG1 OPEN. i.e If this Study has ID:8, then 6&7 are automatically used. Choose free selction if you want to use data other than SG1 OPEN. ////";

    sc.AutoLoop = 1;

    sc.FreeDLL = 0;

    StudyValue.Name = "StudyValue";
    StudyValue.DrawStyle = DRAWSTYLE_LINE;
    StudyValue.LineWidth = 1;
    
    Stdy1.Name = "Input Study `Study Overlay OHLC`";
    Stdy1.SetStudySubgraphValues(1, 0);

    Stdy2.Name = "Input Study `Study/Price Overlay`";
    Stdy2.SetStudySubgraphValues(2, 0);

    PreviousStudies.Name = "Auto Select Studies = Y. No Auto - free Selection = N";
    PreviousStudies.SetYesNo(true);;

    DrawZeros.Name = "Draw Zeros";
    DrawZeros.SetYesNo(true);

    Multiplier.Name = "Multiplier";
    Multiplier.SetFloat(1.0f);

    return;
  }

  int i = sc.Index;
  int ID0 = sc.StudyGraphInstanceID;
  
  if (PreviousStudies.GetYesNo())
  {
    int ID1 = (ID0 -2);
    int ID2 = (ID0 -1);
    int val = 0;

    Stdy1.SetStudySubgraphValues(ID1,val);
    Stdy2.SetStudySubgraphValues(ID2,val);

    sc.GetStudyArrayUsingID(Stdy1.GetStudyID(),Stdy1.GetSubgraphIndex(),Study1Array);
    sc.GetStudyArrayUsingID(Stdy2.GetStudyID(),Stdy2.GetSubgraphIndex(),Study2Array);
  
    if (Study1Array[i] == 0)
    {
    Study1Array[i] = Study2Array[i];
    }
  }
  
  else
  {
    sc.GetStudyArrayUsingID(Stdy1.GetStudyID(),Stdy1.GetSubgraphIndex(),Study1Array);
    sc.GetStudyArrayUsingID(Stdy2.GetStudyID(),Stdy2.GetSubgraphIndex(),Study2Array);
  
    if (Study1Array[i] == 0)
    {
    Study1Array[i] = Study2Array[i];
    }
  }
  
  if (ID0 <= 2) {return;}
  else
  
  StudyValue.DrawZeros = DrawZeros.GetYesNo();
  StudyValue[i] = Study1Array[i] * Multiplier.GetFloat();
}


Date Time Of Last Edit: 2013-06-12 06:16:36