Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need to figure out how to create a switch that would be trigger if day Loss exceeds x

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

    Need to figure out how to create a switch that would be trigger if day Loss exceeds x

    Hello,
    I have a strategy that is fitted to trend trading.

    Problem is when a day is trading sideways, it realizes a substantial loss.

    That is why I want to add a switch that would turn off all trading for that day in the event that a certain amount of loss is reached.

    On the next day, that switch should be automatically lifted and trading should begin all over.

    Any ideas how I can configure this through the wizard? There are controllers for Realized PnL and Unrealized PnL, however they do not fit here, as I need the realized PnL for each separate day.

    Thanks,

    #2
    Hi nikolaalx,

    To find that value, you would need to be able to do math and accumulation which is a limitation of the Strategy Wizard. So something like this would need to be accomplished with custom code.

    I have a sample that does this if you would like to take a look.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I have managed to add the controller that checks if the current PnL is a certain value.

      However I think the calculation of the Current PnL is not working, as I see 100% of trading identical as when I did not have the controller (even if I try a $1 losslimit on the Current PnL)

      I have attached my strategy.

      Any input would be very much appreciated.

      Thanks.
      Attached Files

      Comment


        #4
        Hello nikolaalx,

        Please take a look at the example I have provided for you.

        The currentPnL is the variable that I am using to track the loss. This is reset on the first bar of a session.

        In the conditions of each trade you will find something like currentPnL > -LossLimit.

        This prevents orders from being made if the currentPnL is less than the loss limit.

        While there is code similar to this in the first two conditions sets, these are not in any of the remaining condition sets and those can still enter a trade even if the loss limit is too low.

        The second order exits the position if the realized plus unrealized hits the loss limit.

        Position.MarketPosition == MarketPosition.Long && (currentPnL+Position.GetProfitLoss(Close[0], PerformanceUnit.Currency)) <= -LossLimit

        Also, anytime you feel that a variable or method is not returning the right value, print the value to the Output window to see what the value is.

        For example:
        Print((currentPnL+Position.GetProfitLoss(Close[0], PerformanceUnit.Currency))+" <= "+(-LossLimit));
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          The currentPnL is the variable that I am using to track the loss. This is reset on the first bar of a session.

          - I added it to the Variables exactly as per the sample you gave to me.


          In the conditions of each trade you will find something like currentPnL > -LossLimit.

          This prevents orders from being made if the currentPnL is less than the loss limit.

          While there is code similar to this in the first two conditions sets, these are not in any of the remaining condition sets and those can still enter a trade even if the loss limit is too low.


          - Only the first two conditions execute an entry. I have added the code as per your sample.
          The latter ones depend on a setting which I intentionally keep at a level that basically disables both.
          For me, it matters only what the currentPnL is and not the current position.


          The second order exits the position if the realized plus unrealized hits the loss limit.

          Position.MarketPosition == MarketPosition.Long && (currentPnL+Position.GetProfitLoss(Close[0], PerformanceUnit.Currency)) <= -LossLimit


          Yes I figured that, but I don't need it for the time being. I only want to make the currentPnL work and use it as a standalone controller that would forbid/allow new entries to be made for the rest of the specific day.


          Also, anytime you feel that a variable or method is not returning the right value, print the value to the Output window to see what the value is.

          This is something I am not sure of. I your sample, this piece of code is commented out with //Print

          Here it is : "
          //Print((currentPnL+Position.GetProfitLoss(Close[0], PerformanceUnit.Currency)) + " - " + -LossLimit);
          // print to the output window if the daily limit is hit in the middle of a trade
          Print("daily limit hit, exiting order "+Time[0].ToString());
          ExitLong();

          "

          Shall I add it without the // in the protected override void OnBarUpdate() section?

          I also want to emphasize again that I don't get where in the code is the formula for the currentPnL calculation? I apologize if this is a stupid question, but I thought there had to be some form of an algo that would figure out how exactly the currentPnL is calculated.

          I reckon the restart on each first bar, but the adding/substracting is something I seem to miss.

          IS it the Print((currentPnL+Position.GetProfitLoss(Close[0], PerformanceUnit.Currency))+" <= "+(-LossLimit)); that you suggest?

          Where should I insert this?

          Thank you for the great help!
          Last edited by nikolaalx; 06-11-2014, 03:51 PM.

          Comment


            #6
            Hi nikolaalx,

            You are not seeing any difference when changing the LossLimit value?

            I am seeing a difference here.

            Attached is a screenshot of an optimize test I performed with the LossLimit the only changing parameter.

            With this instrument and settings do you get the same results?
            Attached Files
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Aviram Y, Today, 05:29 AM
            0 responses
            2 views
            0 likes
            Last Post Aviram Y  
            Started by quantismo, 04-17-2024, 05:13 PM
            3 responses
            25 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by ScottWalsh, 04-16-2024, 04:29 PM
            7 responses
            34 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by cls71, Today, 04:45 AM
            0 responses
            6 views
            0 likes
            Last Post cls71
            by cls71
             
            Started by mjairg, 07-20-2023, 11:57 PM
            3 responses
            217 views
            1 like
            Last Post PaulMohn  
            Working...
            X