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 2,789 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?
Trade idea based off three indicators.
Traders Hideout
MC PL editor upgrade
MultiCharts
Better Renko Gaps
The Elite Circle
About a successful futures trader who didnt know anythin …
Psychology and Money Management
REcommedations for programming help
Sierra Chart
 
  #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