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 RJay with 1 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 sra18376 with 1 posts (0 thanks)
    1. trending_up 1,215 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

Strategy is exiting my long at the wrong time

  #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?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Cheap historycal L1 data for stocks
Stocks and ETFs
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
What broker to use for trading palladium futures
Commodities
 
  #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: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


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 Twitter Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 
RJay's Avatar
 RJay 
Hartford, CT. USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: RTY
Posts: 683 since Jun 2009
Thanks Given: 758
Thanks Received: 787


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: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


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 Twitter Visit my NexusFi Trade Journal Reply With Quote




Last Updated on July 27, 2014


© 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