Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Integer dilemma

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Integer dilemma

    Have the following in a strategy:

    Code:
                int Lots    =    1;
                int LotMult =     1;
                int LotsUsed =     Lots    *    LotMult;
            
    if (SMA(10)[0] < Position.AvgPrice - 70 * TickSize)
                {
                    LotMult = LotsUsed * 2;                
                    ExitLong();
                }
                
                
                if (SMA(10)[0] > Position.AvgPrice + 70 * TickSize)
                {
                    LotMult = 1;                
                    ExitLong();
                }
    When the market moves down, the order should exit, and LotsUsed should double. When the market moves up and exits, LotsUsed should be set at 1.

    When I run the strategy, it always buys just one lot, no matter if the last position closed up or down.




    Question:

    How do I get LotMult to actually equal the proper value (LotsUsed * 2) when the trade went short ?

    #2
    Hello Faspomy,

    Thank you for your post.

    One thing to check is where you declare the initial values for your variables. If you have them within OnBarUpdate() then they will be reset either on a new tick or a new bar.

    If this is the case you should move your variable declaration to the Variables region.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thank you NT Ryan !
      Last edited by Faspomy; 03-17-2010, 03:00 PM.

      Comment


        #4
        Quick question:


        Code:
        #region Variables
                    private int lots    =    1;
                    private int lotMult =     1;
                    private int lotsUsed =     Lots    *    LotMult;


        I'm receiving an error CS0236 on the lotsUsed line:
        'a field initializer cannot reference the nonstatic field, method, or property'


        How do I create the variable lotUsed so that it functions ?

        Comment


          #5
          #region Variables
          private int lots = 1;
          private int lotMult = 1;
          private int lotsUsed;

          protected override void Initialize()
          {
          lotsUsed = Lots * LotMult;
          }

          Comment


            #6
            Thank you !

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            656 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            371 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            579 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X