Support Board
Date/Time: Sun, 23 Feb 2025 22:13:39 +0000
[Programming Help] - turning a subgraph into a system error
View Count: 742
[2021-02-21 14:57:59] |
User61576 - Posts: 445 |
pls check the attached code this was taken from the studies (Ask/Bid Volume Difference Bars) which I am trying to turn into a trading system by using the example in TradingSystem.ccp when compiling it as is, I am getting lots of errors, but as far as I understand I need to redeclare the variables Subgraph_Close , Subgraph_High and Subgraph_Low although they were defined few lines above and yet I don't get exactly how to do it.I hope to get some explanation and assistance thanks |
![]() |
[2021-02-21 16:18:13] |
ForgivingComputers.com - Posts: 1012 |
You don't need to redeclare Subgraph_Close, etc. You need to use an array index. You are set for manual looping, so you cannot use [sc.Index]. Subgraph_Close[BarIndex] > 300
Also, you should not use sc.Arraysize as an index: Subgraph_Close[sc.ArraySize] = 0;
Arrays are zero-based, so you are pointing to an index that is greater than the last index. You should use Subgraph_Close[sc.ArraySize - 1] to address the last bar on the chart. Fortunately, Sierra Chart protects you from using out-of-bounds indices, so this is technically ok.
|
[2021-02-21 19:49:42] |
User61576 - Posts: 445 |
thanks for your replay the confusing point is what the same use of BarIndex was used successfully with the original example of tradingsystemp.cpp? (the macd crossover which was compiled) |
[2021-02-21 19:55:17] |
ForgivingComputers.com - Posts: 1012 |
BarIndex was used successfully with the original example of tradingsystemp.cpp
What the documentation does not make clear is that while you cannot use [sc.Index] with manual looping, you can do manual looping when autoloop is enabled. |
[2021-02-22 06:03:06] |
User61576 - Posts: 445 |
can it be that the function sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED is not returning anything due to the use of index?
|
[2021-02-22 07:17:35] |
Flipper_2 - Posts: 57 |
//Trading system based on the above calculations
//signal long if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED && Subgraph_Close > 300 && Subgraph_Low < -300) { //send order int Result = (int)sc.BuyEntry(NewOrder); // send the mkt order if (Result > 0) //If there has been a successful order entry, then draw an arrow at the low of the bar. { Subgraph_Buy[sc.Index] = sc.Low[sc.Index] - OffsetPercent * Range; Subgraph_Sell[sc.Index] = 0; } } //signal short else if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED && Subgraph_Close < 300 && Subgraph_High > 300) { //send order int Result = (int)sc.SellEntry(NewOrder); //send the mkt order if (Result > 0) //If there has been a successful order entry, then draw an arrow at the high of the bar. { Subgraph_Sell[sc.Index] = sc.High[sc.Index] + OffsetPercent * Range; Subgraph_Buy[sc.Index] = 0; } } else //if no signal condition met, do nothing { Subgraph_Buy[sc.Index] = 0; Subgraph_Sell[sc.Index] = 0; } This whole code block will not work. You have the study set on manual looping so sc.Index will not work. And then the whole block is outside the loop anyway. And Subgraph_Close < 300 will not work because you haven't provided an index for the Array, it should be something like Subgraph_Close[sc.Index] or Subgraph_Close[sc.Index - 1] for auto looping (which you haven't set) or Subgraph_Close[Index] if its in the main loop.You would be far better off making a new study just for the trading system and importing the arrays from other studies that you want to base your signals on using this, sc.GetStudyArrayUsingID() ACSIL Interface Members - Functions: sc.GetStudyArrayUsingID() |
[2021-02-22 18:32:24] |
User61576 - Posts: 445 |
Thanks for your assistance! the new study (the system) will inherit the other study's calculations? is there any known trading example for this? do I need to set per each value of the other study a different SCFloatArray StudyReference; so if I refer to a study with open/high/low/close I will need 4 floats, correct?
|
[2021-02-22 21:40:41] |
Flipper_2 - Posts: 57 |
Have a look at the example in C:\SierraChart\ACS_Source\TradingSystem.cpp scsf_TradingSystemStudySubgraphCrossover That trading system references two study arrays. And yes you need 4 SCFloatArrays not floats. Just another idea I wouldn't use sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED Far better to just reference the data 1 bar back then you know it has closed. so the line if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED && Subgraph_Close > 300 && Subgraph_Low < -300)
would be,if( Subgraph_Close[sc.Index-1] < 300 && Subgraph_Low[sc.Index-1] < -300) if using autolooping
|
[2021-02-23 08:32:18] |
User61576 - Posts: 445 |
I looked on scsf_TradingSystemStudySubgraphCrossover
they also do the same check condition for bar close if (Input_EvaluateOnBarCloseOnly.GetYesNo()
&& sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_NOT_CLOSED) { return; } so for learning purposes, how the above is different from your suggested solution of using [sc.Index-1]
thanks!
|
[2021-02-23 12:50:43] |
ForgivingComputers.com - Posts: 1012 |
Far better to just reference the data 1 bar back then you know it has closed.
Better in what way?Using if (Input_EvaluateOnBarCloseOnly.GetYesNo() will only process the steps once per bar. Using && sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_NOT_CLOSED) { return; } [sc.Index - 1] will process the steps multiple times per bar, and get the same results, but less efficiently.
|
To post a message in this thread, you need to log in with your Sierra Chart account: