NexusFi: Find Your Edge


Home Menu

 





Not able to solve the SimpleMovAvg function error - ACSIL


Discussion in Sierra Chart

Updated
    1. trending_up 409 views
    2. thumb_up 3 thanks given
    3. group 3 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

Not able to solve the SimpleMovAvg function error - ACSIL

  #1 (permalink)
hhomsi8
Stockholm, Sweden
 
Posts: 10 since Feb 2023
Thanks Given: 7
Thanks Received: 0

Hi everyone,
I am very new to ACSIL coding and I am struggling converting my already existing code from previous platform to SierraChart, really hoping someone will be able to help.

The logic I am trying to replicate is really simple:
  • First:3 Inputs (Length, CalcLength,SmoothLength) they will all host integer numbers.
  • Second: Variables: (MA, Main, Signal).
  • Third: I am looping from ss= 0 to Length -1: if the close of the current index > the open of the current index then ss += 1 if the close of the current index < the open of the current index then ss -= 1.
Finally:
  • MA = SimpleMovAvg(ss, Length)
  • Main = SimpleMovAvg(MA, SmoothLength)
  • Signal = SimpleMovAvg(MA, CalcLength)[/INDENT]
My understanding from the error of the compiler below is that the MA, Main and Signal need to be handled as array but I am really struggling to know how to solve it.


Here is the full code:

 
Code
// The top of every source code file must include this line
#include "sierrachart.h"

// For reference, refer to this page:
// https://www.sierrachart.com/index.php?page=doc/AdvancedCustomStudyInterfaceAndLanguage.php

// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies. 
SCDLLName("TrueMomentum_H")

//This is the basic framework of a study function. Change the name 'TemplateFunction' to what you require.
SCSFExport scsf_TrueMomentum_H(SCStudyInterfaceRef sc)
{
    SCSubgraphRef Subgraph_Ma = sc.Subgraph[0];
    SCSubgraphRef Subgraph_Main = sc.Subgraph[1];
    SCSubgraphRef Subgraph_Signal = sc.Subgraph[2];
    SCSubgraphRef Subgraph_ZeroLine = sc.Subgraph[3];
    SCSubgraphRef Subgraph_UpperLine = sc.Subgraph[4];
    SCSubgraphRef Subgraph_LowerLine = sc.Subgraph[5];
    SCSubgraphRef Subgraph_Overbought = sc.Subgraph[6];
    SCSubgraphRef Subgraph_Oversold = sc.Subgraph[7];

    SCInputRef Input_Length = sc.Input[0];
    SCInputRef Input_CalcLength = sc.Input[1];
    SCInputRef Input_SmoothLength = sc.Input[2];

    if (sc.SetDefaults)
    {
        sc.GraphName = "MyMomentum";

        sc.GraphRegion = 0;
        sc.ValueFormat = 2;
        sc.AutoLoop = 1;

        Subgraph_Main.Name = "Ma";
        Subgraph_Main.DrawStyle = DRAWSTYLE_LINE;
        Subgraph_Main.PrimaryColor = RGB(0, 255, 0);
        Subgraph_Main.SecondaryColor = RGB(255, 0, 0);
        Subgraph_Main.SecondaryColorUsed = true;
        Subgraph_Main.DrawZeros = false;
        
        Subgraph_Main.Name = "Main";
        Subgraph_Main.DrawStyle = DRAWSTYLE_LINE;
        Subgraph_Main.PrimaryColor = RGB(0, 255, 0);
        Subgraph_Main.SecondaryColor = RGB(255, 0, 0);
        Subgraph_Main.SecondaryColorUsed = true;
        Subgraph_Main.DrawZeros = false;

        Subgraph_Signal.Name = "Signal";
        Subgraph_Signal.DrawStyle = DRAWSTYLE_LINE;
        Subgraph_Signal.PrimaryColor = RGB(0, 255, 0);
        Subgraph_Signal.SecondaryColor = RGB(255, 0, 0);
        Subgraph_Signal.SecondaryColorUsed = true;
        Subgraph_Signal.DrawZeros = false;

        Subgraph_ZeroLine.Name = "ZeroLine";
        Subgraph_ZeroLine.DrawStyle = DRAWSTYLE_LINE;
        Subgraph_ZeroLine.PrimaryColor = RGB(169, 169, 169);
        Subgraph_ZeroLine.DrawZeros = true;

        Subgraph_UpperLine.Name = "UpperLine";
        Subgraph_UpperLine.DrawStyle = DRAWSTYLE_LINE;
        Subgraph_UpperLine.PrimaryColor = RGB(255, 0, 0);
        Subgraph_UpperLine.DrawZeros = false;

        Subgraph_LowerLine.Name = "LowerLine";
        Subgraph_LowerLine.DrawStyle = DRAWSTYLE_LINE;
        Subgraph_LowerLine.PrimaryColor = RGB(0, 255, 0);
        Subgraph_LowerLine.DrawZeros = false;

        Subgraph_Overbought.Name = "Overbought";
        Subgraph_Overbought.DrawStyle = DRAWSTYLE_LINE;
        Subgraph_Overbought.PrimaryColor = RGB(255, 0, 0);
        Subgraph_Overbought.DrawZeros = false;

        Subgraph_Oversold.Name = "Oversold";
        Subgraph_Oversold.DrawStyle = DRAWSTYLE_LINE;
        Subgraph_Oversold.PrimaryColor = RGB(0, 255, 0);
        Subgraph_Oversold.DrawZeros = false;

        Input_Length.Name = "Length";
        Input_Length.SetInt(14);
        Input_Length.SetIntLimits(1, MAX_STUDY_LENGTH);

        Input_CalcLength.Name = "Calculation Length";
        Input_CalcLength.SetInt(5);
        Input_CalcLength.SetIntLimits(1, MAX_STUDY_LENGTH);

        Input_SmoothLength.Name = "Smooth Length";
        Input_SmoothLength.SetInt(3);
        Input_SmoothLength.SetIntLimits(1, MAX_STUDY_LENGTH);

        return;
    }

    int len = Input_Length.GetInt();
    SCFloatArrayRef s = sc.Subgraph[7]; // Create an array to store 's' values
    SCFloatArrayRef MA = sc.Subgraph[8]; // Create an array to store 'MA' values
    SCFloatArrayRef Main = sc.Subgraph[9]; // Create an array to store 'Main' values
    SCFloatArrayRef Signal = sc.Subgraph[10]; // Create an array to store 'Signal' values

    s[sc.Index] = 0;
    for (int ss = 0; ss < len; ss++)
    {
        if (sc.Close[sc.Index] > sc.Open[sc.Index - ss])
            s[sc.Index] = s[sc.Index] + 1;
        else if (sc.Close[sc.Index] < sc.Open[sc.Index - ss])
            s[sc.Index] = s[sc.Index] - 1;
        //else
        //  s[sc.Index] = 0;
    }

    //MA[sc.Index] = sc.SimpleMovAvg(s, Input_CalcLength.GetInt());
    //Main[sc.Index] = sc.SimpleMovAvg(MA, Input_SmoothLength.GetInt());
    //Signal[sc.Index] = sc.SimpleMovAvg(Main, Input_SmoothLength.GetInt());


    MA[sc.Index] = sc.SimpleMovAvg(s[sc.Index],Subgraph_Ma, Input_CalcLength.GetInt());
    Main[sc.Index] = sc.SimpleMovAvg(MA[sc.Index], Subgraph_Main,Input_SmoothLength.GetInt());
    Signal[sc.Index] = sc.SimpleMovAvg(Main[sc.Index],Subgraph_Signal ,Input_SmoothLength.GetInt());


    Subgraph_Main[sc.Index] = Main[sc.Index];
    Subgraph_Signal[sc.Index] = Signal[sc.Index];
    Subgraph_ZeroLine[sc.Index] = 0;
    Subgraph_UpperLine[sc.Index] = len;
    Subgraph_LowerLine[sc.Index] = -len;
    Subgraph_Overbought[sc.Index] = len * 0.8;
    Subgraph_Oversold[sc.Index] = -len * 0.8;
}
And Here is the error I am getting from the compiler:
 
Code
-- Starting remote build of Custom Studies Source files: TrueMomentum_H.cpp. 64-bit --     02:11:35

Allow time for the server to compile the files and build the DLL.

The remote build did not succeed. Result:

TrueMomentum_H.cpp: In function 'void scsf_TrueMomentum_H(SCStudyInterfaceRef)':
TrueMomentum_H.cpp:118:93: error: no matching function for call to 's_sc::SimpleMovAvg(float&, float&, int)'
  118 |  MA[sc.Index] = sc.SimpleMovAvg(s[sc.Index],Subgraph_Ma[sc.Index], Input_CalcLength.GetInt());
      |                                                                                             ^
In file included from TrueMomentum_H.cpp:2:
sierrachart.h:1253:18: note: candidate: 'c_ArrayWrapper<float>& s_sc::SimpleMovAvg(SCFloatArrayRef, SCFloatArrayRef, int, int)'
 1253 |  SCFloatArrayRef SimpleMovAvg(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length)
      |                  ^~~~~~~~~~~~
sierrachart.h:1253:18: note:   candidate expects 4 arguments, 3 provided
sierrachart.h:1257:18: note: candidate: 'c_ArrayWrapper<float>& s_sc::SimpleMovAvg(SCFloatArrayRef, SCFloatArrayRef, int)'
 1257 |  SCFloatArrayRef SimpleMovAvg(SCFloatArrayRef In, SCFloatArrayRef Out, int Length)
      |                  ^~~~~~~~~~~~
