Login Page - Create Account

Support Board


Date/Time: Tue, 26 Nov 2024 06:46:09 +0000



[User Discussion] - ACSIL code generated by Chat GPT

View Count: 2457

[2023-04-11 16:52:09]
Tony - Posts: 518
A user named Matias Quadro mentioned in this post that he managed to generated a study by Chat GPT, thought give it a try with Google Chat GPT, which only works in Chrome right now.

I typed "Sierra Chart ACSIL display last close price cross whole chart" and got this:


#include "sierrachart.h"

SCDLLName("Last Price Example")

SCSFExport scsf_LastPrice(SCStudyInterfaceRef sc)
{
if (sc.SetDefaults)
{
sc.GraphName = "Last Price";
sc.StudyDescription = "Displays the last traded price";
sc.GraphRegion = 0;
sc.AutoLoop = 0;
sc.FreeDLL = 1;

sc.Subgraph[0].Name = "Last Price";
sc.Subgraph[0].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[0].PrimaryColor = RGB(0, 255, 0);
return;
}

sc.Subgraph[0][sc.Index] = sc.BaseData[SC_LAST][sc.Index];
}

That is very interesting, didn't work though, until I made some modifications:


  for (int IndexCount {sc.Index}; IndexCount>sc.IndexOfFirstVisibleBar; IndexCount--)
    sc.Subgraph[0][IndexCount] = sc.BaseData[SC_LAST][sc.Index];

Maybe I asked the wrong question, I will try Bing's Chat GPT later, since I don't have access to Edge browser at this point...
Date Time Of Last Edit: 2023-04-11 16:53:47
[2023-04-12 09:50:10]
ForgivingComputers.com - Posts: 960
This would have also made it work:

sc.AutoLoop = 1;

[2023-04-15 16:01:33]
eaglefutures - Posts: 48
This code here
c++ multiple header files

is all ChatGPT. I have never coded anything and probably am not going to understand half of it.
Its able to go through changes, rename stuff, etc , reformat the stuff , add comments.

It is very much trial and error for me, as I do not know what is incorrect and cant spot it.

But it has been able to build some stuff, just takes some time and back and forth questions.
I would not be able to write this on my own.
[2023-04-15 22:17:27]
Tony - Posts: 518
Just a matter of time I guess, took me 3 years from zero knowledge about ACSIL to
comfortably coding basic studies. Using ACSIL to control Orders/Positions is always
scary, I am really worried about suffering some big loss if there are any fatal
mistakes in my coding.

Thanks for sharing your experiences.
[2023-04-15 23:35:22]
ondafringe - Posts: 286
You are right to be worried. Just make certain you thoroughly SIM your algo -- both backtesting and forward testing -- before going live. And when you do go live, only trade one micro until your live forward test proves out, and never let your algo trade without you monitoring things -- just in case.

I can remember my algo trading in SIM and then, out of nowhere, something went wrong and it started placing orders right and left and before I knew it, I suddenly had, like, a 100 open positions. Even in SIM, that's enough to give you a simulated heart attack! lol
Date Time Of Last Edit: 2023-04-16 13:32:54
[2023-04-16 12:01:09]
58LesPaul - Posts: 429
Could someone tell me what I did wrong? I added bradh's line to the bottom of the code but it shows nothing. Within SC studies it shows up as

Custom Study DLL(LastPriceExample.dll v2486)

I select the + beside that and it will expand and show "Template Function"



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

// For reference, refer to this page:
// Advanced Custom Study Interface and Language (ACSIL)

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

//This is the basic framework of a study function. Change the name 'TemplateFunction' to what you require.
SCSFExport scsf_TemplateFunction(SCStudyInterfaceRef sc)
#include "sierrachart.h"



SCDLLName("Last Price Example")



SCSFExport scsf_LastPrice(SCStudyInterfaceRef sc)

{

if (sc.SetDefaults)

{

sc.GraphName = "Last Price";

sc.StudyDescription = "Displays the last traded price";

sc.GraphRegion = 0;

sc.AutoLoop = 0;

sc.FreeDLL = 1;

sc.AutoLoop = 1;

sc.Subgraph[0].Name = "Last Price";

sc.Subgraph[0].DrawStyle = DRAWSTYLE_LINE;

sc.Subgraph[0].PrimaryColor = RGB(0, 255, 0);

return;

}



sc.Subgraph[0][sc.Index] = sc.BaseData[SC_LAST][sc.Index];

}

