The easiest way to share data within charts is to use GlobalDictionary. Using GlobalDictionary, you can share data between multiple timeframe charts and make decisions for your strategy based on different timeframe analyses.
There is not much information on the internet, however, you can find a good example in the Tradestation forums.
Here are the examples that I have tested and it is easily modified based on your requirement.
For Receiver:
using elsystem ;
using elsystem.collections ;
inputs:
Key1( "ESU13_0_5" ),
Key2( "ESU13_0_21" ),
Key3( "ESU13_0_89" ),
Key4( "ESU13_0_377" ),
Key5( "ESU13_0_1597" ),
Key6( "ESU13_0_6765" ) ;
variables:
intrabarpersist double CurrentValue1( 0 ),
intrabarpersist double CurrentValue2( 0 ),
intrabarpersist double CurrentValue3( 0 ),
intrabarpersist double CurrentValue4( 0 ),
intrabarpersist double CurrentValue5( 0 ),
intrabarpersist double CurrentValue6( 0 ),
intrabarpersist double CurrentSum( 0 ),
GlobalDictionary GD1( NULL ) ;
method void GDUpdated( Object Sender, ItemProcessedEventArgs args )
begin
Switch ( args.Key )
begin
Case Key1: CurrentValue1 = GD1.Items[Key1] astype double ;
Case Key2: CurrentValue2 = GD1.Items[Key2] astype double ;
Case Key3: CurrentValue3 = GD1.Items[Key3] astype double ;
Case Key4: CurrentValue4 = GD1.Items[Key4] astype double ;
Case Key5: CurrentValue5 = GD1.Items[Key5] astype double ;
Case Key6: CurrentValue6 = GD1.Items[Key6] astype double ;
end ;
CalcSum() ;
PlotOutputs() ;
end ;
method void CalcSum ()
begin
CurrentSum = CurrentValue1 + CurrentValue2 + CurrentValue3 +
CurrentValue4 + CurrentValue5 + CurrentValue6 ;
end ;
method void PlotOutputs ()
begin
Plot1( CurrentSum, "CurrentSum" ) ;
Plot2( 0, "ZeroLine" ) ;
Plot3( 6, "BuyThresh" ) ;
Plot4( - 6, "SellThresh" ) ;
end ;
once
begin
GD1 = GlobalDictionary.Create( true, "SignalInfo" ) ;
GD1.ItemChanged += GDUpdated ;
if GD1.Contains( Key1 ) then
CurrentValue1 = GD1.Items[Key1] astype double ;
if GD1.Contains( Key2 ) then
CurrentValue2 = GD1.Items[Key2] astype double ;
if GD1.Contains( Key3 ) then
CurrentValue3 = GD1.Items[Key3] astype double ;
if GD1.Contains( Key4 ) then
CurrentValue4 = GD1.Items[Key4] astype double ;
if GD1.Contains( Key5 ) then
CurrentValue5 = GD1.Items[Key5] astype double ;
if GD1.Contains( Key6 ) then
CurrentValue6 = GD1.Items[Key6] astype double ;
CalcSum() ;
PlotOutputs() ;
end ;
PlotOutputs() ;
For Sender
using elsystem ;
using elsystem.collections ;
inputs:
PosColor( DarkGreen ),
NegColor( DarkRed ) ;
variables:
intrabarpersist string Key( " " ),
intrabarpersist double PriorValue( 0 ),
intrabarpersist bool NotAChart( false ),
double CurrentValue( 0 ),
GlobalDictionary GD1( NULL ) ;
once
begin
NotAChart = GetAppInfo( aiApplicationType ) <> cChart ;
Key = Symbol + "_" + NumToStr( BarType, 0 ) + "_" + NumToStr( BarInterval, 0 ) ;
GD1 = GlobalDictionary.Create( true, "SignalInfo" ) ;
if GD1.Contains( Key ) = false then
GD1.Add( Key, 0 ) ;
end ;
// initial GDic update
once ( LastBarOnChartEX )
begin
GD1.Items[Key] = CurrentValue astype double ;
end ;
//==============================================
// USER LOGIC
// You can put your logic here
// Assign a +1 or -1 to currentvalue
inputs:
FastAvgLen( 9 ),
SlowAvgLen( 18 ) ;
variables:
FastAvgValue( 0 ),
SlowAvgValue( 0 ) ;
FastAvgValue = Average( Close, FastAvgLen ) ;
SlowAvgValue = Average( Close, SlowAvgLen ) ;
if FastAvgValue > SlowAvgValue then
CurrentValue = 1
else if FastAvgValue < SlowAvgValue then
CurrentValue = -1 ;
// End of user calculations
//===============================================
// if currentvalue changes update the GDic
if CurrentValue <> PriorValue then
GD1.Items[Key] = CurrentValue astype double ;
// plot values
Plot1( Key, "Name" ) ;
Plot2( CurrentValue, "Value" ) ;
if NotAChart then
begin
if CurrentValue = 1 then
SetPlotBGColor( 2, PosColor )
else
SetPlotBGColor( 2, NegColor ) ;
end ;
// Update intrabarpersist vars
// for next pass
PriorValue = CurrentValue ;
You can change the variable based on the stocksymbol + bartype + barinterval to retrieve data in the receiver.
Hope this help for all algorithmic trader.