NexusFi: Find Your Edge


Home Menu

 





Difficulty with a relatively basic EMA bar-cross indicator


Discussion in EasyLanguage Programming

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




 
Search this Thread
  #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:	195
Size:	34.9 KB
ID:	315346  
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Iran Update May 8: Still Reviewing MOU, Demands Reparati …
Traders Hideout
ATFX Suspends Prop Trading Unit ATFunded -- Full Review …
Funded Trading Evaluation Firms
Election Sunday Resolves: Peru Heads to Runoff at 42pct, …
Prediction Markets & Event Contracts
Powell in 48 Hours: Word Markets Give 78% on Inflation, …
Prediction Markets & Event Contracts
UMA Votes Tonight: Polymarkets $80M Strategy Bitcoin Bat …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
196 thanks
Sober Journey With S&P
27 thanks
30 Sessions
20 thanks
BERN ALGOS algo trading journal
8 thanks
Volume Indicators
8 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,642

nukespace,

welcome to NexusFi. 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 X 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 NexusFi. 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,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,642

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 X Reply With Quote




Last Updated on July 26, 2021


© 2026 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 - Downloads - Top
no new posts