NexusFi: Find Your Edge


Home Menu

 





Using negative numbers as private int


Discussion in NinjaTrader

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




 
Search this Thread

Using negative numbers as private int

  #1 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

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...



Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
About a successful futures trader who didn´t know anyth …
Psychology and Money Management
Better Renko Gaps
The Elite Circle
Cheap historycal L1 data for stocks
Stocks and ETFs
Quant vue
Trading Reviews and Vendors
What broker to use for trading palladium futures
Commodities
 
  #2 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,463 since Jun 2009
Thanks Given: 33,239
Thanks Received: 101,662

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

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #3 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800


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 window
Print(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(Eco2New2fastEco2New2signalEco2New2slow).Main[0]);
Print(
Time[0] + " Eco Main [1] Value: " ECO2New2(Eco2New2fastEco2New2signalEco2New2slow).Main[1]);

Learning a lot today... OK now back to Ninja Script

Started this thread Reply With Quote




Last Updated on September 9, 2009


© 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