NexusFi: Find Your Edge


Home Menu

 





Need some help with my Awesome Oscillator strategy


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one ABCTG with 3 posts (2 thanks)
    2. looks_two BTGUK with 3 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 SMCJB with 1 posts (1 thanks)
    1. trending_up 2,150 views
    2. thumb_up 3 thanks given
    3. group 3 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
BTGUK
London, United Kingdom
 
Posts: 3 since Aug 2018
Thanks Given: 3
Thanks Received: 0

Hi All,

I'm new to EasyLanguage, and try to make my first steps in it. My first real attempt to develop my own strategy is this one, which is based on the idea of the Awesome Oscillator indicator and which (if it was working) should scan for a Twin Peaks situation and then buy and sell accordingly.

After spending some time doing modal diagrams and thinking about what the strategy should do, I came up with some EL code. Only - it doesn't seem to do anything. Nothing.

So I'm hoping that someone who's more experienced than me could have a look at my code and tell me where it's going wrong?

Here's the masterpiece

 
Code
Inputs:
		AOShortPeriod(5),
		AOLongPeriod(34),
		NumStocks(100),
		TimeBegin(930),
		TimeEnd(1145),
		ExTime(1245),
		MaxEntry(10);
	

Variables:
		AOLong(0),
		AOShort(0),
		AO(0),
		LwMkr(0),
		HiMkr(0),
		Gd(0),
		Bool Dwnwrd(false),
		Bool Upwrd(false),
		Bool Xdwn(false),
		Bool Xup(false);

	
// Calculate AO

	AOLong = Average((High + Low)/2,AOLongPeriod);
	AOShort = Average((High + Low)/2,AOShortPeriod);
	AO = AOShort - AOLong;

// Detect direction

	Dwnwrd = AO < 0 and AO < AO[1] and AO[1] < AO[2];
	Upwrd = AO > 0 and AO > AO[1] and AO[1] > AO[2];


// Detect Xing

	Xdwn = (AO < 0) and (AO[1] = 0);
	Xup = (AO > 0) and (AO[1] = 0);
	
	
// Compute Running Condition

	If Dwnwrd and Xdwn then Gd = 1;
	If Upwrd and Xup then Gd = 2;
	
	
// Compute Entry	
	
	If (MarketPosition = 0) and (EntriesToday(Date) < MaxEntry) and Time > TimeBegin And Time < TimeEnd Then 
	Begin
		
		If (Gd = 1) then
		Begin
			
			if AO > AO[1] and AO[1] < AO[2] then
			Begin	
				if (LwMkr = 0) or ((LwMkr < 0) and (LwMkr < AO[1])) then LwMkr = AO[1];
				
				if (LwMkr < 0) and (LwMkr > AO[1]) then
				Begin
					Buy ("AOBuy") NumStocks shares next bar at market;
				LwMkr = 0;
				End;
			End;
		
			if AO > 0 then
			Begin
				Gd = 2;
				LwMkr = 0;
			End;
			
		End;

	End;
	
	
	
// Compute Exits
	
	If (MarketPosition = 1) and Time > TimeBegin And Time < TimeEnd Then 
	Begin
		
		If (Gd = 2) then
		Begin
			
			if AO < AO[1] and AO[1] > AO[2] then
			Begin	
				if (HiMkr = 0) or ((HiMkr > 0) and (HiMkr > AO[1])) then HiMkr = AO[1];
				
				if (HiMkr > 0) and (HiMkr < AO[1]) then
				Begin
					Sell ("AOSale") next bar at market;
					HiMkr = 0;
				End;
			End;
		
			if AO < 0 then
			Begin
				Gd = 1;
				HiMkr = 0;
			End;
			
		End;

	End;
	

	If (MarketPosition = 1) and Time > ExTime Then 
	Begin
		Sell ("AOExit") next bar at market;
	End;
Any ideas? Comments? Critique?

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
RSI Values Scale
NinjaTrader
TOS inspired trading simulator
ThinkOrSwim
Equity Monaco download file?
Psychology and Money Management
DOM in QTrader vs Bookmap
Platforms and Indicators
IBD Accumulation/Distribution Rating
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
11 thanks
Just another trading journal: PA, Wyckoff & Trends
8 thanks
Want your NinjaTrader indicator created, free?
3 thanks
Gradient Divergence Trading
2 thanks
Knowledge Nuggets from the Web
2 thanks
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,441 since Apr 2013
Thanks Given: 491
Thanks Received: 1,634


BTGUK,

