Using negative numbers as private int - NinjaTrader Programming | futures io social day trading

 Notices

Using negative numbers as private int
 Updated: September 9th, 2009 (06:41 AM) Views / Replies: 1,955 / 2 Created: September 9th, 2009 (12:01 AM) by MXASJ Attachments: 0

 Welcome to futures io.

# Using negative numbers as private int

 September 9th, 2009, 12:01 AM #1 (permalink) Elite Member Asia   Futures Experience: Beginner Platform: NinjaTrader, TOS   Posts: 798 since Jun 2009 Thanks: 109 given, 790 received Using negative numbers as private int Hey All, Having some coding trouble and hoping the community can help before market open tommorow. In one of my strategies, I use Eco2New2 as a filter. The value of Main[0] must be above, say +5 or below -5 to allow a trade. It works long, it doesn't work short. In region Variables I have this: ... privateint eco2New2strength = 5; // Default setting for Eco2New2strength privateint eco2New2strengthneg = -5; // Default setting for Eco2New2strengthneg ... In my strat (OnBarUpdate) I have this: ... && ((ECO2New2(Eco2New2fast, Eco2New2signal, Eco2New2slow).Main[0]>= Eco2New2strength) || (ECO2New2(Eco2New2fast, Eco2New2signal, Eco2New2slow).Main[0] <= Eco2New2strengthneg)) && ((ECO2New2(Eco2New2fast, Eco2New2signal, Eco2New2slow).Main[1]>= Eco2New2strength) || (ECO2New2(Eco2New2fast, Eco2New2signal, Eco2New2slow).Main[1] <= Eco2New2strengthneg)) ... Where I am trying to look at Eco2New2.Main[0] and [1] can create a condition where those values need to be above 5 OR below -5. In the Properties region I have this: [Description("")] [Category("Parameters")] publicint Eco2New2strength { get { return eco2New2strength; } set { eco2New2strength = Math.Max(1, value); } } [Description("")] [Category("Parameters")] publicint Eco2New2strengthneg { get { return eco2New2strengthneg; } set { eco2New2strengthneg = value; } } Long... I'm good. Its not taking shorts, though, since I realized a coding error and introduced a negative for the variable eco2new2strengthneg. Any obvious error in my code? Thanks for your time...

Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500

Posts: 46,801 since Jun 2009

When posting code please wrap it in the [ code ] or [ php ] blocks so the spacing doesn't get messed up.

To make a variable a negative value of itself, do this:

Code
 ``` ``` int strength = 5;int negstrength = -strength;  ``` ```
In other words, if they will always be balanced (+5 and -5) then just put - in front, like -strength. You don't need the extra int even.

Also if you get into trouble the best thing to do is use Print statements. I suggest Printing the values so you can see where the problem lies.

Mike

Elite Member
Asia

Futures Experience: Beginner

Posts: 798 since Jun 2009

Thanks Mike. Let me try the PHP thing:

Code
 ``` ``` if (atmStrategyId.Length > 0){// You can change the stop price. Added // before the wto lines below to disable.//if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)// AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);// Print some information about the strategy to the output windowPrint(Time[0] + " The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId));Print(Time[0] + " The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId));Print(Time[0] + " The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId));Print(Time[0] + " The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyId));Print(Time[0] + " Eco Main [0] Value: " + ECO2New2(Eco2New2fast, Eco2New2signal, Eco2New2slow).Main[0]);Print(Time[0] + " Eco Main [1] Value: " + ECO2New2(Eco2New2fast, Eco2New2signal, Eco2New2slow).Main[1]);}  ``` ```
Learning a lot today... OK now back to Ninja Script

 futures io > Using negative numbers as private int

Upcoming Webinars and Events (4:30PM ET unless noted)

December

January

Elite only

Elite only

Elite only

## TBA w/Brett Steenbarger

Elite only

 Similar Threads Thread Thread Starter Forum Replies Last Post kbit News and Current Events 0 August 8th, 2011 07:35 PM Quick Summary News and Current Events 0 July 26th, 2011 10:50 PM RM99 News and Current Events 0 July 20th, 2011 07:47 PM zokirb NinjaTrader Programming 5 May 28th, 2011 12:47 AM

 Tags atm strategy, average, code, es, information, market position, ninjascript, ninjatrader, signal, strategies, values, variable