NexusFi: Find Your Edge


Home Menu

 





Close position when EMA equals entry price


Discussion in NinjaTrader

Updated
    1. trending_up 2,258 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 4 posts
    2. attach_file 1 attachments




 
Search this Thread
  #1 (permalink)
AquaLife
Amsterdam
 
Posts: 3 since Oct 2014
Thanks Given: 1
Thanks Received: 0

Hi all,

I'm currently working on my first automated strategy and I'm having some problems with the following;

When the EMA is equal to the entry price --> Close position at market.
Im currently using the following coding, but I cant figure out why it doesn't work. Note that I don't get a coding error, but when I use the strategy analyser, the position is closed out on a different spot.

if (EMA(100)[0] == Position.AvgPrice);
{
ExitShort(0, 30000, "ExitEMAShort", "");
}

As you can see in the attached picture, the position is closed out only a few bars after the entry while the EMA is not near the entry price and I can't figure out why it closes the position at this specific price.
Could anyone help me out with this?

Thanks in advance!

Dennis


Attached Thumbnails
Click image for larger version

Name:	Clarification.png
Views:	259
Size:	63.6 KB
ID:	162324  
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Bookmap Global Plus Lifetime + Lifetime Addons For Sale
Platforms and Indicators
One Wallet Made $200K in Hours: AP Probes Polymarket Cea …
Prediction Markets & Event Contracts
Saylors 41-Month HODL Breaks: Strategy Sells 32 BTC as $ …
Prediction Markets & Event Contracts
CME Launches Bitcoin Volatility Futures June 1 -- First …
Cryptocurrency
Kharg Island at 6%, Regime Fall at 1.5% -- The Black Swa …
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
8 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #3 (permalink)
 NW27 
Newcastle, Australia
 
Experience: Intermediate
Platform: Multicharts 8 - Full Version
Broker: IB
Trading: SPI,FTSE100, 6E, 6A
Posts: 285 since Oct 2010
Thanks Given: 108
Thanks Received: 188


Try removing the semicolon on the end of the if statement line.
Also don't use == but use <= the price will never be exactly the same.


Reply With Quote
Thanked by:
  #4 (permalink)
AquaLife
Amsterdam
 
Posts: 3 since Oct 2014
Thanks Given: 1
Thanks Received: 0

Thanks, it works now! The sollution is so simple. Now you notice I'm a beginner in coding ninjatrader strategy's.

I'm sure I will be comming with more questions. Is it best to create 1 topic with different questions as they arrise, or should I make a topic for each subject?


Reply With Quote
  #5 (permalink)
 NW27 
Newcastle, Australia
 
Experience: Intermediate
Platform: Multicharts 8 - Full Version
Broker: IB
Trading: SPI,FTSE100, 6E, 6A
Posts: 285 since Oct 2010
Thanks Given: 108
Thanks Received: 188

Which ever. Just hope someone responds.


Reply With Quote




Last Updated on October 20, 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