Login Page - Create Account

Support Board


Date/Time: Sun, 29 Mar 2020 21:27:43 +0000



[Programming Help] - ACSIL: simple FOR loop , very long reload and recalculate time

[2019-02-26 16:16:50]
TedMar - Posts: 164 | Ending Date: 2020-06-27
Hi, in my Example, try simple FOR loop. BUT this example "reload and recalculate" 26 secunds on 1 Day History and period 5 minutes chart. Whats wrong?



SCSFExport scsf_ExampleForCount(SCStudyInterfaceRef sc)
{
  SCSubgraphRef Graph1 = sc.Subgraph[0];
  if (sc.SetDefaults)    
  {
    sc.GraphName = "Example Count 4 Red Bars ";
    sc.StudyDescription = "Count RED Bars Serries in Manual loop";
    sc.AutoLoop = 0;
    sc.GraphRegion = 0;
  
    Graph1.Name = "Graph1";
    Graph1.DrawStyle = DRAWSTYLE_ARROW_DOWN;
    Graph1.LineWidth = 3;
    Graph1.PrimaryColor = RGB(255, 51, 255);

    return;
  }


  for (int BarIndex = sc.UpdateStartIndex; BarIndex < sc.ArraySize; BarIndex++) //Manual Loop
  {

    
    if (sc.Close[BarIndex] < sc.Open[BarIndex]) // find REDBAR
    {
      int REDCount = 1;
      for (int i = REDCount; sc.Close[BarIndex - (REDCount)] < sc.Open[BarIndex - (REDCount)]; i++) //Count RedBars serie,this loop needs 26s for chart Reload 5m Chart on Intel i5 3,3Mhz

      {
        REDCount++;
      }
      
      if (REDCount >= 4)
      {
        for (int i = 0; i < REDCount; i++)
        {
          Graph1[BarIndex - (i)] = sc.High[BarIndex - (i)];
        }

      }    
    }
  }
}




v1879
Date Time Of Last Edit: 2019-02-26 16:22:38
[2019-02-26 17:16:35]
Ackin - Posts: 666 | Ending Date: 2020-09-04
Whats wrong?

try:

1) int& colorred = sc.GetPersistentInt(1);
when REDcandle then increment colorred
when GREENCOLOR then colorred set to zero

2) if (colorred >= 4) then .....
Date Time Of Last Edit: 2019-02-26 17:18:23
[2019-02-26 17:37:10]
TedMar - Posts: 164 | Ending Date: 2020-06-27
@ackin Im not clear what u mean. Is posible u adjust my example? For me is not important green or red candels, but the code to get same effect but faster. @ackin u tryied my example, is similiery slow reload chart?
Date Time Of Last Edit: 2019-02-26 17:41:49
[2019-02-26 18:18:02]
Ackin - Posts: 666 | Ending Date: 2020-09-04

SCSFExport scsf_ExampleForCount(SCStudyInterfaceRef sc)

{
  SCSubgraphRef Graph1 = sc.Subgraph[0];

  if (sc.SetDefaults)
  {
    sc.GraphName = "Example Count 4 Red Bars ";
    sc.StudyDescription = "Count RED Bars Serries in Manual loop";
    sc.AutoLoop = 1;
    sc.GraphRegion = 0;
    
    Graph1.Name = "Graph1";
    Graph1.DrawStyle = DRAWSTYLE_ARROW_DOWN;
    Graph1.LineWidth = 3;
    Graph1.PrimaryColor = RGB(255, 51, 255);

    return;
  }

  int& colorred = sc.GetPersistentInt(1);
  
  if (sc.GetBarHasClosedStatus(sc.Index) == BHCS_BAR_HAS_CLOSED) {
    if (sc.Close[sc.Index] < sc.Open[sc.Index]) { //without DOJI
      colorred += 1;
    }
    else {
      colorred = 0;
    }

    if ((colorred) >= 4) {
      for (int i = 0; i < (colorred); i++)
      {
        Graph1[sc.Index - (i)] = sc.High[sc.Index - (i)];
      }

    }
  }
}

[2019-02-26 18:41:25]
TedMar - Posts: 164 | Ending Date: 2020-06-27
@Ackin, thank u,in fact u example effect is same , but why takes FOR LOOP so long time on reload chart?
[2019-02-26 19:09:04]
Ackin - Posts: 666 | Ending Date: 2020-09-04
Nasdaq, IB data with Sierra Feeds, 10 ses timeframe, Intraday chart, 100 days load

10ms study calculate
max 10 sec loading data



Maybe check Data/trade Service Settings Days to Download
Date Time Of Last Edit: 2019-02-26 19:15:02
[2019-02-26 19:26:49]
TedMar - Posts: 164 | Ending Date: 2020-06-27
@Ackin u tryed my Example and is result 10ms ?
Date Time Of Last Edit: 2019-02-26 19:28:09
[2019-02-26 19:47:05]
Ackin - Posts: 666 | Ending Date: 2020-09-04
yes, your code is faster (but against logic - loop in loop in loop)

