Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I'm putting this in the NT programming section since there are more NT users here
I need some help creating some gapless indicators. Let's just start with a simple request, a gapless EMA. I will convert it to EasyLanguage after.
Let's say my chart is a RTH chart. The opening session gaps down 100 ticks from the prior day close. I would like to have my EMA 20 "close that gap". In other words, the first bar of the new session would take into account the gap (from session to session) and then it would automagically close the gap.
Some suggestions on making this happen? I can measure the gap, but then what action should I be taking? Should I use the length of the MA (ie, 20) and then do what with it? You guys know my math skills are terrible, so I'm just stuck here trying to figure out how to properly handle this.
Don't know if I understand well... for the 20 ema the logic could be:
- if the 20 bars are all in the same session, then calculate ema normally
- if some of this 20 bars are in the previous session, then add (or subtract) the gap to the bars of the previuos session and calculate ema accordingly.
This way you should have an ema that "gaps with the price".
I understand that you want to create a moving average that reflects the current session only. So you would want to restart it again and again, when the session starts.
There is a catch: The EMA or SMA formulae may not work, because the logic used only applies to continuous moving averages. I encountered this problem, when coding the anchored VWMA for the current session. I wanted to smooth it with a SMA(3). Could not use the native Ninja SMA for smoothing, because it would look back into the previous session. So only smoothed starting from the third bar of the new session onwards.
If you want to use a session related moving average, the anchored VWAP is quite interesting. You can then use the difference between an EMA(20) and the anchored VWAP as a trend filter.
I have used this method that i found at Tradestation forums, the author is John Mc.
The code is free and it is for Tradestation but it should work without problems for MULTICHART
My English is not good so I make the cut and paste of the explanation:
"
thought I’d share a method I use for handling opening gaps that seems to work well for both indicators and strategies.
There are approximately 17 hours between the close of the market one day and the open the next day. Significant trading volume may occur during after-hour trading. The opening gap up or down from the previous day's close is misleading. Trading just prior to the open may be sideways or converging from the opposite direction. Usually traders have to either restart their indicators at day beginning or allow enough bars to pass for their indicators to settle down.
I use a routine I call, "gapless," which avoids these problems by treating separate days in a manner similar to continuous contracts.
Vars:
RelO(0), // Relative Open
RelH(0), // Relative High
RelL(0), // Relative low
RelC(0), // Relative Close
gap(0), // the opening gap (modified by the gap coefficient)
GapCoef(1.0), // Gap Coefficient
Accum(0); // The sum of all the daily gaps
if date<>date[1] then
begin
gap = GapCoef*(O-C[1]);
Accum = Accum+gap;
end;
This is how it works: The opening “gap” is recorded for the first bar of each trading day.
A relative stream of OHLC's are calculated by subtracting this “gap” from the actual prices. This relative stream of OHLC’s are maintained right along side of the real OHLC’s. If the EL programmer needs to convert between the relative prices and the real price data, the sum of all the gap values is stored in the variable, “accum,” which makes the conversion simple.
If you’re squeamish about eliminating the opening gap altogether, I’ve included a “GapCoef,” that you can set between 0.00 and 1.00 to reduce part or all of the gap as you choose. For example, set the coefficient to 0.5 to reduce the gap by half. I prefer to eliminate the gap altogether so I set the coefficient to 1.0, which eliminates 100% of the opening gap.
Indicators, such as RSI and Stochastics, (see below examples) work fine with this relative price stream and never need to be converted back to real prices.
If you have an indicator that needs to be displayed on the same scale as the underlying data, simply add “accum,” i.e. (indicator + accum) as the last step prior to plotting. You can see an example of this with the Bollinger Band below (code included below in Gapless.ELD).
In order to work correctly, all manipulations (adding, averaging, etc...) should only be done with the relative data (RelO, RelH, RelL and RelC), then if the data needs to be returned to the real domain the variable "accum" is added as the last step.
Below, I've included several examples of indicators using "GapLess" code. The code for each is included below in GAPLESS.ELD. It includes %R, ATR, RSI, Fast Stochastics and Bollinger Bands. You'll see from the examples that any indicator or stategy can take advantage of this code.
The images below show the dramatic difference this approach can make.