NexusFi: Find Your Edge


Home Menu

 





Simple HMA Strategy


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one honkin with 3 posts (1 thanks)
    2. looks_two Trader.Jon with 1 posts (0 thanks)
    3. looks_3 Big Mike with 1 posts (1 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 3,534 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

Simple HMA Strategy

  #1 (permalink)
honkin
Melbourne, Australia
 
Posts: 13 since Dec 2010
Thanks Given: 4
Thanks Received: 2

Hi

I am extremely new to Ninja Script, so please have a little patience with me. I want to attempt to do it without using the wizard. I based what I am doing on one of Mike's video tutorials.

Basically, I want a simple HMA strategy that enters long on rising HMA and enters short on falling HMA. Naturally, when entering long, any short position would need to be closed and vice versa. I believe that EnterLong() will do the reverse without having to first exit the short position.

I want to be able to run it through the optimiser, so want to be able to allow it to alter the HMA. My preference is to run it on a 1 day chart using HMA(40) but am happy to let the optimiser do its job.

I initially set my variable, which is the HMA:

private int hmalength = 40;

The next 2 sections look like this:

protected override void Initialize()
{
CalculateOnBarClose = true;
EntryHandling = EntryHandling.UniqueEntries;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>


protected override void OnBarUpdate()
{
EntryHandling = EntryHandling.UniqueEntries;

HMA hmav = HMA(HMAlength);

//ManageOrders();

if ((Position.MarketPosition == MarketPosition.Long) && Falling(hmav))
EnterShort();

else if ((Position.MarketPosition == MarketPosition.Short) && Rising(hmav))
EnterLong();

Lastly, under properties, I have:

[Description("")]
[GridCategory("Parameters")]
public int HMAlength
{
get { return hmalength; }
set { hmalength = Math.Max(1, value); }
}

When I compile this, I get no errors, which is always a good sign. When I open the Strategy Analyser and alter any variables, I get an error message when I select an optimisation method. The error window says:

"Unable to retrieve type intos from assembly '1f9fb650f5264307ae7d5ce95e24f7e5'
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.Module._GetTypesInternal(StackCrawlMarkstacMack)

If I run the optimisation using just the default optimization, I get no trades. In output window also shows no activity.

Can anyone say what I am doing wrong, or do I need to reinstall my NT7, as I get the same message running an optimisation on one of NTs preset strategies?

cheers

honkin

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Cheap historycal L1 data for stocks
Stocks and ETFs
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Quant vue
Trading Reviews and Vendors
How to apply profiles
Traders Hideout
 
  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,463 since Jun 2009
Thanks Given: 33,239
Thanks Received: 101,662



honkin View Post
Can anyone say what I am doing wrong, or do I need to reinstall my NT7, as I get the same message running an optimisation on one of NTs preset strategies?

Well the last line means it could be any strategy causing this problem. To know for sure if it is this strategy, what you need to do is go to your Documents\NinjaTrader\bin\custom\Strategy folder, locate the .cs file for this strategy, and temporarily move it out of that folder (like to your Desktop).

Then recompile something in Ninja, and see if you still get the error using a built-in strategy.

If so, you might also look at your trace log in the Documents\NinjaTrader folder, to see if it is helpful in telling you which strategy is the problem. Otherwise you might look to remove all the custom strategies (and possibly indicators) out of your installation using the method above until you can find the one causing the problem.

Have you asked NT support for help on this?

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184


honkin View Post
Hi

I am extremely new to Ninja Script, so please have a little patience with me. I want to attempt to do it without using the wizard. I based what I am doing on one of Mike's video tutorials.
//ManageOrders();

if ((Position.MarketPosition == MarketPosition.Long) && Falling(hmav))
EnterShort();

else if ((Position.MarketPosition == MarketPosition.Short) && Rising(hmav))
EnterLong();
If I run the optimisation using just the default optimization, I get no trades. In output window also shows no activity.

Can anyone say what I am doing wrong, or do I need to reinstall my NT7, as I get the same message running an optimisation on one of NTs preset strategies?

cheers

honkin

If you are short and do a enter long, I think you will only flatten ... try this ..

if ((Position.MarketPosition == MarketPosition.Short) && Rising(hmav))
ExitShort();
EnterLong();

or

if ((Position.MarketPosition == MarketPosition.Flat) && Rising(hmav))
EnterLong();

Hope it helps,
Jon

Reply With Quote
  #5 (permalink)
honkin
Melbourne, Australia
 
Posts: 13 since Dec 2010
Thanks Given: 4
Thanks Received: 2


Trader.Jon View Post
If you are short and do a enter long, I think you will only flatten ... try this ..

if ((Position.MarketPosition == MarketPosition.Short) && Rising(hmav))
ExitShort();
EnterLong();

or

if ((Position.MarketPosition == MarketPosition.Flat) && Rising(hmav))
EnterLong();

Hope it helps,
Jon

cheers Jon. Not saying this is incorrect, but conflicting advice from the NT forum indicated it would actually reverse the trades.

I initially had it as you have shown, but one of the mods at the forum showed me the code as you have seen it.

cheers

honkin

Reply With Quote
Thanked by:
  #6 (permalink)
honkin
Melbourne, Australia
 
Posts: 13 since Dec 2010
Thanks Given: 4
Thanks Received: 2


Trader.Jon View Post
If you are short and do a enter long, I think you will only flatten ... try this ..

if ((Position.MarketPosition == MarketPosition.Short) && Rising(hmav))
ExitShort();
EnterLong();

or

if ((Position.MarketPosition == MarketPosition.Flat) && Rising(hmav))
EnterLong();

Hope it helps,
Jon

Hi Jon

The same mod from NT just replied to me saying that he thinks the correct code to enable the trade to reverse is this:

"please remove your MarketPosition checks in the entry conditions then you should see it trigger trades -

if (Falling(hmav))
EnterShort();

if (Rising(hmav))
EnterLong();

"The Enter() method does reverse for you if needed"

Not really sure what he means by "The Enter () does reverse for you if needed". How does NT know what I need and why wouldn't it just flatten instead of reversing? Mmm!

Not sure, but guess I will just do some testing to see.

cheers Jon

Reply With Quote




Last Updated on January 4, 2011


© 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