NexusFi: Find Your Edge


Home Menu

 





Math.Abs() erratic outcome in strategy


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Trader.Jon with 3 posts (0 thanks)
    2. looks_two MXASJ with 1 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 cory with 1 posts (0 thanks)
    1. trending_up 2,809 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 1 attachments




 
Search this Thread
  #1 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184

Another week, another challenge,

I had a bunch of erratic outcomes in backtesting so I stripped down the code and ...

Using the PRC2 from the downloads area, and NOW the only condition in the strategy is the Math.Abs portion of the code

My pseudo code [idea to test]

IF the (Absolute Value of the ((PRC2.SqHI2 minus HIGH) is GREATER THAN
( the Absolute Value of the ((LOW minus PRC2.SqLOW2 ))
Then Go LONG ...

ie there is more potential to go up than there is to go down if that is true. The reason I am using Abs is to cover cases when the HI might already be greater than the Sqh2 .... reversing logic to go shorts ... on the screen shot you will see that the trigger bars are (in this example) in position to take SHORT, but 1 went LONG instead.. 33.3333% of trades going the wrong way do not a happy tester make!

Likely it is my mis use of the tool, but I dont know any better lol

Thanks especially for a fix ... been hitting on this all weekend trying to find the problem
Jon


 
Code
                            
 

if
(
Position.MarketPosition == MarketPosition.Flat 
&& (Math.Abs(PRC2(PRC2DegreePRC2Period1.622.00PRC2HATEMAPeriodPRC2TEMAPeriod).Sqh2[0] - Highs[0][0])) >
 (
Math.Abs(Lows[0][0] - PRC2(PRC2DegreePRC2Period1.622.00PRC2HATEMAPeriodPRC2TEMAPeriod).Sql2[0])) 
)
// go long 


Attached Thumbnails
Click image for larger version

Name:	Math.Abs().errors.jpg
Views:	273
Size:	947.1 KB
ID:	25994  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
The Week Ahead -- CPI Wednesday With Oil Past $90, PPI L …
Traders Hideout
$12M Ceasefire Contract Goes Disputed as Bandar Abbas St …
Prediction Markets & Event Contracts
After $87M Settles NO: Irans Nuclear Redline Sets Up the …
Prediction Markets & Event Contracts
NYSE Owner ICE Invests in Crypto Exchange OKX at $25 Bil …
Cryptocurrency
CFTC Approves First US Bitcoin Perpetual Futures -- Kals …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
21 thanks
2026 Jlab journal
10 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #3 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 801


I believe Math.Abs simply ensures the return is a positive number. Is that what you want?

For example Math.Abs(-24312) returns 24312, and Math.Abs(24312) returns 24312.


Reply With Quote
  #4 (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

prc is probl the most heavily repaint (recalculation) indicator.


Reply With Quote
  #5 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184


MXASJ View Post
I believe Math.Abs simply ensures the return is a positive number. Is that what you want?

For example Math.Abs(-24312) returns 24312, and Math.Abs(24312) returns 24312.

Cory,

Thats the plan ... it is ... just the way the results come out it has no pattern that I can determine what the error comes from. The screen shot shows two very similar, consecutive entries, but one is long and the other short.

Jon


Started this thread Reply With Quote
  #6 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184


cory View Post
prc is probl the most heavily repaint (recalculation) indicator.

Cory,

I appreciate the analysis.

I have looked at the code, I cant really see where it recalculates ... but it is definitely too complex for my wetware.

Any thoughts on a version that doesnt recalculate, or let it recalculate but only allow changes to the current bar? Something like a 'window' to stop changes to already plotted data?

Jon


Started this thread Reply With Quote




Last Updated on November 21, 2010


© 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