NexusFi: Find Your Edge


Home Menu

 





Difficulty with a relatively basic EMA bar-cross indicator


Discussion in EasyLanguage Programming

Updated
    1. trending_up 2,806 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

  #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:	114
Size:	34.9 KB
ID:	315346  
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Cheap historycal L1 data for stocks
Stocks and ETFs
REcommedations for programming help
Sierra Chart
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Better Renko Gaps
The Elite Circle
 
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

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
  #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
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

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