Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ending Ninjascript strategy

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

    #31
    $GBPUSD
    Sell
    1
    2.1087
    ########
    c7209a0160674c04b07d0644603eb631
    Exit
    -
    aa201c62c41e436590e7813bc6f157f1
    Sell
    $GBPUSD
    Buy
    1
    2.1094
    ########
    bcfa91a0c2794828a16e06beed5d5574
    Entry
    1L
    5340d8adaf064e36a7112469ec24e4a3
    Buy
    $GBPUSD
    Sell
    1
    2.1088
    ########
    7ca85de54daf4c3d9963866d930d12f9
    Exit
    -
    1bca3245936144a5a0fd1c1cf2166e29
    Sell
    $GBPUSD
    Buy
    1
    2.1093
    ########
    cfb44e9c36c74371a294ef7e74e6bc83
    Entry
    1L
    e49a4b4ac47541a78cc6cd96cb9c3925
    Buy
    $GBPUSD
    Sell
    1
    2.1088
    ########
    739bb21aaa484bb39bf07fc5924ba06d
    Exit
    -
    ae795fc661644722bce641ad09cefe3d
    Sell
    $GBPUSD
    Buy
    1
    2.1094
    ########
    e7ee78df7a8c40368bacb0eac38a19dd
    Entry
    1L
    096eeb2c5a684e6da8540010eff83c7e
    Buy

    Strategy
    Instrument
    Data Series
    Parameters
    Position
    Avg Price
    Unrealized
    Realized
    Account
    Connection
    Start/Stop
    test
    $GBPUSD
    20 Seconds
    1 (MyInput0)
    -
    0
    $0.00
    $0.00
    Sim101
    Amp Forex
    Stop

    I ran the same 20 second test. 3 trades
    Realized should be $180.00 loss, shows zero.

    Comment


      #32
      Thanks, I can reproduce now. Issue with currencies. Thanks for your co-operation and reporting this.
      RayNinjaTrader Customer Service

      Comment


        #33
        ending ninjascript

        Add the CumProfit to the Position.GetProfitLoss().

        I need help with how to code this.
        Thanks,
        Jim

        Comment


          #34
          Would this be right?

          if (Position.MarketPosition == MarketPosition.Long && Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) + (Performance.RealtimeTrades.TradesPerformance.Curr ency.CumProfit) > 100)
          return;

          Comment


            #35
            ending ninjascript

            Sorry, I meant this--


            if
            (Position.MarketPosition == MarketPosition.Long && Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) + (Performance.RealtimeTrades.TradesPerformance.Curr ency.CumProfit) > 100)
            ExitLong(
            "lg");
            return;

            Comment


              #36
              Close...

              Code:
              [FONT=Courier New][COLOR=#0000ff]if[/COLOR][SIZE=2] (Position.MarketPosition == MarketPosition.Long && Position.GetProfitLoss(Close[[/SIZE][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][SIZE=2]], PerformanceUnit.Currency) + Performance.RealtimeTrades.TradesPerformance.Currency.CumProfit > [/SIZE][SIZE=2][COLOR=#800080]100[/COLOR][/SIZE][/FONT][SIZE=2][FONT=Courier New])
              [SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][SIZE=2];
              [/SIZE][/FONT][/SIZE]


              If you are trading FX, you may consider swapping in GetCurrentBid() or GetCurrentAsk() instead of Close[0]. This is since Close[0] in FX through GAIN or MBT is always the bid price since there is no true "last" price in FX.
              RayNinjaTrader Customer Service

              Comment


                #37
                ending ninjascript

                You don't show ExitLong()
                Will the return; cause the exit and then stop the strategy?

                Comment


                  #38
                  return will return from the method, if you want to do something else, then you will need to add some more lines of code after condition is true.

                  For example, this is pseudo code:

                  if (myCondition == true)
                  {
                  // Do some stuff here
                  }
                  RayNinjaTrader Customer Service

                  Comment


                    #39
                    ending ninjascript

                    The coding below gives the following result trading the $USDCAD in simulation:
                    After having a buy at .9399, there was a sell at .9409 for a $100.00 gain, which shows under the Executions Tab, but the strategy is still running, and there are no results showing under the Strategies Tab for Realized P&L, and nothing showing under the Account tab for Realized P&L.
                    Money is still accumulating in the Unreaqlized P&L column.
                    Also, the buy shows on the chart, but the sell exit does not.

                    if (Position.MarketPosition == MarketPosition.Long && Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) + Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit > 100)
                    ExitLong(
                    "lg");
                    return;

                    Comment


                      #40
                      ending ninjascript

                      Everything appears to be working fine, now, with Version 3.5.3 on stopping a strategy from running once a given amount of profit has been attained.
                      Thanks for solving this,
                      Jim

                      Comment


                        #41
                        Excellent thanks for reporting back.
                        RayNinjaTrader Customer Service

                        Comment


                          #42
                          Thanks

                          oh Add the CumProfit to the Position.GetProfitLoss().

                          I need help with how to code this.
                          Thanks,

                          Comment


                            #43
                            See post #36 for a sample.
                            RayNinjaTrader Customer Service

                            Comment


                              #44
                              ending ninjascript

                              I spoke too soon on this.
                              It is not ending the running of the strategy.
                              It is exiting, but not removing orders or ending the strategy.
                              here's the code:
                              // If the profit on real-time trades is > $100 stop trading

                              if (Position.MarketPosition == MarketPosition.Flat && Position.GetProfitLoss(GetCurrentBid(), PerformanceUnit.Currency) + Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit > 200)
                              return;

                              if (Position.MarketPosition == MarketPosition.Flat && Position.GetProfitLoss(GetCurrentAsk(), PerformanceUnit.Currency) + Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit > 200)
                              return;

                              Comment


                                #45
                                ending ninjascript

                                Should have said:
                                // If the profit on real-time trades is > $200 stop trading

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                649 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                370 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                109 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                574 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                576 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X