Login Page - Create Account

Support Board


Date/Time: Tue, 26 Nov 2024 08:37:50 +0000



[Programming Help] - c++ multiple header files

View Count: 839

[2023-04-15 15:51:59]
eaglefutures - Posts: 48
hello support, couple of caveats, am new to coding.

I am trying to make it easier to manage the code, by having 3 separate files. They all do not give any errors in VScode, but when I compile they do. I have included the header files at the top which are not sierrachart.h as written in the help docs.

The files are as follows Order_Management to store all the order types.
Signal Management to collect various signals,
SystemA, this does the execution bit after reading the other two.

Is this the correct approach firstly to do this?
is it possible to do this in sierracharts as I get this error msg repeatedly. and have absolutely no idea what this is.


Error Messages

[vcvarsall.bat] Environment initialized for: 'x64'
SystemA.cpp
Creating library SystemA.lib and object SystemA.exp
SystemA.obj : error LNK2001: unresolved external symbol "void __cdecl GetSignalsFromProviders(struct s_sc &,int &,int &,struct s_SCInput_145 &,struct s_SCInput_145 &)" (?GetSignalsFromProviders@@YAXAEAUs_sc@@AEAH1AEAUs_SCInput_145@@2@Z)
SystemA.obj : error LNK2001: unresolved external symbol "void __cdecl ExecuteMarketBuyEntry(struct s_sc &,int)" (?ExecuteMarketBuyEntry@@YAXAEAUs_sc@@H@Z)
SystemA.obj : error LNK2001: unresolved external symbol "void __cdecl ExecuteMarketSellEntry(struct s_sc &,int)" (?ExecuteMarketSellEntry@@YAXAEAUs_sc@@H@Z)
C:\SierraChart\Data\SystemA_64.dll : fatal error LNK1120: 3 unresolved externals
-- End of Build -- 10:31:42



Order Management.h File

#pragma once
#include "sierrachart.h"

void ExecuteMarketBuyEntry(SCStudyInterfaceRef sc, int order_quantity);
void ExecuteMarketSellEntry(SCStudyInterfaceRef sc, int order_quantity);
void ExecuteLimitBuyEntry(SCStudyInterfaceRef sc, int order_quantity, float price);
void ExecuteLimitSellEntry(SCStudyInterfaceRef sc, int order_quantity, float price);



Order Management.cpp File

#include "Order_Management.h"

void ExecuteMarketBuyEntry(SCStudyInterfaceRef sc, int order_quantity) {
s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = order_quantity;
NewOrder.OrderType = SCT_ORDERTYPE_MARKET;
NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;

sc.BuyEntry(NewOrder);
}

void ExecuteMarketSellEntry(SCStudyInterfaceRef sc, int order_quantity) {
s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = order_quantity;
NewOrder.OrderType = SCT_ORDERTYPE_MARKET;
NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;

sc.SellEntry(NewOrder);
}


void ExecuteLimitBuyEntry(SCStudyInterfaceRef sc, int order_quantity, float price) {
s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = order_quantity;
NewOrder.OrderType = SCT_ORDERTYPE_LIMIT;
NewOrder.Price1 = price; // Updated from NewOrder.LimitPrice
NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;

sc.BuyEntry(NewOrder);
}

void ExecuteLimitSellEntry(SCStudyInterfaceRef sc, int order_quantity, float price) {
s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = order_quantity;
NewOrder.OrderType = SCT_ORDERTYPE_LIMIT;
NewOrder.Price1 = price; // Updated from NewOrder.LimitPrice
NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;

sc.SellEntry(NewOrder);
}




Signal Management.cpp

#include "Signal_Management.h"

void GetSignalsFromProviders(SCStudyInterfaceRef sc, int& signal1, int& signal2, SCInputRef i_sbg1Ref, SCInputRef i_sbg2Ref)
{
// Retrieve the 1 or -1 values from the SignalProvider1 indicator
SCFloatArray SignalProvider1;
sc.GetStudyArrayUsingID(i_sbg1Ref.GetStudyID(), i_sbg1Ref.GetSubgraphIndex(), SignalProvider1);
signal1 = static_cast<int>(SignalProvider1[sc.Index]);

// Retrieve the 1 or -1 values from the SignalProvider2 indicator
SCFloatArray SignalProvider2;
sc.GetStudyArrayUsingID(i_sbg2Ref.GetStudyID(), i_sbg2Ref.GetSubgraphIndex(), SignalProvider2);
signal2 = static_cast<int>(SignalProvider2[sc.Index]);
}




Signal Management.h
#pragma once
#include "sierrachart.h"

void GetSignalsFromProviders(SCStudyInterfaceRef sc, int& signal1, int& signal2, SCInputRef i_sbg1Ref, SCInputRef i_sbg2Ref);




SystemA.cpp

#include "Order_Management.h"
#include "Signal_Management.h"

#include "sierrachart.h"

SCDLLName("SimpleSysA")

