1. 首页
  2. 易语言 - EasyLanguage
  3. 共享内存同步技巧 Shared Memory Synchronization Techniques

共享内存同步技巧 Shared Memory Synchronization Techniques

本文讲述如何在一个或多个图表同步多个分析技术,全局变量、ELC、ADE、 DLL共享内存。

This page discusses how to synchronize multiple studies on single and multiple charts. It is important for Global Variables, Collections for EasyLanguage (ELC) and All-Data-Everywhere (ADE), as well as any other DLL based shared memory applications.

The information given is down to a single person’s testing. If this is important to you and you think the calculation order can affect your P&L then you should do your own testing. TradeStation do not support the synchronization of data between multiple charts.

The problem is how to get your indicators/strategies to run in the correct order so that ‘Indicator A’ calculates a value and puts it into shared memory before ‘Indicator B’ looks into shared memory and retrieves that value. If you don’t synchronize correctly then ‘Indicator B’ will retrieve the value before ‘Indicator A’ has calculated it. So you end up with ‘old’ data. Of course, sometimes ‘old’ means only one tick old but sometimes it can also means much longer.

  • The first thing to know is that TS runs things in series. That is, it calculates an indicator from the first bar on a chart to the last bar, and when it’s finished it moves onto the next indicator. Strategies operate slightly differently in that when you apply two or more strategies to a chart they become part of a ‘strategy group’. Each strategy within the group takes its turn to calculate a bar before moving onto the next bar. A strategy group will run for every bar on the chart before moving on to any indicators. i.e. strategies always run before indicators.
  • Testing was done using a simple indicator/strategy
Inputs: ChartID(1); 

print("Chart ID: ", ChartID:0:0, " - ", ComputerDateTime:4:10);
  • ‘ChartID’ is changed for each chart that the indicator/strategy is applied to, then the Print Log monitored to see which indicator/strategy ran first. This assumes that the Print Log operates in the same order that the indicators/strategies calculate. TS staff have confirmed that this is true.
  • The word “Indicator” means Indicator, PaintBar or ShowMe.
  • The terminology “A-B-A-B-A-B” means Indicator/Strategy A runs first then Indicator/Strategy B, then A, then B, then A and finally B. When it is necessary to show more detail, the terminology “A1-B1-A2-B2-A3-B3” has been used. This means the first tick was processed by Indicator/Strategy A and then processed by Indicator/Strategy B. Then the second tick was processed by A and then B. And then the third tick was processed by A and then B.
  • These tests were run on Build 3159, so things may change with future builds or versions.

On the same chart

his section refers to synchronizing indicators/strategies that are all applied to the same chart.

  1. Indicator to Indicator
    Indicators are calculated in the order in which they are applied to the chart.
    Testing was done with up to four indicators and it held true.
    Attempts were made to change the calculation order by:
    • re-verifying the indicators
    • turning the status of the indicators to off and then back to on
    • changing the value of indicator inputs
    • moving the indicators to different sub-graphs
      But none of these made any difference to the calculation order.
  2. Indicator to Strategy
    Strategies are always calculated before indicators. Therefore, it is not possible to synchronize in this direction.
  3. Strategy to Indicator
    Strategies are always calculated before indicators. Therefore, sending data from a strategy to an indicator on the same chart will always be synchronized.
  4. Strategy to Strategy
    Strategies are calculated in the order in which they are listed in the Format Strategies screen. Their order can be changed by using the ‘Move Up’ and ‘Move Down’ buttons.
If more than one strategy is applied to a chart then it automatically becomes part of a ‘strategy group’. Each strategy within the group then takes turns to calculate each bar on the chart before moving onto the next bar.

On multiple charts on multiple workspace

This section refers to synchronizing indicators/strategies that are applied to separate charts located in the same workspace.

An illustration of running the following indicator code on different charts and in different workspaces.

inputs: 
	ChartID( 1 ) ; 
 
print( "Chart ID: ",NumToStr(ChartID,0), " " , ComputerDateTime:4:10 ) ; 

For each separate chart, format the indicator and set the input ChartID to a different number. On each chart have the “Update value intrabar” setting checked.

When the code runs you may see a repeatable sequence of chart ordering, but then press Control-R on 1 or more of the charts. When the charts refresh and reload the data, you may see the ordering of chart execution change. This ordering change can occur across charts and across workspaces.

For example, I ran this code on 4 charts, 3 in one workspace and 1 in a second workspace. Initially the output to the print log was like:

Chart ID: 3 39084.7190856481
Chart ID: 4 39084.7190856481
Chart ID: 2 39084.7190856481
Chart ID: 1 39084.7190856481
Chart ID: 3 39084.7193055556
Chart ID: 4 39084.7193055556
Chart ID: 2 39084.7193055556
Chart ID: 1 39084.7193055556
Chart ID: 3 39084.7193287037
Chart ID: 4 39084.7193287037
Chart ID: 2 39084.7193287037
Chart ID: 1 39084.7193287037

Then after a refresh:

Chart ID: 3 39084.7259953704
Chart ID: 4 39084.7259953704
Chart ID: 1 39084.7259953704
Chart ID: 2 39084.7259953704
Chart ID: 3 39084.7260069444
Chart ID: 4 39084.7260069444
Chart ID: 1 39084.7260069444
Chart ID: 2 39084.7260069444
Chart ID: 3 39084.7260416667
Chart ID: 4 39084.7260416667
Chart ID: 1 39084.7260416667
Chart ID: 2 39084.7260416667

Notice that charts 1, 2, and 3 were all in the 1st workspace, and chart 4 was in a separate workspace, yet chart 4 ran after chart 3 but before charts 1 and 2 — so the 3 charts that were all in the same workspace weren’t run in chart creation sequence or all run together before a chart in another workspace ran.

Since a refresh can occur outside of a user control (i.e., because of a network disconnect or server farm generated refresh), the initial chart / workspace ordering may not be maintained and you can’t rely on that ordering.

更新于 2020年6月3日

这篇文章对您有帮助吗?

相关的话题

留言评论