How to make custom symbols (spreads)

I was trying to figure out a way of adding some spreads as symbols and track them in a realtime manner , i tried the ADDTOCOMPOSITE() function but it doesnt update the spread as the relatime data comes in and also doesnt compute the full history of the spread , is there an alternative way to achieve this where my spreads are like any other normal symbols .

As you mentioned it's possible to use AddToComposite() to create/update a ticker. In that case run your script using Scan/Explore at regular interval to update it (using Auto-Repeat in Settings of your Scan/Exploration). Select "All quotes" in Range. Don't forget to use the atcFlagResetValues. Everything is in the user's guide. In particular read How to create your own exploration.

This thread may also help you:

You can also store your spreads in static variables instead of tickers (using StaticVarSet)
Last note: in most use cases it's fine to recompute spreads on the fly when needed.

PS: here is an example of a single formula for both Scanning & Charting.

SetBarsRequired(sbrAll,sbrAll); // for StaticVarAdd if QuickAFL is ON

ticker1 = ParamStr("Ticker 1", "ESZ1-GLOBEX-FUT");
ticker2 = ParamStr("Ticker 2", "NQZ1-GLOBEX-FUT");
tickerspread = ParamStr("Spread Name/ticker", "ES-NQ");

A = Foreign(ticker1, "C");
B = Foreign(ticker2, "C");

f = Param("factor1", 4, 0.5, 6, 0.5);
g = Param("factor2", 1, 0.5, 6, 0.5);

// Only in Analysis/Scan
Spread = f*A-g*B;
AddToComposite(Spread, "~"+tickerspread, "C", atcFlagResetValues|atcFlagDeleteValues);

// Only in Charts here, but could be used instead of ATC in Scan
if (Status("ActionEx") == actionIndicator) {
	StaticVarSet("Spread"+tickerspread, Spread); 
}

Plot(Foreign("~"+tickerspread, "C"), ""+f+"*ES-"+g+"*NQ", colorDefault);
Plot(StaticVarGet("Spread"+tickerspread), ""+f+"*ES-"+g+"*NQ Bis", colorBlue,styleLine|styleLeftAxisScale); // Check/Visual Test

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.