NexusFi: Find Your Edge


Home Menu

 





solving system of inequalities (C# / NinjaScript)


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one SARdynamite with 3 posts (0 thanks)
    2. looks_two artemiso with 2 posts (0 thanks)
    3. looks_3 shodson with 1 posts (2 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 2,501 views
    2. thumb_up 3 thanks given
    3. group 4 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 SARdynamite 
Belgium
 
Experience: Advanced
Platform: SaxoTrader
Broker: SaxoBank
Trading: ESTX
Posts: 289 since Dec 2009
Thanks Given: 243
Thanks Received: 110

As a basic explanation, I'm trying to estimate in ticks where to place a stoploss to restrict my strategy without a max daily loss limit, considering my real P&L (which is not a round multiple of TickSize since including past commissions and slippage as well as anticipated commission+slippage for the stopout)

Please note I'm coding this from a NT indicator, not a strategy, hence I work from a simulated running EC.

ANYWAY, I will simplify the matter here to something along those lines :

 
Code
(ProfitDistance is a double)

X >= (ProfitDistance - Close[0]) / TickSize
X < (ProfitDistance + 1 - Close[0]) / TickSize

X must be an integer

Can it be solved efficiently in C# ? If so what needs to be written ? Never came accross such a need before. Thanks for your help (example scripts of equations solving welcomed)


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
I Have a Thing Called Iran -- Trump Stays in DC as Airsp …
Prediction Markets & Event Contracts
The Confluence Meter: A Multi-Layered Signal Framework B …
The Elite Circle
One Wallet Made $200K in Hours: AP Probes Polymarket Cea …
Prediction Markets & Event Contracts
NinjaTrader Parent Payward Acquires Bitnomial for $550M …
Platforms and Indicators
Post-Summit Scorecard: $36M in May 15 Bets Settle Near-Z …
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
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #3 (permalink)
 
cory's Avatar
 cory 
virginia
the coin hunter
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,093


you can check out his code, https://nexusfi.com/download/ninjatrader-7/indicators/1248-download.html?view


Reply With Quote
Thanked by:
  #4 (permalink)
 SARdynamite 
Belgium
 
Experience: Advanced
Platform: SaxoTrader
Broker: SaxoBank
Trading: ESTX
Posts: 289 since Dec 2009
Thanks Given: 243
Thanks Received: 110

Will give it a look. Thanks


Started this thread Reply With Quote
  #5 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,971 since Jun 2009
Thanks Given: 534
Thanks Received: 3,711

Have you tried rounding ProfitDistance to the nearest tick size?

 
Code
this.Instrument.MasterInstrument.Round2TickSize(ProfitDistance)


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #6 (permalink)
 SARdynamite 
Belgium
 
Experience: Advanced
Platform: SaxoTrader
Broker: SaxoBank
Trading: ESTX
Posts: 289 since Dec 2009
Thanks Given: 243
Thanks Received: 110

Yes, I thought about using the Round method to solve it as a first intention but actually my equation terms are more complex than the ones written and I would have gotten several terms inside the same Round function which then I cannot split to solve the one liner equation... too bad.

(not sure if my explanation is clear but end of the story is that it was not possible in that case to achieve perfect precision )


Started this thread Reply With Quote
  #7 (permalink)
 Cloudy 
desert CA
 
Experience: Intermediate
Platform: NT7, various
Broker: various, TDA
Trading: NQ,ES
Posts: 2,126 since Jul 2011
Thanks Given: 2,398
Thanks Received: 1,751

Just vaguely recalling from school. Linear algebra can be used to solve systems of linear equations. And there's probably code out there in C that does it.

(code on this page)
Gauss's method to solve system of linear equation.

Cramer's Rule to Solve Systems of Equations


Visit my NexusFi Trade Journal Reply With Quote




Last Updated on July 5, 2013


© 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