I assume I can't just copy/paste the code from above because the colors disappear.
Date Time Of Last Edit: 2023-04-16 12:37:31
[2023-04-16 12:55:08]
58LesPaul - Posts: 429
Is this what the above study should look like? the green line connecting last prices?
Date Time Of Last Edit: 2023-04-16 12:56:02
imageNAS100 [CV-D][M] Daily #2 2023-04-16 07_53_30.556.png / V - Attached On 2023-04-16 12:54:56 UTC - Size: 51.88 KB - 205 views
[2023-04-16 13:36:02]
ForgivingComputers.com - Posts: 960
If you are going to use something like ChatGPT, don't expect miracles. You also should be able to understand what it is doing or you are asking for trouble. If your goal is to learn ACSIL, then the examples provided by Sierra Chart are much more useful than the code generated by a Chatbot.

Back to your study.

You have extra and incorrect lines of code that are causing this to break. This function has no curly brackets:
SCSFExport scsf_TemplateFunction(SCStudyInterfaceRef sc)

This is all that you need:

#include "sierrachart.h"
SCDLLName("Last Price Example")

SCSFExport scsf_LastPrice(SCStudyInterfaceRef sc)
{
  if (sc.SetDefaults)
  {
    sc.GraphName = "Last Price";
    sc.StudyDescription = "Displays the last traded price";
    sc.GraphRegion = 0;
    sc.AutoLoop = 1;

    sc.Subgraph[0].Name = "Last Price";
    sc.Subgraph[0].DrawStyle = DRAWSTYLE_LINE;
    sc.Subgraph[0].PrimaryColor = RGB(0, 255, 0);

    return;
  }

  sc.Subgraph[0][sc.Index] = sc.BaseData[SC_LAST][sc.Index];

}

[2023-04-16 13:38:51]
User431178 - Posts: 541
the examples provided by Sierra Chart are much more useful than the code generated by a Chatbot
Yes, this 100%
[2023-04-17 21:37:39]
58LesPaul - Posts: 429
If you are going to use something like ChatGPT, don't expect miracles. You also should be able to understand what it is doing or you are asking for trouble. If your goal is to learn ACSIL, then the examples provided by Sierra Chart are much more useful than the code generated by a Chatbot.

Yeah, I'm just messing around to see what AI would do.

Thanks
[2023-12-20 15:40:52]
j4ytr4der_ - Posts: 938
ChatGPT is my personal coding assistant for all my study work, and sometimes even complex alert formulas. It's completely changed everything with regards to what I (think I) can do, and has enabled me to regularly crank out very sophisticated studies that I would otherwise have had zero idea of how to pull off.

However, it will pretty much never spit out functional code on the first try. It will typically get you 80% to 90% of the way there, but you have to get the code over the finish line. Lots of reading of documentation and experimenting, has accomplished this for me every time.
[2023-12-20 16:06:16]
j4ytr4der_ - Posts: 938
And just to illustrate, I got tired of using spreadsheets to get Open P&L, so I whipped up my own Open P&L study, using chatGPT to do most of the actual coding. Took about 20 minutes total and now works great. Here's the chat in case it's helpful to anyone else looking to do the same type of thing:


User
I need a study which will output the current open profit & loss to a subgraph. In the SC documentation I found the following example code, how could it be modified such that it outputs the Open P&L number into a subgraph?

sc.CreateProfitLossDisplayString()

Type: Function

void CreateProfitLossDisplayString(double ProfitLoss, int Quantity, PositionProfitLossDisplayEnum ProfitLossFormat, SCString& Result);

The sc.CreateProfitLossDisplayString() function creates a Profit/Loss text string based on the provided parameters.

The Result parameter is passed by reference and receives the formatted Profit/Loss text string.

Parameters
ProfitLoss: The profit or loss value as a floating-point number.
Quantity: The Position or Trade quantity.
ProfitLossFormat: The profit or loss format. The possibilities are: PPLD_DO_NOT_DISPLAY, PPLD_CURRENCY_VALUE, PPLD_POINTS, PPLD_POINTS_IGNORE_QUANTITY, PPLD_TICKS, PPLD_TICKS_IGNORE_QUANTITY, PPLD_CV_AND_POINTS, PPLD_CV_AND_POINTS_IGNORE_QUANTITY, PPLD_CV_AND_TICKS, PPLD_CV_AND_TICKS_IGNORE_QUANTITY. For descriptions of these, refer to Profit/Loss Format.
Result: A SCString variable to receive the formatted profit/loss string.
Example
if (ShowOpenPL.GetYesNo())
{
SCString PLString;
double Commission = RTCommissionRate * PositionData.PositionQuantity / 2.0;
sc.CreateProfitLossDisplayString(PositionData.OpenProfitLoss-Commission, PositionData.PositionQuantity, ProfitLossDisplayFormat, PLString);
Text.Format("Open PL: %s", PLString.GetChars());
}

ChatGPT
To output the current open profit and loss to a subgraph, you can use the CreateProfitLossDisplayString function and set the result to a subgraph value. Here's an example modification of the provided code:

