Anyone who needs a flat stop set after a certain amount of profit, I have an answer - futures io
futures io futures trading



Anyone who needs a flat stop set after a certain amount of profit, I have an answer


Discussion in NinjaTrader

Updated by sra18376
    1. trending_up 569 views
    2. thumb_up 2 thanks given
    3. group 1 followers
    1. forum 0 replies
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 100,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Thread Tools Search this Thread
 

Anyone who needs a flat stop set after a certain amount of profit, I have an answer

  #1 (permalink)
kansas city, ks
 
 
Posts: 17 since Jun 2014
Thanks: 0 given, 5 received

Anyone who needs a flat stop set after a certain amount of profit, I have an answer

I have gone from being completely new to ninjatrader, ninjascript and programming in general to finishing programming my own strategy in about a month and a half, and I have to give a lot of credit to this forum, because browsing through threads here taught me 80% of what I learned.

So to pay it forward here is a little code that I have seen a lot of people have questions about. Setting a flat stop once you are a few points in profit. The great thing about this code is that you can still use SetTrailStop() if you want because this code doesn't use SetStopLoss(). So here it is. Enjoy


This will set a flat stop once you are 2 points in profit.

Under the Variables region:

 
Code
private bool stopSet = false;

Under the OnBarUpdate() section:

 
Code
if (Position.MarketPosition == MarketPosition.Long)
{
				if (Close [0] >= Position.AvgPrice + 2)
				{
				stopSet = true;
				}

				if (stopSet && Close [0] <= Position.AvgPrice)
				{
				ExitLong();
				stopSet = false;
				}
}

Reply With Quote
The following 2 users say Thank You to sra18376 for this post:



futures io Trading Community Platforms and Indicators NinjaTrader > Anyone who needs a flat stop set after a certain amount of profit, I have an answer




Upcoming Webinars and Events
 

Free BloodHound Licenses to everyone!

June
 

Every journal equals ten meals for the hungry

June
     



Copyright © 2020 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts