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 cory with 1 posts (1 thanks)
    4. looks_4 Cloudy with 1 posts (0 thanks)
    1. trending_up 1,911 views
    2. thumb_up 3 thanks given
    3. group 4 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread

solving system of inequalities (C# / NinjaScript)

  #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?
Exit Strategy
NinjaTrader
MC PL editor upgrade
MultiCharts
REcommedations for programming help
Sierra Chart
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #3 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090


you can check out his code,

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,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709

Have you tried rounding ProfitDistance to the nearest tick size?

 
Code
this.Instrument.MasterInstrument.Round2TickSize(ProfitDistance)

Follow me on Twitter 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,124 since Jul 2011
Thanks Given: 2,396
Thanks Received: 1,748

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


© 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