welcome to NexusFi. A good way to find out why a strategy is not behaving like you think it does is using the print reserved word. You would simply add print statements within code blocks and when you execute your code you can see the print statements in the EasyLanguage Output log. This will
Another way is to turn parts of the logic into an input and plot the results, as sometimes it's a lot easier to see what is going on (or better not correctly working) when you have it plotted on a chart.

One thing to check is that AO[1] is actually 0 for some bars. Keep in mind that it might be unlikely that the two averages are exactly the same for one bar i.e. if they are different at the tenth decimal place only your condition would not be valid. If that is the problem, an alternative approach could be to check for AO crossing over and under 0 for example.

Apart from that what chart and interval settings did you apply the strategy to, so one could reproduce what you are seeing?

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
BTGUK
London, United Kingdom
 
Posts: 3 since Aug 2018
Thanks Given: 3
Thanks Received: 0

Hi ABCTG,

Thanks for your reply!


ABCTG View Post
A good way to find out why a strategy is not behaving like you think it does is using the print reserved word. You would simply add print statements within code blocks and when you execute your code you can see the print statements in the EasyLanguage Output log.

Thanks, I wasn't aware of this print facility, but it sounds like a good tool to probe what's going on in the strategy. I'll have to read more about it and then give it a try.


Quoting 
Another way is to turn parts of the logic into an input and plot the results, as sometimes it's a lot easier to see what is going on (or better not correctly working) when you have it plotted on a chart.

You mean like temporarily disabling (i.e. via curly brackets) conditional routines and setting a fixed condition instead? Certainly worth a try.


Quoting 
One thing to check is that AO[1] is actually 0 for some bars. Keep in mind that it might be unlikely that the two averages are exactly the same for one bar i.e. if they are different at the tenth decimal place only your condition would not be valid. If that is the problem, an alternative approach could be to check for AO crossing over and under 0 for example.

Thanks, I didn't think of that. One fix for that could be to multiply the individual Long and Short Averages by say 1'000'000 and then divide the difference by 1'000'000, i.e. instead

 
Code
// Calculate AO

	AOLong = Average((High + Low)/2,AOLongPeriod);
	AOShort = Average((High + Low)/2,AOShortPeriod);
	AO = AOShort - AOLong;
I use

 
Code
// Calculate AO

	AOLong = (Average((High + Low)/2,AOLongPeriod)) * 1000000);
	AOShort = (Average((High + Low)/2,AOShortPeriod)) * 1000000);
	AO = (AOShort - AOLong) / 1000000;
I assume this would then avoid the issue with deltas less than 1, at least up to the 6th decimal place.


Quoting 
Apart from that what chart and interval settings did you apply the strategy to, so one could reproduce what you are seeing?

Chart settings I tried were line chart, candlestick and candlestick with Momentum, with 15s a 1s intervals. The only study that was open was Awesome Oscillator. The other settings were left at standard for TS 10.

Thanks a lot for your help!

Reply With Quote
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,441 since Apr 2013
Thanks Given: 491
Thanks Received: 1,634

BTGUK,

I am afraid there is a typo in my reply, I meant to write "Another way is to turn parts of the logic into an indicator and plot the results [...]".

It depends on what you are actually trying to discover when you say Xing. You can also simply check for one indicator crossing over or under the other using the reserved words "crosses over" and "crosses under".
That should effectively eliminate any problems due to a variable not being 0 in the nth decimal place.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #6 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT Stellar & Tradestation
Broker: Primarily Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals, U308 and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,085 since Dec 2013
Thanks Given: 4,434
Thanks Received: 10,274


BTGUK View Post
 
Code
// Calculate AO

	AOLong = Average((High + Low)/2,AOLongPeriod);
	AOShort = Average((High + Low)/2,AOShortPeriod);
	AO = AOShort - AOLong;
I use

 
Code
// Calculate AO

	AOLong = (Average((High + Low)/2,AOLongPeriod)) * 1000000);
	AOShort = (Average((High + Low)/2,AOShortPeriod)) * 1000000);
	AO = (AOShort - AOLong) / 1000000;
I assume this would then avoid the issue with deltas less than 1, at least up to the 6th decimal place.

Not really. Try...
 
Code
        AOLong = Average((High + Low)/2,AOLongPeriod);
	AOShort = Average((High + Low)/2,AOShortPeriod);
	AO = Round(AOShort - AOLong, 3);
Or as @ABCTG suggested instead of
 
Code
// Detect Xing

	Xdwn = (AO < 0) and (AO[1] = 0);
	Xup = (AO > 0) and (AO[1] = 0);
you could just use
 
