NexusFi: Find Your Edge


Home Menu

 





Difficulty with a relatively basic EMA bar-cross indicator


Discussion in EasyLanguage Programming

Updated
    1. trending_up 2,762 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 1 attachments




 
Search this Thread

Difficulty with a relatively basic EMA bar-cross indicator

(login for full post details)
  #1 (permalink)
nukespace
Orlando, FL
 
Posts: 2 since Jul 2021
Thanks Given: 0
Thanks Received: 0

Hey all,

I'm trying to create a basic EMA bar-cross indicator in EL for use in TradeStation's scanner. The criteria are:
  • +1 if the price crosses positively over the EMA (Last > EMA > Open)
  • -1 if the price crosses negatively below the EMA (Open > EMA > Last)
  • 0 otherwise

It's a relatively simple criterion, and in its basic form I can already implement it within the Scanner app. The issue, however, is that the scanner's price parameters (Open, High, Low, Close, etc.) are restricted to a granularity of one day, whereas I want to be able to operate on a timeframe of something like 5 min.

I'm by no means a novice to programming, but I've only had to interact with EasyLanguage a couple of times. I created this indicator which looks correct, but does not work correctly:
 
Code
inputs:
	Length( 55 ) [
		DisplayName = "Length",
		ToolTip = "The EMA period to use."
	],
	Price( Last ) [
		DisplayName = "Price", 
		ToolTip = "The final price to use in the computation."
	];

Value1 = 0;
if (Price > XAverage(Close, Length)) and (XAverage(Close, Length) > Open) then begin 
	Value1 = 1;
end;
if (Price < XAverage(Close, Length)) and (XAverage(Close, Length) < Open) then begin 
	Value1 = -1;
end;

Plot1( Value1, "Oscillator" ) ;
Plot2( 0, "ZeroLine" ) ;
Attached is a snippet of the results on a random equity from the Scanner (VXX, 5min). It compiles, but it seems to ignore the positive crosses (where the value should be +1) and it also sustains a value, which it should not do. I've confirmed that the positive crosses do appear within the sample (i.e. it's not just "close"). The magenta line is an EMA with the same period as the indicator should be screening for (55).

Any ideas or suggestions on where I went wrong?

Thanks in advance.

Attached Thumbnails
Click image for larger version

Name:	badIndicator.PNG
Views:	109
Size:	34.9 KB
ID:	315346  
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Request for MACD with option to use different MAs for fa …
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Futures Close-Out Policy
Commodities
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Daytrading ES & NQ
32 thanks
Spoo-nalysis ES e-mini futures S&P 500
28 thanks
Battlestations: Show us your trading desks!
24 thanks
Retail Trading As An Industry
24 thanks

(login for full post details)
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,429 since Apr 2013
Thanks Given: 479
Thanks Received: 1,619

nukespace,

welcome to futures.io. Last is a quote field that does not carry any history, but will return the current last price whenever you call it. Try using Close instead.

Regards,

ABCTG


nukespace View Post
Hey all,

I'm trying to create a basic EMA bar-cross indicator in EL for use in TradeStation's scanner. The criteria are:
  • +1 if the price crosses positively over the EMA (Last > EMA > Open)
  • -1 if the price crosses negatively below the EMA (Open > EMA > Last)
  • 0 otherwise

It's a relatively simple criterion, and in its basic form I can already implement it within the Scanner app. The issue, however, is that the scanner's price parameters (Open, High, Low, Close, etc.) are restricted to a granularity of one day, whereas I want to be able to operate on a timeframe of something like 5 min.

I'm by no means a novice to programming, but I've only had to interact with EasyLanguage a couple of times. I created this indicator which looks correct, but does not work correctly:
 
Code
inputs:
	Length( 55 ) [
		DisplayName = "Length",
		ToolTip = "The EMA period to use."
	],
	Price( Last ) [
		DisplayName = "Price", 
		ToolTip = "The final price to use in the computation."
	];

Value1 = 0;
if (Price > XAverage(Close, Length)) and (XAverage(Close, Length) > Open) then begin 
	Value1 = 1;
end;
if (Price < XAverage(Close, Length)) and (XAverage(Close, Length) < Open) then begin 
	Value1 = -1;
end;

Plot1( Value1, "Oscillator" ) ;
Plot2( 0, "ZeroLine" ) ;
Attached is a snippet of the results on a random equity from the Scanner (VXX, 5min). It compiles, but it seems to ignore the positive crosses (where the value should be +1) and it also sustains a value, which it should not do. I've confirmed that the positive crosses do appear within the sample (i.e. it's not just "close"). The magenta line is an EMA with the same period as the indicator should be screening for (55).

Any ideas or suggestions on where I went wrong?

Thanks in advance.


Follow me on Twitter Reply With Quote
(login for full post details)
  #3 (permalink)
nukespace
Orlando, FL
 
Posts: 2 since Jul 2021
Thanks Given: 0
Thanks Received: 0



ABCTG View Post
nukespace,

welcome to futures.io. Last is a quote field that does not carry any history, but will return the current last price whenever you call it. Try using Close instead.

Regards,

ABCTG

Well, I had a feeling it was a stupid mistake - and I was right. I thought I would've tried Close as a quick test, but apparently I didn't.

Now, will this still assert intrabar? That is, if the condition is met at 2.5 minutes into a 5 min candle, will the indicator read 1/-1 prior to the period closing?

Thanks for the help in the right direction. I'm still trying to get the hang of EasyLanguage.

n.s.

Reply With Quote
(login for full post details)
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,429 since Apr 2013
Thanks Given: 479
Thanks Received: 1,619

nukespace,

this depends on your indicator settings. If you allow intrabar updates for the indicator in the settings it will.

Regards,

ABCTG


nukespace View Post
Well, I had a feeling it was a stupid mistake - and I was right. I thought I would've tried Close as a quick test, but apparently I didn't.

Now, will this still assert intrabar? That is, if the condition is met at 2.5 minutes into a 5 min candle, will the indicator read 1/-1 prior to the period closing?

Thanks for the help in the right direction. I'm still trying to get the hang of EasyLanguage.

n.s.


Follow me on Twitter Reply With Quote





Last Updated on July 26, 2021


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts