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 2,779 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

Exit Signal Help

  #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?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
Better Renko Gaps
The Elite Circle
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Are there any eval firms that allow you to sink to your …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
37 thanks
NexusFi site changelog and issues/problem reporting
23 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #3 (permalink)
 
vvhg's Avatar
 vvhg 
Northern Germany
 
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,583 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,335


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


© 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