Trace Order Status during executing Code in different Methods

Created at 22 Feb 2016, 00:14
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
Mikro's avatar

Mikro

Joined 20.06.2015

Trace Order Status during executing Code in different Methods
22 Feb 2016, 00:14


Hi there,

I have an Issue tracking the Status of an Order while executing different Methods in my Code.

Basically I do not want my Code to stop if a Market Order is executed in Order to be able to continue with Calculations.

My Code looks like this

namespace cAlgo
{
   [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
   public class myBot: Robot
   {
      public TradeOperation OpenLong;

      Method1()
      {
         TradeOperation OpenLong = ExecuteMarketOrderAsync(TradeType.Buy,Symbol,10,"OpenLong",30,30);
      }

      onTick()
      {
         If(OpenLong.TradeResult.IsSuccessful == true) Print("Order filled")
      }
   }
}

If the Code Execution proceeds the the If() in onTick() I get an 'System.NullReferenceException'.

What am I missing, respectively how can I query the Order Status from another Method?

 

Thank you!


@Mikro
Replies

Mikro
23 Feb 2016, 22:18

Sorted that one out

The mistake ist to declare 'OpenLong' as a TradeOperation the second time inside Method1().

Only using

OpenLong = ExecuteMarketOrderAsync(...);

it works.
 


@Mikro