Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Increment or Counter in the Strategy Builder?

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

    #16
    Originally posted by culpepper View Post
    Hello Forum,

    The posted EventCounterExample works great. I've created a specific counter for my needs however I need a way to limit the print statement to report only when the counter value updates instead of printing on every bar. Could someone please post the syntax. I can't find a reference to it anywhere. Tried creating a new Custom Series and recording the bar's Date/Time to it, however the data format does not allow it. Same result when trying to create a Date/Time Variable to record the bar date/time when the counter updates.

    The only issue is the massive Print Statement. Again, only the timestamp for the bar on which the counter increases by one (1) is required.

    For the example let's put "EventCounter" on a 15sec chart & start counting from 8:31:00 AM on Jan 3, 2023. You can see the counter increment increasing by one (1) when an event occurs. The counter remains static until the next event.
    1/3/2023 8:31:00 AM 0
    1/3/2023 8:31:15 AM 1
    1/3/2023 8:31:30 AM 2
    1/3/2023 8:31:45 AM 3
    1/3/2023 8:32:00 AM 3
    1/3/2023 8:32:15 AM 3
    1/3/2023 8:32:30 AM 3
    prints a line representing each 15 sec. bar
    ~~~
    ...and we're still at a count of "3" after 24 hours and ~21,600 output lines later.....
    1/4/2023 8:30:45 AM 3
    1/4/2023 8:31:00 AM 3
    1/4/2023 8:31:15 AM 4
    1/4/2023 8:31:30 AM 4
    1/4/2023 8:31:45 AM 5
    1/4/2023 8:32:00 AM 5
    1/4/2023 8:32:15 AM 5
    ~~~

    This is an example of the desired NinjaScript Output.
    Count increases by one and only prints the bar date/time where the conditions were true.
    1/3/2023 8:31:00 AM 0
    1/3/2023 8:31:15 AM 1
    1/3/2023 8:31:30 AM 2
    1/3/2023 8:31:45 AM 3
    1/4/2023 8:31:15 AM 4
    1/4/2023 8:31:45 AM 5


    There is a help guide Methods discussion which includes "Method With No Return Type" (pasted below) however this non-programmer can't get the strategy to compile after adding it to the NinjaScript.

    // This method prints out the data and time
    private void PrintDateTime()
    {
    Print(DateTime.Now.ToString());
    }


    Thanks in advance.​
    I think you need to check what set it is under in Strategy Builder.

    Comment


      #17
      Originally posted by mcosta72 View Post
      Hello WattMan, you can try this:
      protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition)
      {
      if (position.MarketPosition == MarketPosition.Flat)
      {
      if (SystemPerformance.AllTrades.Count >= 1)
      {
      Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1] ;
      double res = lastRTTrade.ProfitCurrency * lastRTTrade.Quantity;
      if(res < 0)
      stop += 1;
      if(res > 0)
      target += 1;
      }
      }
      }
      Can anyone tell me how I can do this in Strategy Builder?

      Comment


        #18
        Originally posted by lovelean View Post

        Can anyone tell me how I can do this in Strategy Builder?
        There is an example of a Counter by NinjaTrader_PaulH in the forums that counts crosses. Not sure if system performance objects can be counted using Builder.

        Comment


          #19
          Hello lovelean,

          That code uses OnPositionUpdate so it would need to be manually coded to be used. The file that NinjaTrader Paul posted shows how you can use a counter in the builder.
          JesseNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by ChartTourist, Today, 08:22 AM
          0 responses
          3 views
          0 likes
          Last Post ChartTourist  
          Started by LiamTwine, Today, 08:10 AM
          0 responses
          2 views
          0 likes
          Last Post LiamTwine  
          Started by Balage0922, Today, 07:38 AM
          0 responses
          5 views
          0 likes
          Last Post Balage0922  
          Started by JoMoon2024, Today, 06:56 AM
          0 responses
          6 views
          0 likes
          Last Post JoMoon2024  
          Started by Haiasi, 04-25-2024, 06:53 PM
          2 responses
          19 views
          0 likes
          Last Post Massinisa  
          Working...
          X