NexusFi: Find Your Edge


Home Menu

 





Exit Signal Help


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Quick Summary with 1 posts (0 thanks)
    2. looks_two jordis with 1 posts (0 thanks)
    3. looks_3 MWinfrey with 1 posts (0 thanks)
    4. looks_4 vvhg with 1 posts (0 thanks)
    1. trending_up 3,373 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 jordis 
Mobile, Alabama
 
Experience: Beginner
Platform: NinjaTrader, TOS
Trading: Stocks
Posts: 29 since Sep 2011
Thanks Given: 6
Thanks Received: 3

Hopefully this is a simple task that I am just too stupid to grasp at the moment, but here goes:

If I want to trade based on an indicator (just say a moving average or something), and I want to buy at some point below the average. However, I want to wait until the price moves above the average, and at this time I would like to set this same average to be my exit condition to the downside.

So, train of thought would be:

1. Go long at Point A below moving average
2. Wait until Close[0] is above the moving average
3. Exit Long when Close[0] crosses back below the moving average



I tried coding it sort of like this, but it doesn't work at all.

 
Code
if (Positions[0].MarketPosition == MarketPosition.Long)
				{
					 if (Close[0] > MovingAverage)
						if(CrossBelow(EMA(1), MovingAverage), 1))
						{
							ExitLong("c"+Time[-1], "long");
						}
						
				}

Can anyone provide some help on this? I know it's convoluted, but I'd at least like to learn how to code this (for educational purposes if nothing else!)

Thanks,
Jordis


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
AI for Traders — Agents, Memory, Tools & Real-Worl …
Elite Quantitative GenAI/LLM
My Rant with AMP Futures
Trading Reviews and Vendors
No book, only a stair: journaling fills where price move …
Cryptocurrency
Building a free browser DOM/SMC simulator - need some ad …
Platforms and Indicators
Bitcoin’s 2022 low, 2025 high and 2026 low so far arou …
Cryptocurrency
 
  #3 (permalink)
 
vvhg's Avatar
 vvhg 
Northern Germany
 
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,580 since Mar 2011
Thanks Given: 1,016
Thanks Received: 2,826



jordis View Post
Hopefully this is a simple task that I am just too stupid to grasp at the moment, but here goes:

If I want to trade based on an indicator (just say a moving average or something), and I want to buy at some point below the average. However, I want to wait until the price moves above the average, and at this time I would like to set this same average to be my exit condition to the downside.

So, train of thought would be:

1. Go long at Point A below moving average
2. Wait until Close[0] is above the moving average
3. Exit Long when Close[0] crosses back below the moving average



I tried coding it sort of like this, but it doesn't work at all.

 
Code
if (Positions[0].MarketPosition == MarketPosition.Long)
				{
					 if (Close[0] > MovingAverage)
						if(CrossBelow(EMA(1), MovingAverage), 1))
						{
							ExitLong("c"+Time[-1], "long");
						}
						
				}

Can anyone provide some help on this? I know it's convoluted, but I'd at least like to learn how to code this (for educational purposes if nothing else!)

Thanks,
Jordis

I assume you have CalculateOnBarClose=true;

The easiest way would be to use a simple bool flag like
 
Code
if(crossedabove && CrossBelow(Close[0], MovingAverage) 
{
ExitLong();
crossedabove = false;
}
else if(Crossabove(Close[0], MovingAverage) && Positions[0].MarketPosition != MarketPosition.Flat) crossedabove = true;
Vvhg


Hic Rhodos, hic salta.
Reply With Quote
  #4 (permalink)
 
MWinfrey's Avatar
 MWinfrey 
Lubbock TX
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Stage 5 Trading
Trading: CL
Posts: 1,878 since Jul 2009
Thanks Given: 1,450
Thanks Received: 3,337


jordis View Post
Hopefully this is a simple task that I am just too stupid to grasp at the moment, but here goes:

If I want to trade based on an indicator (just say a moving average or something), and I want to buy at some point below the average. However, I want to wait until the price moves above the average, and at this time I would like to set this same average to be my exit condition to the downside.

So, train of thought would be:

1. Go long at Point A below moving average
2. Wait until Close[0] is above the moving average
3. Exit Long when Close[0] crosses back below the moving average



I tried coding it sort of like this, but it doesn't work at all.

 
Code
if (Positions[0].MarketPosition == MarketPosition.Long)
				{
					 if (Close[0] > MovingAverage)
						if(CrossBelow(EMA(1), MovingAverage), 1))
						{
							ExitLong("c"+Time[-1], "long");
						}
						
				}

Can anyone provide some help on this? I know it's convoluted, but I'd at least like to learn how to code this (for educational purposes if nothing else!)

Thanks,
Jordis

How about something like this...I hope I interpreted your rule correctly.


if (Close[0] < MovingAverage[0]) EnterLong();


if (Close[0] < MovingAverage[0] && High[0] >= MovingAverage[0]) ExitLong();


Reply With Quote




Last Updated on December 20, 2012


© 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