if there are more dates, the succession will be opposite...

*********************
ver Sierrachart 1855
Date Time Of Last Edit: 2019-02-26 19:54:39
[2019-02-26 20:21:29]
TedMar - Posts: 164 | Ending Date: 2020-06-27
im confused, in v1879 need my example 26 >"SECUNDS"< for reload , and u Example Ackin needs 10 "Milisecunds" for 1 Day history / 5m bar period.
[2019-02-26 20:48:55]
Ackin - Posts: 666 | Ending Date: 2020-09-04
I don´t know. We can´t compare our results because we have different versions sw and other data sources.
In my opinion the problem is in data loading instead of the study. In other thread is written that v1879 is bad ... try downgrade

note:
I have own tester of AOS where the test of year takes approx 30 sec (without data loading). The program (c++) has more than 20 000 rows
[2019-03-09 14:38:06]
TedMar - Posts: 164 | Ending Date: 2020-06-27
@Ackin in your Example colorred GetPersistentInt counted RedBars. How is best way to remeber RedBarsseries and Last.Price for later calculation in an Array?

in my added lines in u example i use a subgraphArrey for store data, and i compare Last Array with current one

SCSFExport scsf_ExampleArrayCount(SCStudyInterfaceRef sc)
{
  SCSubgraphRef Graph1 = sc.Subgraph[0];
  SCSubgraphRef Graph2 = sc.Subgraph[1];

  if (sc.SetDefaults)
  {
    sc.GraphName = "Example Array Cont ";
    sc.StudyDescription = "Count RED Bars ArraySeries";
    sc.AutoLoop = 1;
    sc.GraphRegion = 0;

    Graph1.Name = "Graph1";
    Graph1.DrawStyle = DRAWSTYLE_ARROW_DOWN;
    Graph1.LineWidth = 3;
    Graph1.PrimaryColor = RGB(255, 51, 255);

    Graph2.Name = "Graph2";
    Graph2.DrawStyle = DRAWSTYLE_POINT_ON_LOW;
    Graph2.LineWidth = 3;
    Graph2.PrimaryColor = COLOR_BLUE;

    return;
  }
  SCString message;
  
  SCFloatArray myArray = sc.Subgraph[2].Arrays[0]; // SubgraphArrey [2] for Calculate only

  int& colorred = sc.GetPersistentInt(1);

  if (sc.GetBarHasClosedStatus(sc.Index) == BHCS_BAR_HAS_CLOSED)
  {

    if (sc.Close[sc.Index] < sc.Open[sc.Index])
    { //without DOJI

        colorred += 1;
    }
    else {colorred = 0;  }
        
    if ((colorred) >= 4)
    {
      for (int i = 0; i < (colorred); i++)
      {
        Graph1[sc.Index - (i)] = sc.High[sc.Index - (i)];
      }

      myArray[sc.Index] = sc.Close[sc.Index];

      if (myArray[sc.Index] < myArray[sc.Index - 1]) // Comapre Prices from last RedBarSeries
      {
        Graph2[sc.Index] = myArray[sc.Index];
      }
      message.Format("Array %i ", myArray.GetArraySize());
      sc.AddMessageToLog(message, 1);
    }
    
  }
}


is posible to resolve this comapre without subgraph array ? maybe with vector or other array type include sc.BaseData?



Please leve me example if u know.. THX
Date Time Of Last Edit: 2019-03-09 21:04:22
[2019-03-09 23:31:28]
Ackin - Posts: 666 | Ending Date: 2020-09-04
Hi,

I would like to help you, but I don´t understand your question?

You can also solve this thing other way, but "subgraph array" is not in this case bad choice.
You can use vector, a list or an array of pointers, but for such a simple thing it is unnecessary an the code of other possibility will be harder and study will not be faster.

Maybe we don´t understand each other. Would be possible to insert picture of parameters what does the study should have (how it should work).
[2019-03-10 00:23:11]
TedMar - Posts: 164 | Ending Date: 2020-06-27
its simple, i would like made Index of all (4Redbars series) , every serie + sc.Close Price from lastbar from serie,

After save them to array i.e , access to RedBar Series Index and lastBarprice , then compare RedBarSerie[sc.index -(x)][sc.Cloese] > RedBarSerie[sc.Index][sc.Close]

may question, how is best way to made index for this comparsion?

i see in my example
myArray[sc.Index] < myArray[sc.Index - 1]
is wrong, in fact the myArray not Store Index of RedBarSeries, -1 bar is not RedBarSeries index , why?


by the way. i requested you directMessages authorization.
[2019-03-10 08:17:23]
Ackin - Posts: 666 | Ending Date: 2020-09-04
ok, direct message

To post a message in this thread, you need to login with your Sierra Chart account:

Login

Login Page - Create Account