NexusFi: Find Your Edge


Home Menu

 





Strategy is exiting my long at the wrong time


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one rleplae with 2 posts (0 thanks)
    2. looks_two kandlekid with 1 posts (0 thanks)
    3. looks_3 RJay with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 1,986 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
sra18376
kansas city, ks
 
Posts: 17 since Jun 2014
Thanks Given: 0
Thanks Received: 5

I am having some very frustrating trouble with a strategy that I am programming right now. Basically, I want to exit my long position when the price crosses below a certain point (cutLevel). Instead what is happening is that my position is exiting when it crosses above it. I have absolutely no idea why its doing this and I have been staring at the code for hours. Can anyone help? Here is the code:

 
Code
if (Position.MarketPosition == MarketPosition.Long)
			{
				
				if (Close [0] < MyIndicator.cutLevelLong && Close [1] > MyIndicator.cutLevelLong)
				{
				ExitLong(1); 
				}

                        }
instead of Close [0] and Close [1] I have also tried Close [0] and Open [0] as well as GetCurrentAsk() and Open [0]. None of these have worked either...


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Fabrication or Framework? Irans Denied MOU Explains the …
Prediction Markets & Event Contracts
Ninjatrader users - good CONNECTIONs post and article fr …
NinjaTrader
CPI Eve: Fed Hike Odds Hold at 52% for the First Time, I …
Prediction Markets & Event Contracts
Ceasefire Collapse: Iran Fires 24 Missiles, Israel Hits …
Traders Hideout
Six Days to Kickoff: World Cup Prediction Markets Hit $1 …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
15 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks
  #3 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,855


Are you sure this is the piece of code that is triggering the exit?

The code seems all right.
< has priority over &&, so no () needed

and Close [0] is the last bar


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 
RJay's Avatar
 RJay 
Hartford, CT. USA
 Vendor: www.innovative-trading-solutions-online.com 
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: ES
Posts: 687 since Jun 2009
Thanks Given: 765
Thanks Received: 789


rleplae View Post
Are you sure this is the piece of code that is triggering the exit?

The code seems all right.
< has priority over &&, so no () needed

and Close [0] is the last bar


You are probably right but it should be tested with the additional brackets to be sure that's not the issue.

Strategies can be finicky some times.


if ((Close [0] < MyIndicator.cutLevelLong) && (Close [1] > MyIndicator.cutLevelLong))
{
ExitLong(1);
}


Reply With Quote
  #5 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,855


RJay View Post
You are probably right but it should be tested with the additional brackets to be sure that's not the issue.

Strategies can be finicky some times.


if ((Close [0] < MyIndicator.cutLevelLong) && (Close [1] > MyIndicator.cutLevelLong))
{
ExitLong(1);
}

to be sure you can write to the log:

if ((Close [0] < MyIndicator.cutLevelLong) && (Close [1] > MyIndicator.cutLevelLong))
{
Log("Triggered my ExitLong ", NinjaTrader.Cbi.LogLevel.Information);
ExitLong(1);
}


Follow me on X Visit my NexusFi Trade Journal Reply With Quote




Last Updated on July 27, 2014


© 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