Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

INVERTED PROFIT & STOPLOSS VALUES

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

    INVERTED PROFIT & STOPLOSS VALUES

    Something funny had happened. When I placed LONG order with set values of profit and stop losses I got them displayed /entered incorrectly.
    Stop loss absolute value became Profit and Vice Versa. Could not wrap my head around it. Enclosing picture and snippet of code.
    Click image for larger version  Name:	TARGETS.PNG Views:	0 Size:	89.7 KB ID:	1196408
    Slight discrepancy between absolute values entered in the strategy and displayed on the chart is caused by imperfection in ruler measurement.
    Last edited by kazbek966; 04-04-2022, 05:35 AM.

    #2
    Hi kazbek966, thanks for writing in.

    Did you remove and re-add the strategy to the chart? Are you calling a Set method anywhere other than in OnStateChange? In my test script its working fine. I will need an example of your script if the first two questions do not resolve.

    Kind regards,
    -ChrisL

    Comment


      #3
      Hi Chris,
      Indeed I repeatedly entered and removed strategy and each time those limits were changing to the effect that they finally reversed
      at which point I decided to call cavalry.

      Enclosing is snippet before strategy logic.

      //This namespace holds Strategies in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Strategies
      {
      public class LONGed : Strategy
      {
      private AuLLMA AuLLMA1;


      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Strategy here.";
      Name = "LONGed";
      Calculate = Calculate.OnBarClose;
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.AllEntries;
      IsExitOnSessionCloseStrategy = true;
      ExitOnSessionCloseSeconds = 180;
      IsFillLimitOnTouch = false;
      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
      OrderFillResolution = OrderFillResolution.Standard;
      Slippage = 0;
      StartBehavior = StartBehavior.WaitUntilFlat;
      TimeInForce = TimeInForce.Gtc;
      TraceOrders = true;
      RealtimeErrorHandling = RealtimeErrorHandling.IgnoreAllErrors;
      StopTargetHandling = StopTargetHandling.PerEntryExecution;
      BarsRequiredToTrade = 1;
      // Disable this property for performance gains in Strategy Analyzer optimizations
      // See the Help Guide for additional information
      IsInstantiatedOnEachOptimizationIteration = true;
      }
      else if (State == State.Configure)
      {
      AddDataSeries("MNQ 06-22", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
      }
      else if (State == State.DataLoaded)
      {
      AuLLMA1 = AuLLMA(Close, 1, 1);
      }
      }

      protected override void OnBarUpdate()


      Cheers

      Comment


        #4
        Hi kazbek, I uploaded a very simple strategy that works. You can test this by adding the file to Documents\NinjaTrader 8\bin\Custom\Strategies and compiling. Run it on a 10 second chart and let one real time bar close. It will submit an entry order with the correct stop loss and profit target. Notice I am not using a signal name overload because my entry order does not have a signal name.

        Kind regards,
        -ChrisL
        Attached Files

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X