Code
// Detect Xing

	Xdwn = (AO crosses below 0);
	Xup = (AO crosses above 0);

Reply With Quote
Thanked by:
  #7 (permalink)
BTGUK
London, United Kingdom
 
Posts: 3 since Aug 2018
Thanks Given: 3
Thanks Received: 0

Thanks again for your help, ABCTG and SMCJB.


ABCTG View Post
BTGUK,

I am afraid there is a typo in my reply, I meant to write "Another way is to turn parts of the logic into an indicator and plot the results [...]".

I see. That's a good idea, however thanks to the help I got so far the basic strategy now seems to work and plots enntry and exit points on my charts.


Quoting 
It depends on what you are actually trying to discover when you say Xing. You can also simply check for one indicator crossing over or under the other using the reserved words "crosses over" and "crosses under".
That should effectively eliminate any problems due to a variable not being 0 in the nth decimal place.

I'm sure you're right. I'm still learning the basics and I now realized that for many things there are actually simple ways to do it.



SMCJB View Post
Not really. Try...
 
Code
        AOLong = Average((High + Low)/2,AOLongPeriod);
	AOShort = Average((High + Low)/2,AOShortPeriod);
	AO = Round(AOShort - AOLong, 3);
Or as @ABCTG suggested instead of
 
Code
// Detect Xing

	Xdwn = (AO < 0) and (AO[1] = 0);
	Xup = (AO > 0) and (AO[1] = 0);
you could just use
 
Code
// Detect Xing

	Xdwn = (AO crosses below 0);
	Xup = (AO crosses above 0);

Thank you very much! After I made all the changes you and ABCTG recommend the strategy seems to work now

Well, at least in general terms, but that's a start. Unfortunately it appears the 'detection' of twin peaks isn't very good, as it seems to often mis-interpret the peaks and settles for minimal changes, so something in my code isn't quite right:

 
Code
// Compute Entry	
	
	If (MarketPosition = 0) and (EntriesToday(Date) < MaxEntry) and Time > TimeBegin And Time < TimeEnd Then 
	Begin
		
		If (Gd = 1) then
		Begin
			
			if AO > AO[1] and AO[1] < AO[2] then
			Begin	
				if (LwMkr = 0) or ((LwMkr < 0) and (LwMkr < AO[1])) then LwMkr = AO[1];
				
				if (LwMkr < 0) and (LwMkr > AO[1]) then
				Begin
					Buy ("AOBuy") NumStocks shares next bar at market;
				LwMkr = 0;
				End;
			End;
		
			if AO > 0 then
			Begin
				Gd = 2;
				LwMkr = 0;
			End;
			
		End;

	End;
Does anyone have an idea how I could improve the 'twin peak' detection above?

Reply With Quote
  #8 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,441 since Apr 2013
Thanks Given: 491
Thanks Received: 1,634

BTGUK,

you are welcome. Can you verbalize and show a screenshot of what scenario you are looking to detect exactly when you say twin peak'? This might help others in pointing you in the right direction.

Regards,

ABCTG


BTGUK View Post
Thanks again for your help, ABCTG and SMCJB.



I see. That's a good idea, however thanks to the help I got so far the basic strategy now seems to work and plots enntry and exit points on my charts.



I'm sure you're right. I'm still learning the basics and I now realized that for many things there are actually simple ways to do it.




Thank you very much! After I made all the changes you and ABCTG recommend the strategy seems to work now

Well, at least in general terms, but that's a start. Unfortunately it appears the 'detection' of twin peaks isn't very good, as it seems to often mis-interpret the peaks and settles for minimal changes, so something in my code isn't quite right:

 
Code
// Compute Entry	
	
	If (MarketPosition = 0) and (EntriesToday(Date) < MaxEntry) and Time > TimeBegin And Time < TimeEnd Then 
	Begin
		
		If (Gd = 1) then
		Begin
			
			if AO > AO[1] and AO[1] < AO[2] then
			Begin	
				if (LwMkr = 0) or ((LwMkr < 0) and (LwMkr < AO[1])) then LwMkr = AO[1];
				
				if (LwMkr < 0) and (LwMkr > AO[1]) then
				Begin
					Buy ("AOBuy") NumStocks shares next bar at market;
				LwMkr = 0;
				End;
			End;
		
			if AO > 0 then
			Begin
				Gd = 2;
				LwMkr = 0;
			End;
			
		End;

	End;
Does anyone have an idea how I could improve the 'twin peak' detection above?


Follow me on Twitter Reply With Quote




Last Updated on November 12, 2018


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