cpp
Copy code
SCSubgraphRef Subgraph_OpenPL = sc.Subgraph[0]; // Assuming you have defined a subgraph in your study

// ... (other variable declarations and study initialization)

if (ShowOpenPL.GetYesNo())
{
SCString PLString;
double Commission = RTCommissionRate * PositionData.PositionQuantity / 2.0;

// Calculate Open P&L
double OpenPL = PositionData.OpenProfitLoss - Commission;

// Create profit/loss display string
sc.CreateProfitLossDisplayString(OpenPL, PositionData.PositionQuantity, ProfitLossDisplayFormat, PLString);

// Output the Open P&L to the subgraph
Subgraph_OpenPL[sc.Index] = OpenPL;

// Optionally, you can also output the formatted string to the debug subgraph
Subgraph_Debug[sc.Index] = PLString;

// ... (rest of your code)
}
In this example, Subgraph_OpenPL is assumed to be a subgraph that you have defined in your study. Adjust the subgraph index accordingly based on your actual subgraph setup. The Open P&L value is calculated, and the result is assigned to the subgraph at the current index (sc.Index). Additionally, the formatted profit/loss string is output to a debug subgraph (Subgraph_Debug), but you can omit this part if not needed.

Make sure to adapt the code to fit into your existing study structure and variable definitions.

User
How are you calculating commissions here? Where does RTCommissionRate come from?
ChatGPT
I apologize for the oversight. It seems there was an assumption in the provided code regarding the presence of RTCommissionRate, which wasn't defined in your original code.

To calculate commissions, you need to use the commission rate applicable to your trading scenario. You can replace RTCommissionRate with the actual commission rate you want to apply. If your commissions are fixed per trade, you can replace it with a fixed commission value.

Here's an example assuming a fixed commission per trade:

cpp
Copy code
double CommissionRate = 0.01; // Replace with your actual commission rate (e.g., 1%)
double Commission = CommissionRate * PositionData.PositionQuantity;
In the modified code snippet:

cpp
Copy code
SCSubgraphRef Subgraph_OpenPL = sc.Subgraph[0]; // Assuming you have defined a subgraph in your study

// ... (other variable declarations and study initialization)

if (ShowOpenPL.GetYesNo())
{
SCString PLString;

// Calculate Open P&L without commission
double OpenPL = PositionData.OpenProfitLoss;

// Calculate commission (replace 0.01 with your actual commission rate)
double CommissionRate = 0.01; // Replace with your actual commission rate (e.g., 1%)
double Commission = CommissionRate * PositionData.PositionQuantity;

// Subtract commission from Open P&L
OpenPL -= Commission;

// Create profit/loss display string
sc.CreateProfitLossDisplayString(OpenPL, PositionData.PositionQuantity, ProfitLossDisplayFormat, PLString);

// Output the Open P&L to the subgraph
Subgraph_OpenPL[sc.Index] = OpenPL;

// Optionally, you can also output the formatted string to the debug subgraph
Subgraph_Debug[sc.Index] = PLString;

// ... (rest of your code)
}
Replace 0.01 with your actual commission rate, and adjust the code as needed based on your commission structure.

User
This appears to be working with a display string, when all I want is the value stored in a subgraph that I can reference from elsewhere. Is this still the right way to go about that?
ChatGPT
I appreciate your clarification. If you want to store the open profit and loss directly in a subgraph without using a display string, you can modify the code accordingly. Here's the updated code snippet:

cpp
Copy code
SCSubgraphRef Subgraph_OpenPL = sc.Subgraph[0]; // Assuming you have defined a subgraph in your study

// ... (other variable declarations and study initialization)

if (ShowOpenPL.GetYesNo())
{
// Calculate Open P&L without commission
double OpenPL = PositionData.OpenProfitLoss;

// Calculate commission (replace 0.01 with your actual commission rate)
double CommissionRate = 0.01; // Replace with your actual commission rate (e.g., 1%)
double Commission = CommissionRate * PositionData.PositionQuantity;

// Subtract commission from Open P&L
OpenPL -= Commission;

// Output the Open P&L to the subgraph
Subgraph_OpenPL[sc.Index] = OpenPL;

// ... (rest of your code)
}
In this modification, OpenPL is directly assigned to the subgraph at the current index (sc.Index). Now, you can reference the values stored in the Subgraph_OpenPL from elsewhere in your study.

Ensure that you have defined the subgraph appropriately in your study, and adjust the subgraph index and other details based on your specific requirements.

User
We don't appear to be declaring PositionData
ChatGPT
You're correct, and I appreciate your diligence. The variable PositionData wasn't defined in the provided code snippets. The PositionData typically represents the information about the current position, and it's assumed to be available in Sierra Chart. However, if it's not available directly, you might need to access it through appropriate Sierra Chart functions.

