NexusFi: Find Your Edge


Home Menu

 





Stop using the value of an indicator on previous bar


Discussion in NinjaTrader

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




 
Search this Thread
  #1 (permalink)
 
nanobiotech's Avatar
 nanobiotech 
Brisbane, Australia
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus/Zen-Fire
Trading: CL
Posts: 670 since Jun 2009
Thanks Given: 134
Thanks Received: 430

Hi everyone

I'm trying to find a suitable way of coding a stoploss or trailstop that follows price, using an indicator in an auto strategy.

The indicator I favour is the ZerolagHATEMA.

For example, I've tried:
SetTrailStop(CalculationMode.Ticks, ZeroLagHATEMA(Period).ZeroHATEMA[1]);

I use the Period variable set to 5 so it closely follows price, but it doesn't seem to work when I place it before or after CalculateOnBarClose = true; and protected override void OnBarUpdate() - the latter after the buy/sell signals

I prefer to use the MedianRenko4 bar chart.

My coding skills are not too flash therefore if anyone has any ideas I'd love to hear them.

I have to jump on a plane to New Zealand for a family wedding in a few hours so now off to bed (Brisbane time is +15hrs US EST) - so apologies in advance for not responding for a few days until I return early next week

Cheers,
Nano


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trump Media to sell instant access to market-moving soci …
Traders Hideout
Thanks Mike. Godspeed.
The Elite Circle
Iran Lebanon Problem Kills Switzerland Talks, Brent at $ …
Prediction Markets & Event Contracts
Datafeed for Atas
Platforms and Indicators
Daytrading to swingtrading
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Want your NinjaTrader indicator created, free?
5 thanks
Afternoon-close session
1 thanks
Franks Trading Journey
1 thanks
Denied 20K payouts: Alpha Futures
1 thanks
FootPrintV2 Chart for NT8
1 thanks
  #2 (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

I was thinking on something similar, but with the use of previous swing values:
have you been able to code an effective solution?

TIA,
Jon


Reply With Quote
  #3 (permalink)
 
nanobiotech's Avatar
 nanobiotech 
Brisbane, Australia
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus/Zen-Fire
Trading: CL
Posts: 670 since Jun 2009
Thanks Given: 134
Thanks Received: 430



Trader.Jon View Post
I was thinking on something similar, but with the use of previous swing values:
have you been able to code an effective solution?

TIA,
Jon

Sorry mate, I have moved on after discovering Hurley auto strategy trading. Check out the coding in The Elite Circle/Elite Group Trading Methods/The Hurley Method (automated) - some of Big Mikes and my trailing stoploss methods may be useful.

Cheers,
Nano


Started this thread Reply With Quote
  #4 (permalink)
 zeller4 
Orlando Florida
 
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 478 since Jun 2009
Thanks Given: 1,419
Thanks Received: 404


nanobiotech View Post
For example, I've tried:
SetTrailStop(CalculationMode.Ticks, ZeroLagHATEMA(Period).ZeroHATEMA[1]);

Try using CalculationMode.Price

I don't use SetTrailStop so this is only a guess.

hth,
kz


Reply With Quote
  #5 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 R.I.P. 1977-2026 
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,669 since Jun 2009
Thanks Given: 33,669
Thanks Received: 102,586


nanobiotech View Post
For example, I've tried:
SetTrailStop(CalculationMode.Ticks, ZeroLagHATEMA(Period).ZeroHATEMA[1]);


zeller4 View Post
Try using CalculationMode.Price

Trail Stop should be in ticks, as in ticks away from current price. In the first example from nano, you are trailing the entire value of that indicator. For CL example, if price is 85.00 and the indicator value is 84.20, you are trailing not 80 ticks but 8420 ticks.

Try this (untested):
 
Code
                            
double _stopdiff Math.Abs(Close[0] - ZeroLagHATEMA(Period).ZeroLagHATEMA[1]);
SetTrailStop(CalculationMode.Ticks_stopdiff); 
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 X Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
 
nanobiotech's Avatar
 nanobiotech 
Brisbane, Australia
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus/Zen-Fire
Trading: CL
Posts: 670 since Jun 2009
Thanks Given: 134
Thanks Received: 430


Big Mike View Post
Trail Stop should be in ticks, as in ticks away from current price. In the first example from nano, you are trailing the entire value of that indicator. For CL example, if price is 85.00 and the indicator value is 84.20, you are trailing not 80 ticks but 8420 ticks.

Try this (untested):
 
Code
                            
double _stopdiff Math.Abs(Close[0] - ZeroLagHATEMA(Period).ZeroLagHATEMA[1]);
SetTrailStop(CalculationMode.Ticks_stopdiff); 
Mike

Yes, I now use CalculationMode.Price and not Ticks. Below is a snippet from a recent Hurley strategy:

if (Position.MarketPosition == MarketPosition.Long)
{
if (High[0] >= Position.AvgPrice + (Target1 * TickSize))
{
SetStopLoss("target1", CalculationMode.Price, Math.Min(GetCurrentBid(), Position.AvgPrice + 2 * TickSize), false);
SetStopLoss("target2", CalculationMode.Price, Math.Min(GetCurrentBid(), Position.AvgPrice + 2 * TickSize), false);
SetStopLoss("target3", CalculationMode.Price, Math.Min(GetCurrentBid(), Position.AvgPrice + 2 * TickSize), false);
SetStopLoss("target4", CalculationMode.Price, Math.Min(GetCurrentBid(), Position.AvgPrice + 2 * TickSize), false);
SetStopLoss("target5", CalculationMode.Price, Math.Min(GetCurrentBid(), Position.AvgPrice + 2 * TickSize), false);
}
}

Nano


Started this thread Reply With Quote
  #7 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 R.I.P. 1977-2026 
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,669 since Jun 2009
Thanks Given: 33,669
Thanks Received: 102,586

Yup, always smart to use Price with StopLoss, but use Ticks with TrailStop.

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 X Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on March 29, 2010


© 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