Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Use of unassigned local varriable

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

    Use of unassigned local varriable

    Hi I have in my strategy a method. I declare an IOrder and then use it in the body of the method.
    Code:
    IOrder buyOrder;
    and then later:-

    Code:
    if( buyOrder != null)
         CancelOrder(buyOrder);
    But I am getting the error,

    Use of unassigned local variable 'buyOrder'

    #2
    GKonheiser, I would expect that, since the buyOrder would be local defined then only to the method. I would suggest making a class scope variable instead.

    Comment


      #3
      Hi Bertrand,

      But i am declare the iOrder at the top of the method so i dont understand why buyOrder woudnt have scope? here is the complete method,

      Code:
      private void iceBurger(int size, int maxClip, bool buy, double target, double stop)
      	{
      	// ** FOR THIS METHOD YOU NEED TO HAVE Unmanaged = true; IN Initialize; **
      	
      	int i,j;
      	int fill = 0;
      	int sizeLoop = size;
      	int clip = 0;
      	IOrder buyOrder, sellOrder, longStop, shortStop, longTarget, shortTarget;
      	
      	// generate random number object with stop as seed
      	Random randClipObject = new Random( Convert.ToInt32(stop));
      	
      	for( j=0; j <= size; j = j + fill)
      	{
      		for( i=0; i <= sizeLoop; i=i+clip)
      		{
      			// generates a random number 
      			clip = randClipObject.Next(Math.Min(maxClip+1, sizeLoop+1));
      			
      			
      			if(buy)
      			{
      				if(GetCurrentAskVolume() < clip)
      				{
      					buyOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, clip, GetCurrentAsk() + 1*TickSize, 0, "", "buyOrder" );
      				}
      				
      				else
      				{
      					buyOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, clip, GetCurrentAsk(), 0, "", "buyOrder" );
      				}
      			}
      			
      			else if(!buy)
      			{
      				if(GetCurrentBidVolume() < clip)
      				{
      					sellOrder = SubmitOrder(0, OrderAction.SellShort, OrderType.Limit, clip, GetCurrentBid() - 1*TickSize, 0, "", "sellOrder" );
      				}
      				
      				else
      				{
      					sellOrder = SubmitOrder(0, OrderAction.SellShort, OrderType.Limit, clip, GetCurrentBid(), 0, "", "sellOrder" );
      				}
      			}
      		}
      		
      //		if( buyOrder != null)
      //			CancelOrder(buyOrder);
      //		
      //		if( sellOrder != null)
      //			CancelOrder(sellOrder);
      		
      		fill = Position.Quantity;
      		sizeLoop = size - fill;
      	}
      	
      	if(buy)
      	{
      		longStop = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, Position.Quantity, 0, stop, "long", "Long Stop");
      		
      		longTarget = SubmitOrder(0, OrderAction.Sell, OrderType.Limit, Position.Quantity, target, 0, "long", "Long Target");
      	}
      		
      	else if(!buy)
      	{
      		shortStop = SubmitOrder(0, OrderAction.BuyToCover, OrderType.Stop, Position.Quantity, 0, stop, "short", "Short Stop");
      		
      		shortTarget = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, Position.Quantity, target, 0, "short", "Short Target");
      	}
      }

      Comment


        #4
        Please try initializing them then directly with a value, i.e.

        Code:
        IOrder buyOrder = null, sellOrder = null, longStop = null, shortStop = null, longTarget = null, shortTarget = null;

        Comment


          #5
          that worked

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          648 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          369 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          572 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          573 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X