ProRealCode - Trading & Coding with ProRealTime™
The indicators when applied to Indices would be using the bars from all the 24 hours to calculate (including the hours when no global equity markets open), and not just the bars from the trade hours (or the trade hours + pre/post market hours). Is there anyway to fix or adjust this for an indicators AND for automatic trading signals?
As IG keep trading for 24 hours on markets, even if a specific market (+ its pre & post market, and its futures) are not being traded anywhere in globe. Would this be giving incorrect readings & incorrect long/short signals for a lot of indicators for any chart using a timeframe less than the daily?
This would especially be a problem for Asian Markets, for example if we think of the Nikkei (TSE), or the Hang Seng (HKEX) there is 4 to 5 hours of no global equities market open before their respective markets open. The TSE opens at 0900am Tokyo Time, and its pre-market index futures only opens 15 minutes prior to that at 0845am. Meaning from US markets closing to TSE index futures opening in pre-markets there is 3 hours 45 minutes of no global equity markets open. The Hang Seng then opens later on, which does get about 1 hour of Tokyo and Australia markets trading for its calculations, but still those markets is in no way reflective of China’s current markets conditions though? This might only be an issue for IG users as i don’t see my futures or indices charts showing bars outside of open markets on other platforms charts i use.
On this reasoning, if (as attached image) Hang Seng for example (14) on 15 minutes, start calculation 4.5 hours prior at New York time = 1600 (At market close) = calculations made up mostly of no global equities markets open. Now any calculations on more bar would be taking in futures movement (out of Hong Kong market hours) which is mostly related to USA and Europe markets conditions and not the Hong Kong markets. If used a (14) on a 1 hour chart, means we starting calculation 14 hours earlier, which also means after the Hong Kong markets closed.
Now so i did look at the Hang Seng 50 Indices compared to a random Hang Seng 50 ETF traded only during the HK market times (image 2), and i did indeed see there is a big difference in the signals. The ETF as only taking signals from HK markets which on this chart appears to be giving more correct signals for opening a SHORT based on a trend 2 days ago (on the 2nd of August) at start of trade and closing this about 8 bars later just before lunch as the trend weakens. The time period after this however, unlike the indices, it wouldn’t open any trade, as there was no spike up and then back down to give the start of trade downtrend on the 3rd, and the ADX was weakening (not increasing as was the indices), with other flat market signals unlike the indices. If anything the moving average was uptrend (green) at start of trade for the ETF = correct, vs red for the indices = incorrect. Meaning on the 3rd of August it was a lot more correctly giving the signals, compared to the indices chart.
As such is there any way i can be calculating the indicators for only the bars occurring trade hours of the market and ignoring calculating on the bars outside of market trade? For example [14] at market open means the 14 bars (during markets) before markets closed yesterday, and not the 14 bars (outside of markets) before market opened today. And code this for automatic strategies? So when doing an automatic strategy on the indices i’m getting correct signals (on volumes, trends etc..) related to its market ?
Can this be of help ?
TRSMA – TREMA – TRWMA
Hence theoretically you can make all the indicators yourself and filter by time period(s). And you have a few examples at hand now.
I agree that this 24/7 thing is nothing less than disturbing.
Even if you could achieve what you ask above … assuming you are trading with IG, will you not get gaps (could be big at times?) at most market open where the price IG have been quoting (while ‘official’ markets closed) has changed from official market close?
Will these gaps affect your Indicators and / or Reject your Trading Systems?
Not thought about it deeply … too early, coffee not worked throught yet! 🙂
Can this be of help ? TRSMA – TREMA – TRWMA
will you not get gaps (could be big at times?) at most market open where the price IG have been quoting (while ‘official’ markets closed) has changed from official market close? Will these gaps affect your Indicators and / or Reject your Trading Systems?
Hi – well its far past coffee time in this part of the world > past dinner time here. But yes definitely would get gaps, and i would like them personally (For official markets open) – it would only help and not hinder/reject indicators. Gapping itself (if big eg. 2% up at offical HK market open, from yesterdays close) would make most of the indicators (and various moving averages etc..) all suggest a strong price movement and a Bullish market to open Long on that conditions for day-trading. This would be how normal markets occur – when you watch any business news on TV they almost always say something like “the market is up 1% today” to suggest the conditions? Instead on a 24hr chart the market for example the market could also be up 2% from yesterday but indicators saying the markets is “bearish conditions” cos of the bigger price movements that come from USA Indices (US market movement) the night prior to Asia markets opening the next morning. The example i shared the screenshot from HK market it did gap up (although small of about 0.5%) from yesterdays close, so if anything would be to go for a LONG position if Technical Indicators calculated ONLY on trading hours, other indicators like the moving average went up too to also suggest a Bullish market. But however “Movements”/ Trend strength indicators (from the ETF/ only trade hour) like ADX showed the market was weak, so no trade, which appears correct looking at market. BUT when go over to on a 24hr chart with its pseudo price movements then my indicators on that example instead showed a ‘Downward’ trend because the price went up lots during the US markets hours (cos HK closed it just followed US Indices movements) and as such technical indicators calculating from that ‘incorrectly think’ the markets going down at open but its not it’s up (gapped up 0.5%). It also incorrectly thinks it’s “Strong” because compared to “0” trade volumes and “0” movements that occurred when no global markets were open in the prior 4-odd hours the trend is strong (relative). In hindsight on one example to illustrate the issue i am facing.
I would assume also that the academic’s, qaunt’s or investment bankers that studied the various technical indicators they created would of done so on normal markets conditions without ’24hr charting extensions’ that IG does ?
For reference the current way i have been getting around this bug/issue with PRT/IG charts in the past is all my strategies don’t open any trades during first 2 hours of Asian* market open, and then i use very low number of bars/periods to calculate my indicators (eg. [4], [6], or [8]) this way they don’t use any of the pseudo (false, or fake IG made-up) data from outside market trading times with-in their calculations, but just the bars since market opened, and thus their subsequent buy/sell signals.
*I have a less concern this for other markets as they have longer pre-markets periods, and thus use “real data’ & not made-up data in their prices and thus indicators calculations.
There is also the dimension of Settling Times. Best (or most weighing) example is the DAX (Germany40 ? or whatever IG calls it). This settles (like all European Futures) at underlaying stock closing time (17:30 Amterdam) but happily continues itself, drawn by USA. Like yesterday (my) morning, it was at +1% while (underlaying pre-market) USA was at ~0%.
Normally this is only a visual issue (no issue for Autotrading and what you are dealing with), but when we see that underlaying starts to behave towards that Future (Index for IG) hence stocks really grow towards 1% around opening (09:00 Amsterdam), … then you see how a complex (system as a whole) it all is especially because all the Bloomberg’s of the world keep telling me that Europe does great and USE is so-so (with Asia somewhere in between). But the “great” really springs from last day’s Settling Time which was long before closing so it allowed to grow along with USA and thus starts next opening at 1% (USA resetting to 0% at 22:00 Amsterdam (which also is Settling Time) while happily continuing until 23:00.
A bit in your street (this would be Dutch I guess) is that the opening of the other European Futures next to the DAX (which opened at 02:15 Amsterdam) can all be predicted, when they open at 08:00, by means of looking at the DAX.
And then PRT keeps telling us that it is impossible to look at other instruments (yes we know about “Calculated Instruments”) from within the chart we trade (AutoTrading). It would be the best improvement ever as it really really currently lacks.
This is my working progress, i’ve tried adjust for the ADX to base on only ‘real data’ aka when the markets (and/or its pre-markets and post-market) are open. But i’m not sure i’ve got it right? As some of the values appear not right, eg. the DI+ values seem very high and up near 100 ?
// Because 24hrs charts contain data from when the specific instrument or equity isnt trading on markets, and are just using charting extension or using other markets data instead, and is possible source of error in computation of indicators compared to 'real data' from market time. This is using the bars of when the market, and its pre/post (aka equities futures) markets are open for a more accurate ADX, and Directional movements computations using only bars within the set time-frame.
// Time Range ADX
Periods = 14
//**-- Adjusted for the USA market --**
//Pre and Post Market Hours
FuturesStartTime = 090000
FuturesEndTime = 163000
//Only regular markets hours:
StartTime = 093000 // Pre Market Open
EndTime = 160000 // Post Market Clos
// Calculate the +DM and the -DM
// IF opentime[1] >= FuturesStartTime AND opentime <= FuturesEndTime THEN
IF opentime[1] >= StartTime AND opentime <= EndTime THEN
plusDM = max(high-high[1], 0)
minusDM = max(low[1]-low, 0)
IF plusDM > minusDM THEN
minusDM = 0
ENDIF
IF plusDM < minusDM THEN
plusDM = 0
ENDIF
IF plusDM = minusDM THEN
plusDM = 0
minusDM = 0
ENDIF
endif
// Compute the directional indicators
// Set intial values to 0
plusDI = 0
minusDI = 0
i = 0
// start counting ABS of plusDI and minusDI for [j] during trade times
FOR j = 0 TO 3000
// IF opentime[j] >= FuturesStartTime AND opentime[j] <= FuturesEndTime THEN
IF opentime[j] >= StartTime AND opentime[j] <= EndTime THEN
i = i + 1
plusDI = plusDI + plusDM[j]
minusDI = minusDI + minusDM[j]
IF i = Periods THEN
BREAK
ENDIF
ENDIF
NEXT
// IF opentime >= FuturesStartTime[1] AND opentime <= FuturesEndTime THEN
IF opentime >= StartTime[1] AND opentime <= EndTime THEN
// Compute the DI's using the periods during the trade hours from earlier
TTTR=max(abs(high-close),max(abs(low-close),range))
TTATR=average[periods](TTTR)
endif
plusDI = 100*(plusDI / Periods)/TTATR
minusDI = 100*(minusDI / Periods)/TTATR
DirectionalIndex = plusDI-minusDI
// Compute the ADX's using the periods during the trade hours from earlier
IF opentime >= StartTime[1] AND opentime <= EndTime THEN
TTADX=100*average[periods](abs(plusDI - minusDI)/(plusDI + minusDI))
TTADXR=(TTADX+TTADX[14])/2
endif
//ENDIF
if time>=StartTime and time<=EndTime then
backgroundcolor(10,255,10, 30)
endif
if time>FuturesStartTime and time<=FuturesEndTime then
backgroundcolor(250,244,42,50)
endif
// Graph this data:
Return plusDI as "DI+", minusDI as"DI-", DirectionalIndex style (histogram) as "DI", TTADX as "ADX", TTADXR as "ADXR", 23, 0
without ’24hr charting extensions’ that IG does
Have you tried using separate data display settings for each Instrument you Trade … see attached at red arrowhead?separate data display settings for each Instrument you TradeThanks, that actually would be a lot easier then re-coding every single indicator. BUT will come with an extra cost of 0.5% fee’s when using the US Indices instrument in your example ( aka USD-based chart), instead of ‘CFDA’ instrument choice (Australian/AUD based CFDs) : “CFDs traded in a currency other than your account’s base currency incurs a currency conversion charge of 0.5%” . – IG Australia But changing to a USA-denominated Futures Chart does indeed make the technical indicators look more accurate, with both my coded above and the in-built look more similar now (image-1 attached). Although they are still different at some points, unsure why this difference is there if the functions are calculating correctly thus giving the same values ¯\_(ツ)_/¯.
‘CFDA’ instrument choice (Australian/AUD based CFDs) :Adjusting times isn’t possible for the CFDA’s instrument neither, because for some odd reason CFDA’s Local market time-zone on PRT is UTC +1:00 (London time) > which in itself is just useless (and creates a big problem) as Australian AEST is 9 hours ahead of London time. So even if i could adjust it, i cant because most of the Asian pre-markets start before the 00:00 (UTC +1:00). Doing this way i could, changing the display/market data to start from 00:00 London time, could probably be the best option?
Have you tried and what, you get a message saying
Periods = 100
YesterdayObvClose = 0
//Only regular markets hours:
StartTime = 093000
EndTime = 160000
//If want to use bars from Futures Markets also:
FuturesStartTime = 040000
FuturesEndTime = 200000
TradeTimes = ( time => StartTime AND time <= EndTime )
// The functions that compute On-Balance Volume Value
IF opentime >= StartTime AND opentime <= EndTime THEN
//IF opentime >= FuturesStartTime AND opentime <= FuturesEndTime THEN
IF close > close[1] then
OBVol = OBVol[1] + Volume[1]
elsif close < close[1] then
ObVol = ObVol[1] - Volume[1]
elsif close = close[1] then
OBVol = ObVol[1]
endif
endif
// Start the counting for the average of the OBV from within trade time bars, for the oscillator
i = 0
TTSMA = 0
FOR j = 0 TO 3000
IF opentime >= StartTime[j] AND opentime <= EndTime[j] THEN
//IF opentime >= FuturesStartTime[j] AND opentime <= FuturesEndTime[j] THEN
i = i + 1
TTSMA = TTSMA + OBVol[j]
IF i = Periods THEN
BREAK
ENDIF
ENDIF
NEXT
IF opentime >= StartTime AND opentime <= EndTime THEN
TTSMA = (TTSMA / Periods)
endif
//Out of trade times need to keep the OBV value from Close time until the next days Start Time
OBVClose = 0
OBVClosen = (17.5)*4 //17.5 hrs from close to next day open, Bars Back for a 15min chart
OBVClosei = 1
If opentime >= EndTime OR opentime <= Starttime THEN
WHILE OBVClosei < OBVClosen DO
IF opentime[OBVClosei] = EndTime THEN
OBVol = OBVol[OBVClosei] // Save the CLOSE value for OBV
TTSMA = TTSMA[OBVClosei] // Save the Close value of SMA of OBV
BREAK
ENDIF
OBVClosei = OBVClosei + 1 // Keep counting
WEND
endif
// OBV Oscillator options:
Diff = OBVol - TTSMA
//Perc = Diff/TTSMA*100
RETURN Diff STYLE(histogram,2) AS "OBV Oscillation", 0
// Time Range ADX - set for HK market:
Periods = 14
StartTime = 093000
EndTime = 160000
//For markets with lunch breaks
LunchStartTime = 120000
LunchEndTime = 130000
plusDM = max(high-high[1], 0)
minusDM = max(low[1]-low, 0)
IF plusDM > minusDM THEN
minusDM = 0
ENDIF
IF plusDM < minusDM THEN
plusDM = 0
ENDIF
IF plusDM = minusDM THEN
plusDM = 0
minusDM = 0
ENDIF
TTTR=max(abs(high-close),max(abs(low-close),range))
// Compute the directional indicators
// Set intial values to 0
plusDI = 0
minusDI = 0
i = 0
TTATR = 0
// start counting plusDI and minusDI for [j] during trade times
FOR j = 0 TO 3000
// Uncomment the time option used:
// IF opentime[j] >= StartTime AND opentime[j]<=EndTime THEN
// IF opentime >= FuturesStartTime[j] AND opentime <= FuturesEndTime[j] THEN
IF opentime[j] >= StartTime AND opentime[j] <= LunchStartTime OR opentime[j]>=LunchEndTime and opentime[j]<=EndTime THEN
plusDI = plusDI + plusDM[j]
minusDI = minusDI + minusDM[j]
TTATR= TTATR + TTTR[j]
i = i + 1
IF i = Periods THEN
BREAK
ENDIF
ENDIF
NEXT
// Compute the DI's using the periods during the trade hours from earlier
TTATR=TTATR/Periods
plusDI = 100*(plusDI / Periods)/TTATR
minusDI = 100*(minusDI / Periods)/TTATR
DirectionalIndex = plusDI-minusDI
TTADX = 0
i2 = 0
// Compute the ADX's using the periods during the trade hours from earlier
FOR j2 = 0 TO 3000
// Uncomment the time option used:
// IF opentime >= FuturesStartTime[j] AND opentime <= FuturesEndTime[j] THEN
//IF opentime[j2] >= StartTime AND opentime[j2]<=EndTime THEN
IF opentime[j] >= StartTime AND opentime[j] <= LunchStartTime OR opentime[j]>=LunchEndTime and opentime[j]<=EndTime THEN
TTADX = TTADX + (abs(plusDI - minusDI)/(plusDI + minusDI))[j2]
i2 = i2 + 1
IF i2 = Periods THEN
BREAK
ENDIF
ENDIF
NEXT
TTADX=100*(TTADX/Periods)
i3 = 0
TTADXR = 0
FOR j3 = 0 TO 3000
// Uncomment the time option used:
// IF opentime >= FuturesStartTime[j] AND opentime <= FuturesEndTime[j] THEN
// IF opentime[j2] >= StartTime AND opentime[j2]<=EndTime THEN
IF opentime[j] >= StartTime AND opentime[j] <= LunchStartTime OR opentime[j]>=LunchEndTime and opentime[j]<=EndTime THEN
TTADXR = TTADXR + TTADX[j3]
i3 = i3 + 1
IF i3 = Periods THEN
BREAK
ENDIF
ENDIF
NEXT
TTADXR=TTADXR/Periods
// Graph this data:
if opentime>=StartTime AND opentime<=EndTime then
backgroundcolor(10,255,10, 30)
endif
// To Compare to PRT Inbuilts:
// PRTADX = ADX[14]
// PRTDIPLUS = DIPLUS [14]
// PRTDIMINUS = DIMINUS[14]
Return plusDI as "DI+", minusDI as"DI-", DirectionalIndex style (histogram) as "DI", TTADX as "ADX", TTADXR as "ADXR", 23 as "23"
Indicators use 24hrs and NOT just Trade Hrs Bars > how fix these wrong signals ?
This topic contains 27 replies,
has 4 voices, and was last updated by SkippyTrader
3 years, 5 months ago.
| Forum: | ProBuilder: Indicators & Custom Tools |
| Language: | English |
| Started: | 08/04/2022 |
| Status: | Active |
| Attachments: | 21 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.