Support Board
Date/Time: Wed, 05 Mar 2025 04:27:30 +0000
Post From: create a custom C++ class that manages trade/logic
[2022-01-07 21:21:22] |
User133994 - Posts: 80 |
To whom it may concern, Great product--again. Thanks. I am trying to create a simple C++ class to manage trades, trading logic, etc. Basically to keep all "trade" related items/functions together, etc. However, this all must be done on an "indicator"--thus the class needs to be usable from the indicator--and be persistant. Here is what I tried (an excerpt), which finally did compile: class pSellOrder {
//p is for persistent--doesn't matter which sc.Index is used--this will always refer to the "existing" sell order //not hiding any internal variables at this point...just keeping them together..will grow this class as needed //NOTE: have to use a *pointer* to access sc functions see this discussion for more //sc. structure passed by reference as default value to all functions UPDATE: this caused problems public: //constructor to gain access to sc...I hope pSellOrder(SCStudyInterfaceRef sc):p_sc(&sc) {} int& ParentInternalOrderIDstop = p_sc->GetPersistentInt(11); int& Target1OrderIDstop = p_sc->GetPersistentInt(1); int& Stop1OrderIDstop = p_sc->GetPersistentInt(2); int& Target2OrderIDstop = p_sc->GetPersistentInt(3); int& Stop2OrderIDstop = p_sc->GetPersistentInt(4); int& Target3OrderIDstop = p_sc->GetPersistentInt(5); int& Stop3OrderIDstop = p_sc->GetPersistentInt(6); int& Target4OrderIDstop = p_sc->GetPersistentInt(7); int& Stop4OrderIDstop = p_sc->GetPersistentInt(8); //---------------------- int& ParentInternalOrderIDstop_entrybar = p_sc->GetPersistentInt(28); int& ParentInternalOrderIDstop_entrybar_writeonce = p_sc->GetPersistentInt(29); float& ParentInternalOrderIDstop_price = p_sc->GetPersistentFloat(2); int active () { return (1); } private: s_sc* p_sc; }; So I use pSellOrder pSO(sc);
in the indicator that is attached to my chart; and I set things like this: if (pSO.ParentInternalOrderIDstop != 0)
{ s_SCTradeOrder TradeOrderData; int Result = sc.GetOrderByOrderID(pSO.ParentInternalOrderIDstop, TradeOrderData); } However, I am obviously not doing it correctly because when I attach the indicator to the chart I receive this error: Warning: This Custom DLL study may cause Sierra Chart to be unstable until you remove the study from the chart and restart Sierra Chart. | 2022-01-07 14:13:09.921 *
Warning: The Custom DLL study "jjcUBTradingSysPB.scsf_jjc_TradingUB_PB" has just caused a CPU exception. | 2022-01-07 14:13:16.957 * This is likely from my use of p_sc...I am not confident that I have figured out how to access the "sc" object from my custom class. Please help. I searched and searched and there are no user-customized example classes in ACSIL that access the sc object with all of it's information on a custom study. If I missed it, please point me to a working example. Yes, there are a hundred way to do things--I know I've read much--I am just wanting to know how to use my custom built C++ class (with persistant variables) to use in a custom indicator--which requires access to the sc object inside the class. I could try it another way and I might have to...but for now, would you be able to help me figure this out? Thanks in advance! |