Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Total trades in a day

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

    Total trades in a day

    Hi there,

    I am developing a strategy that takes only certain number of trades in a day or quits trading when certain profit target or stop loss occurred in a day. I am using the following code.

    if (Bars.FirstBarOfSession)
    {
    priorTradesCount = Performance.AllTrades.Count;
    priorTradesCumProfit = Performance.AllTrades.TradesPerformance.Currency.C umProfit;


    }

    if (Performance.AllTrades.TradesPerformance.Currency. CumProfit >= 200
    || Performance.AllTrades.TradesPerformance.Currency.C umProfit <= -400
    || Performance.AllTrades.Count > 1)
    {
    return;
    }

    But when I try to compile this code, it says that "The name Prior trades count does not exist in the current context". What am I doing wrong?

    #2
    Hi pstechie,

    We are not able to see how you are declaring this variable.

    Can you include the full script? (comment out any lines that prevent compile)

    To export your script do the following:
    1. Click File -> Utilities -> Export NinjaScript
    2. Enter a unique name for the file in the value for 'File name:'
    3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
    4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


    Below is a link to the help guide on Exporting NinjaScripts.
    http://www.ninjatrader.com/support/h...nt7/export.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      File Attached

      Please find the export file attached.
      Attached Files

      Comment


        #4
        Hello pstechie,

        The issue is scope.

        You have declared the priorTradesCount and priorTradesCumProfit in Initialize(). This means those variables are only available in Initialize() and cannot be accessed anywhere else in the script.

        Declare variables in the #region Variables section.
        Declare variables that are properties in the #region Properties section.

        For more information, take a look at the EMA script. There is a period value that is declared in the #region Variables section.

        Below is a publicly available link to a 3rd party site on the basics of variable scope.
        http://www.blackwasp.co.uk/CSharpVariableScopes.aspx
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Christopher Leggit, 02-15-2024, 09:00 AM
        3 responses
        45 views
        0 likes
        Last Post rdtdale
        by rdtdale
         
        Started by DavidHP, Today, 07:56 AM
        0 responses
        2 views
        0 likes
        Last Post DavidHP
        by DavidHP
         
        Started by Aviram Y, 08-09-2023, 09:04 AM
        10 responses
        298 views
        0 likes
        Last Post MrHump
        by MrHump
         
        Started by jpapa, Today, 07:22 AM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by kevinenergy, 02-17-2023, 12:42 PM
        116 responses
        2,758 views
        1 like
        Last Post kevinenergy  
        Working...
        X