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 charlesugo_1, 05-26-2026, 05:03 PM
            0 responses
            59 views
            0 likes
            Last Post charlesugo_1  
            Started by DannyP96, 05-18-2026, 02:38 PM
            1 response
            143 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            161 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 05-10-2026, 08:12 PM
            0 responses
            97 views
            0 likes
            Last Post CarlTrading  
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            283 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Working...
            X