SCSFExport scsf_Modified_SC_TradingCrossOverExample(SCStudyInterfaceRef sc)
{
SCInputRef i_sbg1Ref = sc.Input[0];
SCInputRef i_sbg2Ref = sc.Input[1];

SCInputRef i_AllowMultipleEntriesInSameDirection = sc.Input[2];
SCInputRef i_MaximumPositionAllowed = sc.Input[3];
SCInputRef i_SupportReversals = sc.Input[4];

SCInputRef i_SendOrdersToTradeService = sc.Input[5];
SCInputRef i_AllowOppositeEntryWithOpposingPositionOrOrders = sc.Input[6];
SCInputRef i_SupportAttachedOrdersForTrading = sc.Input[7];

SCInputRef i_CancelAllOrdersOnEntriesAndReversals = sc.Input[8];
SCInputRef i_AllowEntryWithWorkingOrders = sc.Input[9];
SCInputRef i_CancelAllWorkingOrdersOnExit = sc.Input[10];
SCInputRef i_AllowOnlyOneTradePerBar = sc.Input[11];

SCInputRef i_OrderQuantity = sc.Input[12];
SCInputRef i_EnableLongs = sc.Input[2];
SCInputRef i_EnableShorts = sc.Input[3];

SCSubgraphRef sbg_Signal = sc.Subgraph[2];

SCSubgraphRef sbg_BuyEntry = sc.Subgraph[0];
SCSubgraphRef sbg_SellEntry = sc.Subgraph[1];

if (sc.SetDefaults)
{
sc.GraphName = "Modified Trading CrossOver Example 1";

sc.StudyDescription = "Test System";

sc.AutoLoop = 1;
sc.GraphRegion = 0;
sc.CalculationPrecedence = LOW_PREC_LEVEL;

i_sbg1Ref.Name = "Buy Entry Subgraph";
i_sbg1Ref.SetStudySubgraphValues(1, 0);

i_sbg2Ref.Name = "Sell Entry Subgraph";
i_sbg2Ref.SetStudySubgraphValues(1, 0);

i_AllowMultipleEntriesInSameDirection.Name = "Allow Multiple Entries in Same Direction";
i_AllowMultipleEntriesInSameDirection.SetYesNo(false);

i_MaximumPositionAllowed.Name = "Maximum Position Allowed";
i_MaximumPositionAllowed.SetInt(5);

i_SupportReversals.Name = "Support Reversals";
i_SupportReversals.SetYesNo(true);

i_SendOrdersToTradeService.Name = "Send Orders to Trade Service";
i_SendOrdersToTradeService.SetYesNo(false);

i_AllowOppositeEntryWithOpposingPositionOrOrders.Name = "Allow Opposite Entry with Opposing Position or Orders";
i_AllowOppositeEntryWithOpposingPositionOrOrders.SetYesNo(false);

i_SupportAttachedOrdersForTrading.Name = "Support Attached Orders for Trading";
i_SupportAttachedOrdersForTrading.SetYesNo(false);

i_CancelAllOrdersOnEntriesAndReversals.Name = "Cancel All Orders on Entries and Reversals";
i_CancelAllOrdersOnEntriesAndReversals.SetYesNo(true);

i_AllowEntryWithWorkingOrders.Name = "Allow Entry with Working Orders";
i_AllowEntryWithWorkingOrders.SetYesNo(false);

i_CancelAllWorkingOrdersOnExit.Name = "Cancel All Working Orders on Exit";
i_CancelAllWorkingOrdersOnExit.SetYesNo(true);

i_AllowOnlyOneTradePerBar.Name = "Allow Only One Trade per Bar";
i_AllowOnlyOneTradePerBar.SetYesNo(true);

i_OrderQuantity.Name = "Order Quantity";
i_OrderQuantity.SetInt(1);

i_EnableLongs.Name = "Enable Longs";
i_EnableLongs.SetYesNo(true);

i_EnableShorts.Name = "Enable Shorts";
i_EnableShorts.SetYesNo(true);

sbg_Signal.Name = "Signal";
sbg_Signal.DrawStyle = DRAWSTYLE_BAR;
sbg_Signal.PrimaryColor = RGB(0, 128, 0);
sbg_Signal.SecondaryColor = RGB(128, 0, 0);
sc.MaintainTradeStatisticsAndTradesData = true;

return;
}

int signal1 = 0;
int signal2 = 0;
GetSignalsFromProviders(sc, signal1, signal2, i_sbg1Ref, i_sbg2Ref);

if (signal1 == 1 && i_EnableLongs.GetYesNo())
{
sbg_BuyEntry[sc.Index] = sc.Low[sc.Index];
ExecuteMarketBuyEntry(sc, i_OrderQuantity.GetInt());
sbg_Signal[sc.Index] = 1;
}

if (signal2 == -1 && i_EnableShorts.GetYesNo())
{
sbg_SellEntry[sc.Index] = sc.High[sc.Index];
ExecuteMarketSellEntry(sc, i_OrderQuantity.GetInt());
sbg_Signal[sc.Index] = -1;
}
}


[2023-04-15 16:20:41]
eaglefutures - Posts: 48
ok I got this working now. It was to include the CPP type of files and not the actual header files and do a multiple selection as usual.

I was referencing this here,
Advanced Custom Study Interface and Language (ACSIL): Using Your Own Header Files

and it may need a expert to take a look at what is described as it says header files and source code files. So I took 2 headers and the systemA.cpp and it bombs.

But when I tried with the 3 cpp file only and then it worked.
Still would be interested to understand if this is a good approach or is there another way, as I am struggling to read through all these lines of code.

Thank you

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

Login

Login Page - Create Account