Login Page - Create Account

Support Board


Date/Time: Thu, 02 May 2024 05:46:56 +0000



Post From: Custom scale for each instrument

[2014-08-06 17:20:46]
vegasfoster - Posts: 444
At the bottom is what I have so far. It is designed so you enter "6E" and it will return the scale setting for any symbol containing 6E, e.g. 6EU4. It works fine if the 10 symbol input fields are completed, but if you only want to evaluate 3 symbols and leave the other 7 fields blank, for example, then it is returning the blank field as true because of the wildcard function and using the default scale setting of 50.

It gives me an error if I try to use something like,

if (*first == '')
return false;
I was searching a little bit and tried a couple suggestions such as,

std::string s;
if (s.empty())
but those aren't working for me either.

I also tried evaluating after the function with,

SCString sym1 = sc.Input[i].GetString() == "" ? "zzzzzzzzzzzzzzzz" : sc.Input[i].GetString();
I'll keep working on it, but any suggestions anyone might have would be appreciated.

#include "sierrachart.h"
#include <stdio.h>
#include <stdbool.h>

SCDLLName("ChartScale")

bool match(const char *first, const char *second)
  {
    //if (*first == '')
    //  return false;
    
    if (*first == '\0' && *second == '\0')
      return true;

    if (*first == '*' && *(first+1) != '\0' && *second == '\0')
      return false;

    if (*first == '?' || *first == *second)
      return match(first+1, second+1);

    if (*first == '*')
      return match(first+1, second) || match(first, second+1);
    return false;
  }

/*==========================================================================*/
SCSFExport scsf_ChartScale(SCStudyInterfaceRef sc)
{
  if (sc.SetDefaults)
  {
    sc.GraphName = "ChartScale";
    sc.GraphRegion  = 0;            
    sc.AutoLoop = true;
    sc.FreeDLL = 1;
        
    sc.Input[0].Name = "Symbol 1";
    sc.Input[0].SetString("");
    
    sc.Input[1].Name = "Symbol 1 - Scale in Ticks";
    sc.Input[1].SetInt(50);
        
    sc.Input[2].Name = "Symbol 2";
    sc.Input[2].SetString("");
    
    sc.Input[3].Name = "Symbol 2 - Scale in Ticks";
    sc.Input[3].SetInt(50);
    
    sc.Input[4].Name = "Symbol 3";
    sc.Input[4].SetString("");
    
    sc.Input[5].Name = "Symbol 3 - Scale in Ticks";
    sc.Input[5].SetInt(50);
    
    sc.Input[6].Name = "Symbol 4";
    sc.Input[6].SetString("");
    
    sc.Input[7].Name = "Symbol 4 - Scale in Ticks";
    sc.Input[7].SetInt(50);
    
    sc.Input[8].Name = "Symbol 5";
    sc.Input[8].SetString("");
    
    sc.Input[9].Name = "Symbol 5 - Scale in Ticks";
    sc.Input[9].SetInt(50);
    
    sc.Input[10].Name = "Symbol 6";
    sc.Input[10].SetString("");
    
    sc.Input[11].Name = "Symbol 6 - Scale in Ticks";
    sc.Input[11].SetInt(50);
        
    sc.Input[12].Name = "Symbol 7";
    sc.Input[12].SetString("");
    
    sc.Input[13].Name = "Symbol 7 - Scale in Ticks";
    sc.Input[13].SetInt(50);
    
    sc.Input[14].Name = "Symbol 8";
    sc.Input[14].SetString("");
    
    sc.Input[15].Name = "Symbol 8 - Scale in Ticks";
    sc.Input[15].SetInt(50);
    
    sc.Input[16].Name = "Symbol 9";
    sc.Input[16].SetString("");
    
    sc.Input[17].Name = "Symbol 9 - Scale in Ticks";
    sc.Input[17].SetInt(50);
    
    sc.Input[18].Name = "Symbol 10";
    sc.Input[18].SetString("");
    
    sc.Input[19].Name = "Symbol 10 - Scale in Ticks";
    sc.Input[19].SetInt(50);
    
    return;
  }
  // Do data processing
  
  for (int i = 0; i<20; i = i+2)
  {
    //SCString sym1 = sc.Input[i].GetString() == "" ? "zzzzzzzzzzzzzzzz" : sc.Input[i].GetString();
    SCString sym1 = sc.Input[i].GetString();
    SCString sym2 = "*";
    SCString sym3 = sym1 + sym2;
  
    if(match(sym3, sc.Symbol))    
      sc.BaseGraphScaleIncrement = sc.Input[i+1].GetInt()*sc.TickSize;
  }  
}