sierrachart.h:1257:47: note:   no known conversion for argument 1 from 'float' to 'SCFloatArrayRef' {aka 'c_ArrayWrapper<float>&'}
 1257 |  SCFloatArrayRef SimpleMovAvg(SCFloatArrayRef In, SCFloatArrayRef Out, int Length)
      |                               ~~~~~~~~~~~~~~~~^~
TrueMomentum_H.cpp:119:100: error: no matching function for call to 's_sc::SimpleMovAvg(float&, float&, int)'
  119 |  Main[sc.Index] = sc.SimpleMovAvg(MA[sc.Index], Subgraph_Main[sc.Index],Input_SmoothLength.GetInt());
      |                                                                                                    ^
In file included from TrueMomentum_H.cpp:2:
sierrachart.h:1253:18: note: candidate: 'c_ArrayWrapper<float>& s_sc::SimpleMovAvg(SCFloatArrayRef, SCFloatArrayRef, int, int)'
 1253 |  SCFloatArrayRef SimpleMovAvg(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length)
      |                  ^~~~~~~~~~~~
sierrachart.h:1253:18: note:   candidate expects 4 arguments, 3 provided
sierrachart.h:1257:18: note: candidate: 'c_ArrayWrapper<float>& s_sc::SimpleMovAvg(SCFloatArrayRef, SCFloatArrayRef, int)'
 1257 |  SCFloatArrayRef SimpleMovAvg(SCFloatArrayRef In, SCFloatArrayRef Out, int Length)
      |                  ^~~~~~~~~~~~
sierrachart.h:1257:47: note:   no known conversion for argument 1 from 'float' to 'SCFloatArrayRef' {aka 'c_ArrayWrapper<float>&'}
 1257 |  SCFloatArrayRef SimpleMovAvg(SCFloatArrayRef In, SCFloatArrayRef Out, int Length)
      |                               ~~~~~~~~~~~~~~~~^~
TrueMomentum_H.cpp:120:106: error: no matching function for call to 's_sc::SimpleMovAvg(float&, float&, int)'
  120 |  Signal[sc.Index] = sc.SimpleMovAvg(Main[sc.Index],Subgraph_Signal[sc.Index] ,Input_SmoothLength.GetInt());
      |                                                                                                          ^
In file included from TrueMomentum_H.cpp:2:
sierrachart.h:1253:18: note: candidate: 'c_ArrayWrapper<float>& s_sc::SimpleMovAvg(SCFloatArrayRef, SCFloatArrayRef, int, int)'
 1253 |  SCFloatArrayRef SimpleMovAvg(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length)
      |                  ^~~~~~~~~~~~
sierrachart.h:1253:18: note:   candidate expects 4 arguments, 3 provided
sierrachart.h:1257:18: note: candidate: 'c_ArrayWrapper<float>& s_sc::SimpleMovAvg(SCFloatArrayRef, SCFloatArrayRef, int)'
 1257 |  SCFloatArrayRef SimpleMovAvg(SCFloatArrayRef In, SCFloatArrayRef Out, int Length)
      |                  ^~~~~~~~~~~~
sierrachart.h:1257:47: note:   no known conversion for argument 1 from 'float' to 'SCFloatArrayRef' {aka 'c_ArrayWrapper<float>&'}
 1257 |  SCFloatArrayRef SimpleMovAvg(SCFloatArrayRef In, SCFloatArrayRef Out, int Length)
      |                               ~~~~~~~~~~~~~~~~^~

-- End of Build --     02:11:40

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Exit Strategy
NinjaTrader
REcommedations for programming help
Sierra Chart
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
26 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #2 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 360

You have the MA function incorrect. When you get an error always look at the docs,

sc.SimpleMovAvg()

Its basically the three parameters.

sc.SimpleMovAvg([data array in], [data array out], [length]);

You have it as = a variable which is throwing the errors.

Follow me on Twitter Reply With Quote
Thanked by:
  #3 (permalink)
hhomsi8
Stockholm, Sweden
 
Posts: 10 since Feb 2023
Thanks Given: 7
Thanks Received: 0


Thanks for ur answer. Sorry I did not understand what u meant by "a Variable"

I followed the docs:
array in is the s calculated earlier
array out is the Subgraph_Ma where it will be printed
length is the Input_CalcLength.GetInt() which will change according to needs since its inputs
MA[sc.Index] = sc.SimpleMovAvg(s[sc.Index],Subgraph_Ma, Input_CalcLength.GetInt());

where did I go wrong?

Reply With Quote
  #4 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 360


hhomsi8 View Post
MA[sc.Index] = sc.SimpleMovAvg(s[sc.Index],Subgraph_Ma, Input_CalcLength.GetInt());

where did I go wrong?

This is all you need. Have a look at the example for the function.

 
Code
sc.SimpleMovAvg(s[sc.Index], Subgraph_Ma, Input_CalcLength.GetInt());
There is no MA[sc.Index] =

Follow me on Twitter Reply With Quote
Thanked by:




Last Updated on September 17, 2023


© 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