Here's an example of how you might declare and use PositionData:

cpp
Copy code
SCFloatArrayRef PositionProfitLoss = sc.GetPersistentFloatArray(1);

// ... (other variable declarations and study initialization)

if (ShowOpenPL.GetYesNo())
{
s_SCPositionData PositionData;
sc.GetTradePosition(PositionData);

// Calculate Open P&L without commission
double OpenPL = PositionData.OpenProfitLoss;

// Calculate commission (replace 0.01 with your actual commission rate)
double CommissionRate = 0.01; // Replace with your actual commission rate (e.g., 1%)
double Commission = CommissionRate * PositionData.PositionQuantity;

// Subtract commission from Open P&L
OpenPL -= Commission;

// Output the Open P&L to the subgraph
Subgraph_OpenPL[sc.Index] = OpenPL;

// Store PositionData in a persistent array for future reference if needed
PositionProfitLoss[sc.Index] = OpenPL;

// ... (rest of your code)
}
This assumes that Sierra Chart provides a function GetTradePosition to fetch position information. If such a function doesn't exist, you may need to check the Sierra Chart documentation or use other available functions to retrieve the necessary position data.

[2023-12-22 07:40:44]
eaglefutures - Posts: 48
Hi
@j4ytr4der
ChatGPT is my personal coding assistant for all my study work, and sometimes even complex alert formulas. It's completely changed everything with regards to what I (think I) can do, and has enabled me to regularly crank out very sophisticated studies that I would otherwise have had zero idea of how to pull off.

Glad that you got this working for you.
I think my coding skills are too limited. I got over my initial Euphoria with using Chatgpt in its current state of "brain" as the effort to fix what it was doing in the code was like working with a monkey in the car workshop.
Each time I would fix something it had previously botched, it would go and silently mess up something somewhere else in the code. I would spend hours back and forth and it would regurgitate some random stuff to the point of arguing with me that what it was doing was correct.

I have no doubt in the future we will be able to use this to code. I do suspect and without sounding like a conspiracy theorist.
We are receiving dumbed down versions or consumer versions which are very rudimentary. I think there may be folks with access to the real deal.

Which versions of Chatgpt are you using that seems to be working ? Is it the new release of it or are you using some of the other ai.
How do you actually prompt this to get it to stay on track.

I find it goes random to the point of driving me crazy, it loses the whole point of what was trying to be built in the first place and then comes up with pseudo code.

I love the part where it says and puts it in the code "and this is where you fill in the rest"
I would say in 2-3 Years we will be in a new paradigm, you could probably just through documentation at it and it would figure it out.
When it starts to say hey, I dont need to code I can actually trade this myself and make some money for my ai army, then Houston we got a problem :)
[2023-12-22 08:00:52]
j4ytr4der_ - Posts: 938
I'm just using plain old free chatGPT. 3.5 I guess it is? Main thing is you can't expect it to spit out a fully complete study. This just won't work. It will make up imaginary functions and capabilities that sound very convincing but don't even exist.

What works well for me is having a pretty clear idea of what I need to do, and all the logic behind it worked out. If I can either write or find some code that is related or near to what I want, even better (I've used the included source codes from SC studies as starting points a bunch of times now). As you can see in the chat I pasted above, I fed it some code, then had to massage it from there. But you're right, it will start just giving you fragments, and if you don't realize that, you'll get really messed up. You can always say "Now give me the complete code" and it will give you everything, so that's worth considering.

Really you have to treat it as an assistant. It won't do the entire job for you, but it will bang out code faster than you probably can unless you're a highly skilled coder already, in which case you're probably faster just writing the thing anyway.

Speaking of documentation... I regularly give it the entire function definition from the docs when I'm doing something, since it often gets things wrong or tries to do something a very "non-SC" way. So it will do its own thing with some imaginary function, or sometimes just with stock C++ stuff that isn't how SC would do something. So I'll copy & paste the relevant section of the docs and just say "Here is the docs for the xxxxxxxxx function, try again using this" and it will take a new approach based on what it has now "learned".

Anyway, I love it but it's definitely more to get me a good part of the way there, and not to just spit out a working study. Everything has to be hand tweaked quite a lot, but even then I'll go back with my tweaks when I'm stuck on something and just tell it what I'm stuck on, and paste it the relevant code section I'm working on - giving it a little context about the goal - and it has been very helpful. I do find that on long conversations it starts to really bog down and get confused, so when that starts happening I'll often start a new conversation, explain just enough so it has context for what we're now doing, and just kinda pick up where we left off. Then it starts working well again (until it bogs down, again...)

But yeah, where this will be in a few years is going to be insane.

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

Login

Login Page - Create Account