NexusFi: Find Your Edge


Home Menu

 





Java Adj Trailing stop strategy help please :)


Discussion in NinjaTrader

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




 
Search this Thread
  #1 (permalink)
sickwake
Vancouver BC Canada
 
Posts: 1 since Feb 2014
Thanks Given: 0
Thanks Received: 0

Hey guys,

New at Programming. Using Java to code my strategy for automated day trading. My plan is simple. Just need some help with the code and where to go from here.

The plan is to have a trailing stop that adjusts as the market moves in favour of the trade. For Example (Going Long/buying): Enter the market at specified entry price and it moves up in favour of the trade. When the price reaches 50% of the way between entry price and target price the trailing stop is adjusted and is adjusted one last time when target price is reached.

What I have thus far... (A really rough first draft as you can see!)

public class StockExample {
public static void main(String[] args) {
}
double MarketPrice;
double EntryPrice; // EntryPrice == Stop Price
double TargetPrice;
double TrailStop;
double TrailStop2; //Initial Trail Adjusted 50%
double TrailStop3; //Trails .05 behind TargetPrice
{
TrailStop2 = TargetPrice - EntryPrice/2 +.02;
TrailStop3 = TargetPrice - .05;
{

if (TrailStop == 50% TargetPrice) {
System.out.println(TrailStop2);
if (TrailStop2 == .05 - TargetPrice );
System.out.println(TrailStop3);
}else{
System.out.println("Target Price not met.");



Also wanting to add this new rule and convert it to code...

If Market price exceeds Entry Price by .15 and is not triggered cancel trade ( like a gap were to occur or something)
Figure it would have to look something like this?

if (MarketPrice > EntryPrice + 0.15)
System.out.println("Cancel Trade");


Any help will be appreciated. Cheers


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NYSE Owner ICE Invests in Crypto Exchange OKX at $25 Bil …
Cryptocurrency
Orban at 29pct as Hungary Votes Tomorrow -- McIlroy Surg …
Prediction Markets & Event Contracts
April 2026 Jobs Report: +115k vs +65k Expected
Traders Hideout
Saylors 41-Month HODL Breaks: Strategy Sells 32 BTC as $ …
Prediction Markets & Event Contracts
Iran Peace Expired NO: Ceasefire on Life Support, OPEC a …
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




Last Updated on February 13, 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