Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cannot convert lambda expression to type bool

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

    Cannot convert lambda expression to type bool

    Hi all,

    My code is refusing to compile. basically I want to do something every few seconds

    ess = Time[0].TimeOfDay.TotalSeconds; // Keep a track of time
    if (Ess => (Ess1 + 3)) // more than 2 seconds have elapsed
    {
    }

    The error i

    Cannot convert lambda expression to type 'bool' because it is not a delegate type

    #2
    Hello,

    Thank you for the question.

    Depending on where you place this code it will or will not happen every few seconds depending on market data.

    For example if you place a time check that is checking every 1 minute if something has happened but you are on at 10 minute chart with CalculateOnBarClose set to true, you will only have this check once ever 10 minutes.

    Please be mindful of the chart time or the CalculateOnBarClose setting, anything that receives ticks in greater than 2 second intervals will make this check null as it will only start once a tick is received.

    For time comparisons you can do something like the following as sort of a timer that gets reset when it is true.

    Code:
    private DateTime timer = DateTime.MinValue;
    protected override void OnBarUpdate()
    {
    	if(timer < DateTime.Now.AddSeconds(-2))
    	{
    		Print("It has been > 2 seconds");
    		timer = DateTime.Now;
    	}
    }
    Something like the above would work for fast data as you will most likely get events before 2 seconds, if you need something independent of the ticks and solely time based you could use a timer. I have attached a Timer example in strategy form. You can import this using the File -> Utilities -> Import NinjaScript.

    I look forward to being of further assistance.
    Attached Files

    Comment


      #3
      Very Helpful

      Hi Jesse,

      That was very helpful.

      With regards to a "tick paced" chart I believe I have overcome this difficulty my placing the code in the "Initialize" section.

      I thought it was clever....???

      Brian

      Comment


        #4
        Hello,

        You will really only want to use the Initialize for NinjaScript items that are specified that they need to go in this method, The reason:

        This method is only called 1 time at the start of the indicator
        The Initialize method is called every time you open the indicator list from a chart or when the indicators list needs initialized.
        Therefore this is not a valid placement for code that needs to be executed when the indicator starts or for anything else aside from the setup of the chart items.

        Instead use:
        protected override void OnStartUp() { }

        This is still called at the start of the indicator, but not when you do not have the indicator on a chart.

        This is also only called once but would be useful for the attached example. Anything that only needs to run once to start will be fine in the OnStartUp, anything that needs to run for each bar will need to go in OnBarUpdate to be in sync with the bar updates.

        Anything that needs to be per tick can go in OnBarUpdate with CalculateOnBarClose set to false or in the OnMarketData method as this is called for each tick.

        I look forward to being of further assistance.

        Comment


          #5
          Ten Points for you thus far....

          However...

          The code did compiled however upon calling the strategy nothing happened. I have pasted a bit of the code where a pending bracket trade should be created.

          For your information the text lines did appear in the Output File however no Pending orders are created.

          public class Samsum : Strategy
          {
          #region Variables
          // Wizard generated variables
          private int stopLoss = 1; // Default setting for StopLoss
          private int profitTarget = 1; // Default setting for ProfitTarget
          private int bracketLimit = 5; // Default setting for BracketLimit
          private int reverseTick = 8; // Default setting for ReverseTick
          private bool reverseAllow = false; // Default setting for ReverseAllow
          private int spare1 = 1; // Default setting for Spare2
          private int spare2 = 1; // Default setting for Spare2
          private int spare3 = 1; // Default setting for Spare2
          private int spare4 = 1; // Default setting for Spare2
          //private bool swit = true; // has initial position been taken?
          private double pTickPrice = 1; // Default setting for Spare3
          private double tickPrice = 1; // Default setting for Spare4
          // bh 10-11
          private IOrder entryOrder = null; // This variable holds an object representing our entry order
          private IOrder stopOrder = null; // This variable holds an object representing our stop loss order
          private IOrder targetOrder = null; // This variable holds an object representing our profit target order
          //bh

          // bh 11-11 can also have milliSeconds
          //private double ess = Time[0].TimeOfDay.TotalSeconds; //Holds current time
          //private double ess1 = Time[0].TimeOfDay.TotalSeconds; //Holds previous time
          private DateTime timer = DateTime.MinValue;
          //#region Variables
          //private int period = 100;
          //private ArrayList myArray = new ArrayList();

          // User defined variables (add any user defined variables below)
          #endregion

          /// <summary>
          /// This method is used to configure the strategy and is called once before any strategy method is called.
          /// </summary>
          protected override void Initialize()
          {
          CalculateOnBarClose = false;
          Unmanaged = true;
          }

          protected override void OnStartUp()
          {
          // Create the Bracket on Initialization
          Print("I was null at " + Time[0]);
          entryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Market, 1, Position.AvgPrice + 4 * TickSize, 0, "", "Enter Short");
          entryOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Market, 1, Position.AvgPrice - 4 * TickSize, 0, "", "Enter Short");
          Print("I was null at " + Time[0]);

          Comment


            #6
            Hello,

            For order methods you would not want to use the OnStartUp method but rather the OnBarUpdate or OnMarketData methods. The OnStartUp is used for exactly what it says, startup items.

            Anything to do with your logic in placing orders you would want to place where you will have bars on the chart and data coming in, this is most likely getting called before anything is loaded in the chart.

            Also I would like to ask, are you meaning to use the unmanaged approach? I would recommend looking at the differences between the managed and unmanaged approach in the help guide here if you have not yet: http://www.ninjatrader.com/support/h...er_methods.htm

            I look forward to being of further assistance.

            Comment


              #7
              The inescapable conclusion...

              Your system is obviously faulty.

              The code below simply opened a position... No bracket order was created.

              The Bracket order explains why I have to use the UnManaged approach.

              Please help...


              protected override void OnMarketData(MarketDataEventArgs e)
              {
              // Create the Bracket on Initialization
              Print("I was null at " + Time[0]);
              longOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Market, 1, Position.AvgPrice + 4 * TickSize, 0, "", "Enter Short");
              shortOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Market, 1, Position.AvgPrice - 4 * TickSize, 0, "", "Enter Short");
              Print("I was null at " + Time[0]);

              Comment


                #8
                Tried this...

                Put it all on a 1 second chart. Appeared to create 2 orders 1 tick apart

                longOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, 1, GetCurrentBid() + 12 * TickSize, 0, "", "Pending Long");
                shortOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, GetCurrentBid() - 12 * TickSize, 0, "", "Pending Short");

                Comment


                  #9
                  Hello,

                  This may be easier with an example. We have a strategy on the forum you can download that uses the unmanaged approach. Here is a link to it: http://www.ninjatrader.com/support/f...tid=-1&lpage=1

                  There are two version of the strategy in this file, one is managed, the other is unmanaged.

                  because we do not have a complete example listed in the help guide I believe this would probably be the next best thing because you can load and run it to see how the components of a unmanaged strategy work together to complete the order process.

                  Please let me know if I may be of additional assistance.

                  Comment


                    #10
                    Jesse...

                    Is there any readily apparent reason why the code last posted will simply create two orders 1 tick apart although I specifically asked for a pending bracket order 12 ticks either side of the CurrentBid?

                    Comment


                      #11
                      Hello,

                      Without seeing the whole script no there is no answer readily available. Using just the order method lines that you have provided I am able to place orders but that does not help in determining the reason why your specific script is having this occur.

                      If you would like to upload the script and also provide the settings for the chart/ script so that I can run it with the same settings/ instrument/ chart setup I can look into this unless the issue has already been resolved.

                      Please let me know if I may be of additional assistance.

                      Comment


                        #12
                        Originally posted by cocopod View Post
                        Hi all,

                        My code is refusing to compile. basically I want to do something every few seconds

                        ess = Time[0].TimeOfDay.TotalSeconds; // Keep a track of time
                        if (Ess => (Ess1 + 3)) // more than 2 seconds have elapsed
                        {
                        }

                        The error i

                        Cannot convert lambda expression to type 'bool' because it is not a delegate type
                        That IS a lambda expression. If you want to say "greater than or equal", it is written " >= " not " => "

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        558 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        324 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        101 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        545 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        547 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X