NexusFi: Find Your Edge


Home Menu

 





Exit Signal Help


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one MWinfrey with 1 posts (0 thanks)
    2. looks_two vvhg with 1 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 jordis with 1 posts (0 thanks)
    1. trending_up 3,148 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?
March Jobs Report Update: 178K Beat vs 59K Expected, Wag …
Traders Hideout
April Jobs Beat Flips Fed Hike Odds Past 52% for First T …
Traders Hideout
After $87M Settles NO: Irans Nuclear Redline Sets Up the …
Prediction Markets & Event Contracts
More Than Capable: Hegseths War Warning Validates $114M …
Prediction Markets & Event Contracts
Pakistan Mediator in Tehran as Hormuz Normalization Coll …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #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,824



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,336


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