Difficulty with a relatively basic EMA bar-cross indicator - futures io
futures io



Difficulty with a relatively basic EMA bar-cross indicator


Discussion in EasyLanguage Programming

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




Welcome to futures io: the largest futures trading community on the planet, with well over 150,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
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: 0 given, 0 received

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

Can you help answer these questions
from other members on futures io?
How do I create Strategy with the Second Entry indicator
NinjaTrader
Big Mo Indicator for NT8
NinjaTrader
How to pay for market data with Dorman LLC
NinjaTrader
help with take profit several targets
TradeStation
NT8 Order Management Strategy
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Is anyone actually making money?
88 thanks
An embarrassing, honest confession
25 thanks
Sierra vs. Ninja : why I chose .....
8 thanks
ApexTraderFunding.com experience and review
8 thanks
Want your NinjaTrader indicator created, free?
7 thanks
 
(login for full post details)
  #2 (permalink)
 ABCTG   is a Vendor
 
 
Posts: 2,361 since Apr 2013
Thanks: 426 given, 1,579 received

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: 0 given, 0 received



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,361 since Apr 2013
Thanks: 426 given, 1,579 received

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


futures io Trading Community Platforms and Indicators EasyLanguage Programming > Difficulty with a relatively basic EMA bar-cross indicator


Last Updated on July 26, 2021


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
     



Copyright © 2023 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), info@futures.io
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.
no new posts