Login Page - Create Account

Support Board


Date/Time: Mon, 25 Nov 2024 13:39:15 +0000



Passing a sierra chart function to another function

View Count: 284

[2024-03-03 14:46:14]
User371315 - Posts: 10
I'm trying to figure out the right syntax to pass a sc function to another function. Here's an example.

The function I'm passing another function into

void PlaceOrder(SCStudyInterfaceRef sc, BotConfig Config, int &InternalOrderID,
int32_t &Stop1OrderID, int32_t &Target1OrderID,
int &ActiveTrade, float CurrentBidAsk,
SCSubgraphRef Subgraph_BuySellEntry,
SCFloatArrayRef HighLowArray, // sc.Low/sc.High,
double (*OrderAction)(s_SCNewOrder &),
float (*HighestLowest)(SCFloatArrayRef, int, int),
const int TypeOfOrder, SCString Message)

PlaceOrder(sc, Config, InternalOrderID, Stop1OrderID, Target1OrderID,
ActiveTrade, sc.Bid, Subgraph_BuyEntry, sc.Low, &sc.BuyEntry,
&sc.GetLowest, BUY, OrderText);

The error that I get is this and I haven't been able to figure out by examples how to do this.

TradingBot.h: In function 'void tradeBot(SCStudyInterfaceRef, int, BotConfig, int&, int32_t&, int32_t&, int&, int, SCSubgraphRef, SCSubgraphRef, SCSubgraphRef, SCSubgraphRef)':
TradingBot.h:109:42: error: no matches converting function 'BuyEntry' to type 'double (*)(struct s_SCNewOrder&)'
109 | &sc.Lowest, BUY, OrderText);
| ^
In file included from TradeBotConfig.h:4,
from Trader.cpp:3:
sierrachart.h:1305:9: note: candidates are: 'double s_sc::BuyEntry(s_SCNewOrder&)'
1305 | double BuyEntry(s_SCNewOrder& NewOrder)//Automatic looping
| ^~~~~~~~

Does anyone have an example I can review or point me to the documentation? can't seem to find it!

TL;DR
Mainly these 2 function pointer definitions that I'm passing sc.BuyEntry and sc.GetLowest

double (*OrderAction)(s_SCNewOrder &),
float (*HighestLowest)(SCFloatArrayRef, int, int)

Date Time Of Last Edit: 2024-03-03 15:18:39
[2024-03-03 16:43:59]
User431178 - Posts: 541
Ignoring the fact that what you are doing seems convoluted, your function pointer syntax is wrong.
BuyEntry and GetLowest are not free functions, but members of s_sc class/struct, therefore the function pointers need to reflect that.


double (*OrderAction)(s_SCNewOrder &)

becomes


double (s_sc::*OrderAction)(s_SCNewOrder &)

then when you call the function you would use


&s_sc::BuyEntry

then within your actual function, you would end up with something like


auto result = (&sc->*OrderAction)(order);

As you are already passing in the sc structure reference, all of the above seems quite unnecessary and can be easily avoided.
Simply pass in an enum or id value to determine the action to take, then call the functions via the sc structure depending on which constant you have passed in.
Date Time Of Last Edit: 2024-03-03 16:45:08
[2024-03-03 17:23:44]
User371315 - Posts: 10
Thank you for the detailed answer and feedback! It sounded better in my head, but you are right it's just easy to pass in the type of order and have the function determine what it needs to do.

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

Login

Login Page - Create Account