Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I would like to open orders called DELTA LONG and DELTA SHO

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

    I would like to open orders called DELTA LONG and DELTA SHO

    CAN SOMEONE PLEASE HELP ME? I have a script for an automated strategy (ES 1 minute timeframe) with which I would like to open orders called DELTA LONG and DELTA SHORT with these conditions: DELTA LONG with a green candle on the chart of at least 4 ticks and a red candle of the Cumulative Delta (or I try to put the condition that the sellers are greater than the buyers); DELTA SHORT the opposite of DELTA LONG. I activate the playback and the script opens orders, but not with the conditions I would like, I certainly cannot give the right commands in the script, but I cannot understand how to do it, for example it opens DELTA LONG with a green candle both on the chart and on the Cumulative Delta Order Flow. THANK YOU. KINDLY. region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class MyCustomStrategy : Strategy
    {
    private OrderFlowCumulativeDelta cumulativeDelta;

    [NinjaScriptProperty]
    public int MinTickMove { get; set; } = 4;

    [NinjaScriptProperty]
    public int MinIcebergVolume { get; set; } = 1000;

    // Dizionario per tenere traccia degli ordini aperti
    private Dictionary<string, Order> activeOrders = new Dictionary<string, Order>();

    // Variabile per tenere traccia dell'indice della barra corrente
    private int currentBarIndex = -1;

    // Variabili di stato per evitare aperture multiple sulla stessa candela
    private bool deltaLongOpenedThisBar = false;
    private bool deltaShortOpenedThisBar = false;
    private bool icebergLongOpenedThisBar = false;
    private bool icebergShortOpenedThisBar = false;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Strategia Delta/Iceberg con gestione diretta degli ordini";
    Name = "MyCustomStrategy";
    EntriesPerDirection = 100; // Aumenta il numero massimo di posizioni
    EntryHandling = EntryHandling.AllEntries; // Accetta tutti gli ordini
    ExitOnSessionCloseSeconds = 30;
    IsExitOnSessionCloseStrategy = true;
    IsUnmanaged = true; // Modalità Unmanaged per gestione manuale
    TraceOrders = true; // Abilita TraceOrders
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Tick, 1);
    }
    else if (State == State.DataLoaded)
    {
    cumulativeDelta = OrderFlowCumulativeDelta(CumulativeDeltaType.BidAs k, CumulativeDeltaPeriod.Bar, 0);
    }
    }

    protected override void OnBarUpdate()
    {
    // Controlla se è una nuova barra
    if (currentBarIndex != CurrentBar)
    {
    // Resetta le variabili di stato all'inizio di ogni nuova candela
    deltaLongOpenedThisBar = false;
    deltaShortOpenedThisBar = false;
    icebergLongOpenedThisBar = false;
    icebergShortOpenedThisBar = false;

    // Aggiorna l'indice della barra corrente
    currentBarIndex = CurrentBar;

    // Stampa informazioni sulla nuova barra
    Print($"Nuova barra: {Time[0]}");
    }

    if (State != State.Realtime || CurrentBar < BarsRequiredToTrade || cumulativeDelta?.DeltaClose == null)
    return;

    try
    {
    // --- Condizioni Delta ---
    if (activeOrders.Count < EntriesPerDirection)
    {
    // Delta Long: Candela del prezzo verde e venditori maggiori dei compratori
    Print(Time[0] + " | DELTA LONG: " +
    "deltaLongOpenedThisBar: " + deltaLongOpenedThisBar + " = false & " +
    "Close[0]: " + Close[0] + " > Open[0]: " + Open[0] + " & " +
    "cumulativeDelta.DeltaClose[0]: " + cumulativeDelta.DeltaClose[0] + " < 0 & " +
    "Close[0] - Open[0]: " + (Close[0] - Open[0]) + " >= MinTickMove * TickSize: " + (MinTickMove * TickSize));

    if (!deltaLongOpenedThisBar && Close[0] > Open[0] && cumulativeDelta.DeltaClose[0] < 0 && (Close[0] - Open[0]) >= MinTickMove * TickSize)
    {
    ExecuteTrade("DELTA_LONG", OrderAction.Buy);
    deltaLongOpenedThisBar = true;
    }

    // Delta Short: Candela del prezzo rossa e venditori minori dei compratori
    Print(Time[0] + " | DELTA SHORT: " +
    "deltaShortOpenedThisBar: " + deltaShortOpenedThisBar + " = false & " +
    "Close[0]: " + Close[0] + " < Open[0]: " + Open[0] + " & " +
    "cumulativeDelta.DeltaClose[0]: " + cumulativeDelta.DeltaClose[0] + " > 0 & " +
    "Open[0] - Close[0]: " + (Open[0] - Close[0]) + " >= MinTickMove * TickSize: " + (MinTickMove * TickSize));

    if (!deltaShortOpenedThisBar && Close[0] < Open[0] && cumulativeDelta.DeltaClose[0] > 0 && (Open[0] - Close[0]) >= MinTickMove * TickSize)
    {
    ExecuteTrade("DELTA_SHORT", OrderAction.SellShort);
    deltaShortOpenedThisBar = true;
    }
    }

    // --- Condizioni Iceberg ---
    CheckIcebergConditions();
    }
    catch (Exception ex)
    {
    Print("Errore: " + ex.Message);
    }
    }

    private void CheckIcebergConditions()
    {
    if (Position.MarketPosition == MarketPosition.Flat || activeOrders.Count < EntriesPerDirection)
    {
    // Iceberg Short: Delta positivo consecutivo
    Print(Time[0] + " | ICEBERG SHORT: " +
    "icebergShortOpenedThisBar: " + icebergShortOpenedThisBar + " = false & " +
    "cumulativeDelta.DeltaClose[0]: " + cumulativeDelta.DeltaClose[0] + " > 0 & " +
    "IsConsecutiveConditionMet(10, true): " + IsConsecutiveConditionMet(10, true));

    if (!icebergShortOpenedThisBar && cumulativeDelta.DeltaClose[0] > 0 && IsConsecutiveConditionMet(10, true))
    {
    ExecuteTrade("ICEBERG_SHORT", OrderAction.SellShort);
    icebergShortOpenedThisBar = true;
    }

    // Iceberg Long: Delta negativo consecutivo
    Print(Time[0] + " | ICEBERG LONG: " +
    "icebergLongOpenedThisBar: " + icebergLongOpenedThisBar + " = false & " +
    "cumulativeDelta.DeltaClose[0]: " + cumulativeDelta.DeltaClose[0] + " < 0 & " +
    "IsConsecutiveConditionMet(10, false): " + IsConsecutiveConditionMet(10, false));

    if (!icebergLongOpenedThisBar && cumulativeDelta.DeltaClose[0] < 0 && IsConsecutiveConditionMet(10, false))
    {
    ExecuteTrade("ICEBERG_LONG", OrderAction.Buy);
    icebergLongOpenedThisBar = true;
    }
    }
    }

    private void ExecuteTrade(string signalName, OrderAction action)
    {
    // Crea un nome univoco per l'ordine
    string uniqueSignalName = $"{signalName}_{DateTime.Now:yyyyMMddHHmmssfff} ";

    // Invia ordine di apertura
    Order entryOrder = SubmitOrderUnmanaged(0, action, OrderType.Market, 1, 0, 0, "", uniqueSignalName);

    // Imposta stop loss e take profit
    if (entryOrder != null)
    {
    // Stop Loss: 40 tick
    double stopLossPrice = action == OrderAction.Buy ?
    entryOrder.AverageFillPrice - 40 * TickSize :
    entryOrder.AverageFillPrice + 40 * TickSize;

    SubmitOrderUnmanaged(0, action == OrderAction.Buy ? OrderAction.Sell : OrderAction.BuyToCover, OrderType.StopMarket, 1, 0, stopLossPrice, uniqueSignalName, $"{uniqueSignalName}_STOP");

    // Take Profit: 40 tick
    double takeProfitPrice = action == OrderAction.Buy ?
    entryOrder.AverageFillPrice + 40 * TickSize :
    entryOrder.AverageFillPrice - 40 * TickSize;

    SubmitOrderUnmanaged(0, action == OrderAction.Buy ? OrderAction.Sell : OrderAction.BuyToCover, OrderType.Limit, 1, takeProfitPrice, 0, uniqueSignalName, $"{uniqueSignalName}_PROFIT");

    // Aggiungi l'ordine al dizionario degli ordini attivi
    activeOrders[uniqueSignalName] = entryOrder;
    }
    }

    private bool IsConsecutiveConditionMet(int barsRequired, bool isBuyVolumeGreater)
    {
    for (int i = 0; i < barsRequired; i++)
    {
    if (i >= CurrentBar || i >= cumulativeDelta.DeltaClose.Count)
    {
    Print(Time[0] + " | IsConsecutiveConditionMet: Barra " + i + " non disponibile. Restituisco false.");
    return false;
    }

    if (isBuyVolumeGreater && cumulativeDelta.DeltaClose[i] <= 0)
    {
    Print(Time[0] + " | IsConsecutiveConditionMet: Barra " + i + ", DeltaClose: " + cumulativeDelta.DeltaClose[i] + " <= 0. Restituisco false.");
    return false;
    }

    if (!isBuyVolumeGreater && cumulativeDelta.DeltaClose[i] >= 0)
    {
    Print(Time[0] + " | IsConsecutiveConditionMet: Barra " + i + ", DeltaClose: " + cumulativeDelta.DeltaClose[i] + " >= 0. Restituisco false.");
    return false;
    }
    }
    Print(Time[0] + " | IsConsecutiveConditionMet: Condizione consecutiva soddisfatta per " + barsRequired + " barre. Restituisco true.");
    return true;
    }

    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    // Gestione ordini riempiti
    if (execution.Order != null && execution.Order.OrderState == OrderState.Filled)
    {
    Print($"Ordine eseguito: {execution.Order.Name} a {price}");

    // Rimuovi l'ordine dal dizionario degli ordini attivi se è stato chiuso
    if (activeOrders.ContainsKey(execution.Order.Name))
    {
    activeOrders.Remove(execution.Order.Name);
    }
    }
    }

    protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)
    {
    // Gestione aggiornamenti dell'ordine
    if (order.OrderState == OrderState.Rejected)
    {
    Print($"⚠️ Ordine {order.Name} RIFIUTATO: {order}");

    // Rimuovi l'ordine dal dizionario degli ordini attivi se è stato rifiutato
    if (activeOrders.ContainsKey(order.Name))
    {
    activeOrders.Remove(order.Name);
    }
    }
    }
    }
    }​

    #2
    Hello rottweiler,

    I've moved your post to a new thread as this was not related to the thread you were posting in.

    Your script adds a 1 tick series which will be BarsInProgress 1.
    Likely, you are probably wanting to process your logic when BarsInProgress is 0.

    In BarsInProgress 1, you will need to update the Cumulative Delta indicator.

    The Desktop SDK provides sample code.
    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


    The try and catch may be preventing the script from showing errors that could be causing undesired behavior.
    I recommend you remove the try and catch.

    If the expected behavior is not occurring, this would indicate that the condition that triggers the action is not evaluating as true. This could result in an order not being submitted, a value not being assigned, a drawing object not being drawn, or many other actions.
    With orders it's possible the order is not being submitted, or the order may have been ignored for several reasons (such as internal order handling, Bars required to trade, and Entry handling), or the order may have been automatically cancelled or was rejected.

    To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that triggers the action.
    The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.
    The debugging print output should clearly show what the condition is, what time the conditions are being compared, all values being compared, and how they are being compared.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Further, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.
    After enabling TraceOrders remove the instance of the strategy from the Configured list in the Strategies window and add a new instance of the strategy from the Available list.
    Last, print the order.ToString() at the top of the OnOrderUpdate() override, as this will show us when orders become working and are being filled, and print the GetCurrentAsk() and GetCurrentBid() in OnOrderUpdate() as well so we can see what the market price is at the time of a fill.

    I am happy to assist you with analyzing the output from the output window.

    Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

    Below is a link to a support article that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.


    Let me know the date and time the behavior occurred or when you are expecting the behavior to occur.

    Please let me know if I may further assist with analyzing the output or if you need any assistance creating a print or enabling TraceOrders.​


    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you, i will try everything tomorrow. I am writing from italy. Very kind.

      Comment


        #4
        Thanks to you I solved it, when the chart candle is green and the Order Flow Cumulative Delta candle is red, in the next candle the LONG position opens and vice versa ... BUT MECHANISMS HAPPEN THAT I DON'T KNOW IF THEY ARE RIGHT: ---EXAMPLE: opening DELTA LONG (orders from a contract) with Stop Loss and Take Profit; another DELTA LONG with Stop Loss and Take Profit and the first DELTA LONG still remains open (which is what I want, because I want my strategy to keep more open orders with Take Profit and Stop Loss); with these two open orders on the Chart Trader the number two of the purchased contracts appears; after a while a DELTA SHORT opens with its Take Profit and Stop Loss, on the Chart Trader the number of contracts goes from two to one, on the graph a line appears that connects the DELTA SHORT order with DELTA LONG, but on the graph the Stop Loss and the Take Profit of the first DELTA LONG always remain in evidence ... I DON'T UNDERSTAND IF EVERYTHING IS NORMAL OR NOT! THANK YOU. KINDLY, FOR YOUR AVAILABILITY.

        Comment


          #5
          region Using declarations

          using System;

          using System.Collections.Generic;

          using System.ComponentModel;

          using System.ComponentModel.DataAnnotations;

          using System.Linq;

          using System.Text;

          using System.Threading.Tasks;

          using System.Windows;

          using System.Windows.Input;

          using System.Windows.Media;

          using System.Xml.Serialization;

          using NinjaTrader.Cbi;

          using NinjaTrader.Gui;

          using NinjaTrader.Gui.Chart;

          using NinjaTrader.Gui.SuperDom;

          using NinjaTrader.Gui.Tools;

          using NinjaTrader.Data;

          using NinjaTrader.NinjaScript;

          using NinjaTrader.Core.FloatingPoint;

          using NinjaTrader.NinjaScript.Indicators;

          using NinjaTrader.NinjaScript.DrawingTools;

          #endregion




          namespace NinjaTrader.NinjaScript.Strategies

          {

          public class MyCustomStrategy : Strategy

          {

          private OrderFlowCumulativeDelta cumulativeDelta;




          [NinjaScriptProperty]

          public int MinTickMove { get; set; } = 4;




          [NinjaScriptProperty]

          public int MinIcebergVolume { get; set; } = 1000;




          // Dizionario per tenere traccia degli ordini aperti

          private Dictionary<string, Order> activeOrders = new Dictionary<string, Order>();




          // Variabile per tenere traccia dell'indice della barra corrente

          private int currentBarIndex = -1;




          // Variabili di stato per evitare aperture multiple sulla stessa candela

          private bool deltaLongOpenedThisBar = false;

          private bool deltaShortOpenedThisBar = false;

          private bool icebergLongOpenedThisBar = false;

          private bool icebergShortOpenedThisBar = false;




          protected override void OnStateChange()

          {

          if (State == State.SetDefaults)

          {

          Description = "Strategia Delta/Iceberg con gestione diretta degli ordini";

          Name = "MyCustomStrategy";

          EntriesPerDirection = 100; // Aumenta il numero massimo di posizioni

          EntryHandling = EntryHandling.AllEntries; // Accetta tutti gli ordini

          ExitOnSessionCloseSeconds = 30;

          IsExitOnSessionCloseStrategy = true;

          IsUnmanaged = true; // Modalità Unmanaged per gestione manuale

          TraceOrders = true; // Abilita TraceOrders

          }

          else if (State == State.Configure)

          {

          AddDataSeries(Data.BarsPeriodType.Tick, 1); // Aggiunge un data series tick per maggiore precisione

          }

          else if (State == State.DataLoaded)

          {

          cumulativeDelta = OrderFlowCumulativeDelta(CumulativeDeltaType.BidAs k, CumulativeDeltaPeriod.Bar, 0); // Inizializza l'indicatore

          }

          }




          protected override void OnBarUpdate()

          {

          if (BarsInProgress == 1)

          {

          // Aggiorna l'indicatore nel BarsInProgress 1

          cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);

          return;

          }




          // Controlla se siamo su una nuova barra

          if (currentBarIndex != CurrentBar)

          {

          // Resetta le variabili di stato all'inizio di ogni nuova candela

          deltaLongOpenedThisBar = false;

          deltaShortOpenedThisBar = false;

          icebergLongOpenedThisBar = false;

          icebergShortOpenedThisBar = false;




          // Aggiorna l'indice della barra corrente

          currentBarIndex = CurrentBar;




          // Stampa informazioni sulla nuova barra

          Print($"Nuova barra: {Time[0]}");

          }




          // Controlla se siamo in stato Realtime e se ci sono abbastanza barre per tradare

          if (State != State.Realtime || CurrentBar < BarsRequiredToTrade || cumulativeDelta?.DeltaClose == null)

          return;




          double barRange = Math.Abs(Close[0] - Open[0]);




          // Debug: Stampa i valori delle condizioni

          Print($"Bar {CurrentBar}: Close[0]={Close[0]}, Open[0]={Open[0]}, DeltaClose={cumulativeDelta.DeltaClose[0]}, DeltaOpen={cumulativeDelta.DeltaOpen[0]}, BarRange={barRange}");




          // --- Condizioni Delta ---

          if (activeOrders.Count < EntriesPerDirection)

          {

          // Delta Long: Candela del prezzo verde e venditori maggiori dei compratori (candela rossa dell'indicatore)

          Print(Time[0] + " | DELTA LONG: " +

          "deltaLongOpenedThisBar: " + deltaLongOpenedThisBar + " = false & " +

          "Close[0]: " + Close[0] + " > Open[0]: " + Open[0] + " & " +

          "cumulativeDelta.DeltaClose[0]: " + cumulativeDelta.DeltaClose[0] + " < cumulativeDelta.DeltaOpen[0] & " +

          "Close[0] - Open[0]: " + (Close[0] - Open[0]) + " >= MinTickMove * TickSize: " + (MinTickMove * TickSize));




          if (!deltaLongOpenedThisBar && Close[0] > Open[0] && cumulativeDelta.DeltaClose[0] < cumulativeDelta.DeltaOpen[0] && (Close[0] - Open[0]) >= MinTickMove * TickSize)

          {

          Print("Condizioni per DELTA_LONG soddisfatte");

          ExecuteTrade("DELTA_LONG", OrderAction.Buy);

          deltaLongOpenedThisBar = true;

          }




          // Delta Short: Candela del prezzo rossa e venditori minori dei compratori (candela verde dell'indicatore)

          Print(Time[0] + " | DELTA SHORT: " +

          "deltaShortOpenedThisBar: " + deltaShortOpenedThisBar + " = false & " +

          "Close[0]: " + Close[0] + " < Open[0]: " + Open[0] + " & " +

          "cumulativeDelta.DeltaClose[0]: " + cumulativeDelta.DeltaClose[0] + " > cumulativeDelta.DeltaOpen[0] & " +

          "Open[0] - Close[0]: " + (Open[0] - Close[0]) + " >= MinTickMove * TickSize: " + (MinTickMove * TickSize));




          if (!deltaShortOpenedThisBar && Close[0] < Open[0] && cumulativeDelta.DeltaClose[0] > cumulativeDelta.DeltaOpen[0] && (Open[0] - Close[0]) >= MinTickMove * TickSize)

          {

          Print("Condizioni per DELTA_SHORT soddisfatte");

          ExecuteTrade("DELTA_SHORT", OrderAction.SellShort);

          deltaShortOpenedThisBar = true;

          }

          }




          // --- Condizioni Iceberg ---

          CheckIcebergConditions();

          }




          private void CheckIcebergConditions()

          {

          if (Position.MarketPosition == MarketPosition.Flat || activeOrders.Count < EntriesPerDirection)

          {

          // Iceberg Short: Delta positivo consecutivo

          Print(Time[0] + " | ICEBERG SHORT: " +

          "icebergShortOpenedThisBar: " + icebergShortOpenedThisBar + " = false & " +

          "cumulativeDelta.DeltaClose[0]: " + cumulativeDelta.DeltaClose[0] + " > 0 & " +

          "IsConsecutiveConditionMet(10, true): " + IsConsecutiveConditionMet(10, true));




          if (!icebergShortOpenedThisBar && cumulativeDelta.DeltaClose[0] > 0 && IsConsecutiveConditionMet(10, true))

          {

          ExecuteTrade("ICEBERG_SHORT", OrderAction.SellShort);

          icebergShortOpenedThisBar = true;

          }




          // Iceberg Long: Delta negativo consecutivo

          Print(Time[0] + " | ICEBERG LONG: " +

          "icebergLongOpenedThisBar: " + icebergLongOpenedThisBar + " = false & " +

          "cumulativeDelta.DeltaClose[0]: " + cumulativeDelta.DeltaClose[0] + " < 0 & " +

          "IsConsecutiveConditionMet(10, false): " + IsConsecutiveConditionMet(10, false));




          if (!icebergLongOpenedThisBar && cumulativeDelta.DeltaClose[0] < 0 && IsConsecutiveConditionMet(10, false))

          {

          ExecuteTrade("ICEBERG_LONG", OrderAction.Buy);

          icebergLongOpenedThisBar = true;

          }

          }

          }




          private void ExecuteTrade(string signalName, OrderAction action)

          {

          // Crea un nome univoco per l'ordine

          string uniqueSignalName = $"{signalName}_{DateTime.Now:yyyyMMddHHmmssfff} ";




          // Invia ordine di apertura

          Print($"Invio ordine: {uniqueSignalName}, Azione: {action}");

          Order entryOrder = SubmitOrderUnmanaged(0, action, OrderType.Market, 1, 0, 0, "", uniqueSignalName);




          // Imposta stop loss e take profit

          if (entryOrder != null)

          {

          // Stop Loss: 40 tick

          double stopLossPrice = action == OrderAction.Buy ?

          entryOrder.AverageFillPrice - 40 * TickSize :

          entryOrder.AverageFillPrice + 40 * TickSize;




          double takeProfitPrice = action == OrderAction.Buy ?

          entryOrder.AverageFillPrice + 40 * TickSize :

          entryOrder.AverageFillPrice - 40 * TickSize;




          Print($"Ordine inviato: {uniqueSignalName}, StopLoss: {stopLossPrice}, TakeProfit: {takeProfitPrice}");




          SubmitOrderUnmanaged(0, action == OrderAction.Buy ? OrderAction.Sell : OrderAction.BuyToCover, OrderType.StopMarket, 1, 0, stopLossPrice, uniqueSignalName, $"{uniqueSignalName}_STOP");

          SubmitOrderUnmanaged(0, action == OrderAction.Buy ? OrderAction.Sell : OrderAction.BuyToCover, OrderType.Limit, 1, takeProfitPrice, 0, uniqueSignalName, $"{uniqueSignalName}_PROFIT");




          // Aggiungi l'ordine al dizionario degli ordini attivi

          activeOrders[uniqueSignalName] = entryOrder;

          }

          else

          {

          Print($"Errore: Ordine non creato per {uniqueSignalName}");

          }

          }




          private bool IsConsecutiveConditionMet(int barsRequired, bool isBuyVolumeGreater)

          {

          for (int i = 0; i < barsRequired; i++)

          {

          if (i >= CurrentBar || i >= cumulativeDelta.DeltaClose.Count)

          {

          Print(Time[0] + " | IsConsecutiveConditionMet: Barra " + i + " non disponibile. Restituisco false.");

          return false;

          }




          if (isBuyVolumeGreater && cumulativeDelta.DeltaClose[i] <= 0)

          {

          Print(Time[0] + " | IsConsecutiveConditionMet: Barra " + i + ", DeltaClose: " + cumulativeDelta.DeltaClose[i] + " <= 0. Restituisco false.");

          return false;

          }




          if (!isBuyVolumeGreater && cumulativeDelta.DeltaClose[i] >= 0)

          {

          Print(Time[0] + " | IsConsecutiveConditionMet: Barra " + i + ", DeltaClose: " + cumulativeDelta.DeltaClose[i] + " >= 0. Restituisco false.");

          return false;

          }

          }

          Print(Time[0] + " | IsConsecutiveConditionMet: Condizione consecutiva soddisfatta per " + barsRequired + " barre. Restituisco true.");

          return true;

          }




          protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)

          {

          // Gestione ordini riempiti

          if (execution.Order != null && execution.Order.OrderState == OrderState.Filled)

          {

          Print($"Ordine eseguito: {execution.Order.Name} a {price}");




          // Rimuovi l'ordine dal dizionario degli ordini attivi se è stato chiuso

          if (activeOrders.ContainsKey(execution.Order.Name))

          {

          activeOrders.Remove(execution.Order.Name);

          }

          }

          }




          protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)

          {

          // Gestione aggiornamenti dell'ordine

          Print(order.ToString());

          if (order.OrderState == OrderState.Rejected)

          {

          Print($"⚠️ Ordine {order.Name} RIFIUTATO: {order}");




          // Rimuovi l'ordine dal dizionario degli ordini attivi se è stato rifiutato

          if (activeOrders.ContainsKey(order.Name))

          {

          activeOrders.Remove(order.Name);

          }

          }

          }

          }

          }

          Comment


            #6
            Thanks to you I solved it, when the chart candle is green and the Order Flow Cumulative Delta candle is red, in the next candle the LONG position opens and vice versa ... BUT MECHANISMS HAPPEN THAT I DON'T KNOW IF THEY ARE RIGHT: ---EXAMPLE: opening DELTA LONG (orders from a contract) with Stop Loss and Take Profit; another DELTA LONG with Stop Loss and Take Profit and the first DELTA LONG still remains open (which is what I want, because I want my strategy to keep more open orders with Take Profit and Stop Loss); with these two open orders on the Chart Trader the number two of the purchased contracts appears; after a while a DELTA SHORT opens with its Take Profit and Stop Loss, on the Chart Trader the number of contracts goes from two to one, on the graph a line appears that connects the DELTA SHORT order with DELTA LONG, but on the graph the Stop Loss and the Take Profit of the first DELTA LONG always remain in evidence ... I DON'T UNDERSTAND IF EVERYTHING IS NORMAL OR NOT! THANK YOU. KINDLY, FOR YOUR AVAILABILITY.

            Comment


              #7
              PlayBack - LOG:

              LOG:Time,Category,Message,

              2/26/2025 4:03:21 PM,Order,Order='eb4e11891ab144bd80b8d50146a47634/Playback101' Name='DELTA_SHORT_20250226160320872_PROFIT' New state='Working' Instrument='ES 03-25' Action='Buy to cover' Limit price=5961.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='DELTA_SHORT_20250226160320872' Filled=0 Fill price=0 Error='No error' Native error='',

              2/26/2025 4:03:21 PM,Order,Order='eb4e11891ab144bd80b8d50146a47634/Playback101' Name='DELTA_SHORT_20250226160320872_PROFIT' New state='Accepted' Instrument='ES 03-25' Action='Buy to cover' Limit price=5961.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='DELTA_SHORT_20250226160320872' Filled=0 Fill price=0 Error='No error' Native error='',

              2/26/2025 4:03:21 PM,Order,Order='eb4e11891ab144bd80b8d50146a47634/Playback101' Name='DELTA_SHORT_20250226160320872_PROFIT' New state='Submitted' Instrument='ES 03-25' Action='Buy to cover' Limit price=5961.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='DELTA_SHORT_20250226160320872' Filled=0 Fill price=0 Error='No error' Native error='',

              2/26/2025 4:03:20 PM,NinjaScript,NinjaScript strategy 'MyCustomStrategy/351959418' submitting order,

              2/26/2025 4:03:20 PM,Order,Order='990bdf459caa444fa31c0e20a4d97c9f/Playback101' Name='DELTA_SHORT_20250226160320872_STOP' New state='Accepted' Instrument='ES 03-25' Action='Buy to cover' Limit price=0 Stop price=5981.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='DELTA_SHORT_20250226160320872' Filled=0 Fill price=0 Error='No error' Native error='',

              2/26/2025 4:03:20 PM,Order,Order='990bdf459caa444fa31c0e20a4d97c9f/Playback101' Name='DELTA_SHORT_20250226160320872_STOP' New state='Submitted' Instrument='ES 03-25' Action='Buy to cover' Limit price=0 Stop price=5981.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='DELTA_SHORT_20250226160320872' Filled=0 Fill price=0 Error='No error' Native error='',

              2/26/2025 4:03:20 PM,NinjaScript,NinjaScript strategy 'MyCustomStrategy/351959418' submitting order,

              2/26/2025 4:03:20 PM,Position,Instrument='ES 03-25' Account='Playback101' Average price=0 Quantity=0 Market position=Flat Operation=Remove,

              2/26/2025 4:03:20 PM,Execution,Execution='d17ecee7ae4b48c7b6b1ca99af 9d5c8c' Instrument='ES 03-25' Account='Playback101' Exchange=Default Price=5971.25 Quantity=1 Market position=Short Operation=Operation_Add Order='8de05ca09bfa43dd945d18910b87b76f' Time='1/2/2025 9:12 AM',

              2/26/2025 4:03:20 PM,Order,Order='8de05ca09bfa43dd945d18910b87b76f/Playback101' Name='DELTA_SHORT_20250226160320872' New state='Filled' Instrument='ES 03-25' Action='Sell short' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=1 Fill price=5971.25 Error='No error' Native error='',

              2/26/2025 4:03:20 PM,Order,Order='8de05ca09bfa43dd945d18910b87b76f/Playback101' Name='DELTA_SHORT_20250226160320872' New state='Working' Instrument='ES 03-25' Action='Sell short' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error='',

              2/26/2025 4:03:20 PM,Order,Order='8de05ca09bfa43dd945d18910b87b76f/Playback101' Name='DELTA_SHORT_20250226160320872' New state='Accepted' Instrument='ES 03-25' Action='Sell short' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error='',

              2/26/2025 4:03:20 PM,Order,Order='8de05ca09bfa43dd945d18910b87b76f/Playback101' Name='DELTA_SHORT_20250226160320872' New state='Submitted' Instrument='ES 03-25' Action='Sell short' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error='',

              2/26/2025 4:03:20 PM,NinjaScript,NinjaScript strategy 'MyCustomStrategy/351959418' submitting order,

              2/26/2025 4:03:01 PM,Position,Instrument='ES 03-25' Account='Playback101' Average price=5971.25 Quantity=1 Market position=Long Operation=Update,

              2/26/2025 4:03:01 PM,Execution,Execution='3646924ee503485b8753964951 9be982' Instrument='ES 03-25' Account='Playback101' Exchange=Default Price=5973.25 Quantity=1 Market position=Short Operation=Operation_Add Order='31cfb45d04e74d83b9b075b1686e6f41' Time='1/2/2025 9:05 AM',

              2/26/2025 4:03:01 PM,Order,Order='d3716214cbcf4b4e98c5bb8b8f1b7108/Playback101' Name='DELTA_LONG_20250226160228655_STOP' New state='Cancelled' Instrument='ES 03-25' Action='Sell' Limit price=0 Stop price=5953.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='DELTA_LONG_20250226160228655' Filled=0 Fill price=0 Error='No error' Native error='',

              2/26/2025 4:03:01 PM,Order,Order='d3716214cbcf4b4e98c5bb8b8f1b7108/Playback101' Name='DELTA_LONG_20250226160228655_STOP' New state='Cancel submitted' Instrument='ES 03-25' Action='Sell' Limit price=0 Stop price=5953.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='DELTA_LONG_20250226160228655' Filled=0 Fill price=0 Error='No error' Native error='',

              2/26/2025 4:03:01 PM,Order,Order='31cfb45d04e74d83b9b075b1686e6f41/Playback101' Name='DELTA_LONG_20250226160228655_PROFIT' New state='Filled' Instrument='ES 03-25' Action='Sell' Limit price=5973.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='DELTA_LONG_20250226160228655' Filled=1 Fill price=5973.25 Error='No error' Native error='',

              2/26/2025 4:03:01 PM,Position,Instrument='ES 03-25' Account='Playback101' Average price=5967.25 Quantity=2 Market position=Long Operation=Update,

              2/26/2025 4:03:01 PM,Execution,Execution='f6c22287621347c68ce8d5fd81 faaccf' Instrument='ES 03-25' Account='Playback101' Exchange=Default Price=5972.5 Quantity=1 Market position=Short Operation=Operation_Add Order='5c5f27bff5a6496395eb6c164abceb59' Time='1/2/2025 9:05 AM',
              ​​

              Comment


                #8
                Thanks to you I solved it, when the chart candle is green and the Order Flow Cumulative Delta candle is red, in the next candle the LONG position opens and vice versa ... BUT MECHANISMS HAPPEN THAT I DON'T KNOW IF THEY ARE RIGHT: ---EXAMPLE: opening DELTA LONG (orders from a contract) with Stop Loss and Take Profit; another DELTA LONG with Stop Loss and Take Profit and the first DELTA LONG still remains open (which is what I want, because I want my strategy to keep more open orders with Take Profit and Stop Loss); with these two open orders on the Chart Trader the number two of the purchased contracts appears; after a while a DELTA SHORT opens with its Take Profit and Stop Loss, on the Chart Trader the number of contracts goes from two to one, on the graph a line appears that connects the DELTA SHORT order with DELTA LONG, but on the graph the Stop Loss and the Take Profit of the first DELTA LONG always remain in evidence ... I DON'T UNDERSTAND IF EVERYTHING IS NORMAL OR NOT! THANK YOU. KINDLY, FOR YOUR AVAILABILITY.

                Comment


                  #9
                  PlayBack - LOG:

                  LOG:Time,Category,Message,

                  2/26/2025 4:03:21 PM,Order,Order='eb4e11891ab144bd80b8d50146a47634/Playback101' Name='DELTA_SHORT_20250226160320872_PROFIT' New state='Working' Instrument='ES 03-25' Action='Buy to cover' Limit price=5961.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='DELTA_SHORT_20250226160320872' Filled=0 Fill price=0 Error='No error' Native error='',

                  2/26/2025 4:03:21 PM,Order,Order='eb4e11891ab144bd80b8d50146a47634/Playback101' Name='DELTA_SHORT_20250226160320872_PROFIT' New state='Accepted' Instrument='ES 03-25' Action='Buy to cover' Limit price=5961.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='DELTA_SHORT_20250226160320872' Filled=0 Fill price=0 Error='No error' Native error='',

                  2/26/2025 4:03:21 PM,Order,Order='eb4e11891ab144bd80b8d50146a47634/Playback101' Name='DELTA_SHORT_20250226160320872_PROFIT' New state='Submitted' Instrument='ES 03-25' Action='Buy to cover' Limit price=5961.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='DELTA_SHORT_20250226160320872' Filled=0 Fill price=0 Error='No error' Native error='',

                  2/26/2025 4:03:20 PM,NinjaScript,NinjaScript strategy 'MyCustomStrategy/351959418' submitting order,

                  2/26/2025 4:03:20 PM,Order,Order='990bdf459caa444fa31c0e20a4d97c9f/Playback101' Name='DELTA_SHORT_20250226160320872_STOP' New state='Accepted' Instrument='ES 03-25' Action='Buy to cover' Limit price=0 Stop price=5981.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='DELTA_SHORT_20250226160320872' Filled=0 Fill price=0 Error='No error' Native error='',

                  2/26/2025 4:03:20 PM,Order,Order='990bdf459caa444fa31c0e20a4d97c9f/Playback101' Name='DELTA_SHORT_20250226160320872_STOP' New state='Submitted' Instrument='ES 03-25' Action='Buy to cover' Limit price=0 Stop price=5981.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='DELTA_SHORT_20250226160320872' Filled=0 Fill price=0 Error='No error' Native error='',

                  2/26/2025 4:03:20 PM,NinjaScript,NinjaScript strategy 'MyCustomStrategy/351959418' submitting order,

                  2/26/2025 4:03:20 PM,Position,Instrument='ES 03-25' Account='Playback101' Average price=0 Quantity=0 Market position=Flat Operation=Remove,

                  2/26/2025 4:03:20 PM,Execution,Execution='d17ecee7ae4b48c7b6b1ca99af 9d5c8c' Instrument='ES 03-25' Account='Playback101' Exchange=Default Price=5971.25 Quantity=1 Market position=Short Operation=Operation_Add Order='8de05ca09bfa43dd945d18910b87b76f' Time='1/2/2025 9:12 AM',

                  2/26/2025 4:03:20 PM,Order,Order='8de05ca09bfa43dd945d18910b87b76f/Playback101' Name='DELTA_SHORT_20250226160320872' New state='Filled' Instrument='ES 03-25' Action='Sell short' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=1 Fill price=5971.25 Error='No error' Native error='',

                  2/26/2025 4:03:20 PM,Order,Order='8de05ca09bfa43dd945d18910b87b76f/Playback101' Name='DELTA_SHORT_20250226160320872' New state='Working' Instrument='ES 03-25' Action='Sell short' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error='',

                  2/26/2025 4:03:20 PM,Order,Order='8de05ca09bfa43dd945d18910b87b76f/Playback101' Name='DELTA_SHORT_20250226160320872' New state='Accepted' Instrument='ES 03-25' Action='Sell short' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error='',

                  2/26/2025 4:03:20 PM,Order,Order='8de05ca09bfa43dd945d18910b87b76f/Playback101' Name='DELTA_SHORT_20250226160320872' New state='Submitted' Instrument='ES 03-25' Action='Sell short' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error='',

                  2/26/2025 4:03:20 PM,NinjaScript,NinjaScript strategy 'MyCustomStrategy/351959418' submitting order,

                  2/26/2025 4:03:01 PM,Position,Instrument='ES 03-25' Account='Playback101' Average price=5971.25 Quantity=1 Market position=Long Operation=Update,

                  2/26/2025 4:03:01 PM,Execution,Execution='3646924ee503485b8753964951 9be982' Instrument='ES 03-25' Account='Playback101' Exchange=Default Price=5973.25 Quantity=1 Market position=Short Operation=Operation_Add Order='31cfb45d04e74d83b9b075b1686e6f41' Time='1/2/2025 9:05 AM',

                  2/26/2025 4:03:01 PM,Order,Order='d3716214cbcf4b4e98c5bb8b8f1b7108/Playback101' Name='DELTA_LONG_20250226160228655_STOP' New state='Cancelled' Instrument='ES 03-25' Action='Sell' Limit price=0 Stop price=5953.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='DELTA_LONG_20250226160228655' Filled=0 Fill price=0 Error='No error' Native error='',

                  2/26/2025 4:03:01 PM,Order,Order='d3716214cbcf4b4e98c5bb8b8f1b7108/Playback101' Name='DELTA_LONG_20250226160228655_STOP' New state='Cancel submitted' Instrument='ES 03-25' Action='Sell' Limit price=0 Stop price=5953.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='DELTA_LONG_20250226160228655' Filled=0 Fill price=0 Error='No error' Native error='',

                  2/26/2025 4:03:01 PM,Order,Order='31cfb45d04e74d83b9b075b1686e6f41/Playback101' Name='DELTA_LONG_20250226160228655_PROFIT' New state='Filled' Instrument='ES 03-25' Action='Sell' Limit price=5973.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='DELTA_LONG_20250226160228655' Filled=1 Fill price=5973.25 Error='No error' Native error='',

                  2/26/2025 4:03:01 PM,Position,Instrument='ES 03-25' Account='Playback101' Average price=5967.25 Quantity=2 Market position=Long Operation=Update,

                  2/26/2025 4:03:01 PM,Execution,Execution='f6c22287621347c68ce8d5fd81 faaccf' Instrument='ES 03-25' Account='Playback101' Exchange=Default Price=5972.5 Quantity=1 Market position=Short Operation=Operation_Add Order='5c5f27bff5a6496395eb6c164abceb59' Time='1/2/2025 9:05 AM',
                  ​​

                  Comment


                    #10
                    2/26/2025 4:03:01 PM,Order,Order='fcc94acc53e04a26ac821b8562c199c6/Playback101' Name='DELTA_LONG_20250226160056095_STOP' New state='Cancelled' Instrument='ES 03-25' Action='Sell' Limit price=0 Stop price=5952.5 Quantity=1 Type='Stop Market' Time in force=GTC Oco='DELTA_LONG_20250226160056095' Filled=0 Fill price=0 Error='No error' Native error='',

                    2/26/2025 4:03:01 PM,Order,Order='fcc94acc53e04a26ac821b8562c199c6/Playback101' Name='DELTA_LONG_20250226160056095_STOP' New state='Cancel submitted' Instrument='ES 03-25' Action='Sell' Limit price=0 Stop price=5952.5 Quantity=1 Type='Stop Market' Time in force=GTC Oco='DELTA_LONG_20250226160056095' Filled=0 Fill price=0 Error='No error' Native error='',

                    2/26/2025 4:03:01 PM,Order,Order='5c5f27bff5a6496395eb6c164abceb59/Playback101' Name='DELTA_LONG_20250226160056095_PROFIT' New state='Filled' Instrument='ES 03-25' Action='Sell' Limit price=5972.5 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='DELTA_LONG_20250226160056095' Filled=1 Fill price=5972.5 Error='No error' Native error='',

                    2/26/2025 4:03:00 PM,Order,Order='3686fb154aab4596aaf1e07311c3f0f7/Playback101' Name='DELTA_LONG_20250226160300747_PROFIT' New state='Working' Instrument='ES 03-25' Action='Sell' Limit price=5981.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='DELTA_LONG_20250226160300747' Filled=0 Fill price=0 Error='No error' Native error='',

                    2/26/2025 4:03:00 PM,Order,Order='3686fb154aab4596aaf1e07311c3f0f7/Playback101' Name='DELTA_LONG_20250226160300747_PROFIT' New state='Accepted' Instrument='ES 03-25' Action='Sell' Limit price=5981.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='DELTA_LONG_20250226160300747' Filled=0 Fill price=0 Error='No error' Native error='',

                    2/26/2025 4:03:00 PM,Order,Order='3686fb154aab4596aaf1e07311c3f0f7/Playback101' Name='DELTA_LONG_20250226160300747_PROFIT' New state='Submitted' Instrument='ES 03-25' Action='Sell' Limit price=5981.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='DELTA_LONG_20250226160300747' Filled=0 Fill price=0 Error='No error' Native error='',

                    2/26/2025 4:03:00 PM,NinjaScript,NinjaScript strategy 'MyCustomStrategy/351959418' submitting order,

                    2/26/2025 4:03:00 PM,Order,Order='2e3f20fec2904b1b8b481210ee907b5a/Playback101' Name='DELTA_LONG_20250226160300747_STOP' New state='Accepted' Instrument='ES 03-25' Action='Sell' Limit price=0 Stop price=5961.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='DELTA_LONG_20250226160300747' Filled=0 Fill price=0 Error='No error' Native error='',

                    2/26/2025 4:03:00 PM,Order,Order='2e3f20fec2904b1b8b481210ee907b5a/Playback101' Name='DELTA_LONG_20250226160300747_STOP' New state='Submitted' Instrument='ES 03-25' Action='Sell' Limit price=0 Stop price=5961.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='DELTA_LONG_20250226160300747' Filled=0 Fill price=0 Error='No error' Native error='',

                    2/26/2025 4:03:00 PM,NinjaScript,NinjaScript strategy 'MyCustomStrategy/351959418' submitting order,

                    2/26/2025 4:03:00 PM,Position,Instrument='ES 03-25' Account='Playback101' Average price=5965.666666666667 Quantity=3 Market position=Long Operation=Update,

                    2/26/2025 4:03:00 PM,Execution,Execution='c8fc747e963b401f9c8f0d8742 c91ce0' Instrument='ES 03-25' Account='Playback101' Exchange=Default Price=5971.25 Quantity=1 Market position=Long Operation=Operation_Add Order='f05747bc52724ce0bcad1f53a2dd54f9' Time='1/2/2025 9:05 AM',

                    2/26/2025 4:03:00 PM,Order,Order='f05747bc52724ce0bcad1f53a2dd54f9/Playback101' Name='DELTA_LONG_20250226160300747' New state='Filled' Instrument='ES 03-25' Action='Buy' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=1 Fill price=5971.25 Error='No error' Native error='',

                    2/26/2025 4:03:00 PM,Order,Order='f05747bc52724ce0bcad1f53a2dd54f9/Playback101' Name='DELTA_LONG_20250226160300747' New state='Working' Instrument='ES 03-25' Action='Buy' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error='',

                    2/26/2025 4:03:00 PM,Order,Order='f05747bc52724ce0bcad1f53a2dd54f9/Playback101' Name='DELTA_LONG_20250226160300747' New state='Accepted' Instrument='ES 03-25' Action='Buy' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error='',

                    2/26/2025 4:03:00 PM,Order,Order='f05747bc52724ce0bcad1f53a2dd54f9/Playback101' Name='DELTA_LONG_20250226160300747' New state='Submitted' Instrument='ES 03-25' Action='Buy' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error='',

                    2/26/2025 4:03:00 PM,NinjaScript,NinjaScript strategy 'MyCustomStrategy/351959418' submitting order,

                    2/26/2025 4:02:28 PM,Order,Order='31cfb45d04e74d83b9b075b1686e6f41/Playback101' Name='DELTA_LONG_20250226160228655_PROFIT' New state='Working' Instrument='ES 03-25' Action='Sell' Limit price=5973.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='DELTA_LONG_20250226160228655' Filled=0 Fill price=0 Error='No error' Native error='',

                    2/26/2025 4:02:28 PM,Order,Order='31cfb45d04e74d83b9b075b1686e6f41/Playback101' Name='DELTA_LONG_20250226160228655_PROFIT' New state='Accepted' Instrument='ES 03-25' Action='Sell' Limit price=5973.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='DELTA_LONG_20250226160228655' Filled=0 Fill price=0 Error='No error' Native error='',

                    2/26/2025 4:02:28 PM,Order,Order='31cfb45d04e74d83b9b075b1686e6f41/Playback101' Name='DELTA_LONG_20250226160228655_PROFIT' New state='Submitted' Instrument='ES 03-25' Action='Sell' Limit price=5973.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='DELTA_LONG_20250226160228655' Filled=0 Fill price=0 Error='No error' Native error='',

                    2/26/2025 4:02:28 PM,NinjaScript,NinjaScript strategy 'MyCustomStrategy/351959418' submitting order,

                    2/26/2025 4:02:28 PM,Order,Order='d3716214cbcf4b4e98c5bb8b8f1b7108/Playback101' Name='DELTA_LONG_20250226160228655_STOP' New state='Accepted' Instrument='ES 03-25' Action='Sell' Limit price=0 Stop price=5953.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='DELTA_LONG_20250226160228655' Filled=0 Fill price=0 Error='No error' Native error='',

                    2/26/2025 4:02:28 PM,Order,Order='d3716214cbcf4b4e98c5bb8b8f1b7108/Playback101' Name='DELTA_LONG_20250226160228655_STOP' New state='Submitted' Instrument='ES 03-25' Action='Sell' Limit price=0 Stop price=5953.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='DELTA_LONG_20250226160228655' Filled=0 Fill price=0 Error='No error' Native error='',

                    2/26/2025 4:02:28 PM,NinjaScript,NinjaScript strategy 'MyCustomStrategy/351959418' submitting order,

                    2/26/2025 4:02:28 PM,Position,Instrument='ES 03-25' Account='Playback101' Average price=5962.875 Quantity=2 Market position=Long Operation=Update,

                    2/26/2025 4:02:28 PM,Execution,Execution='f9df387d82e1441f8f39f751a1 558bf7' Instrument='ES 03-25' Account='Playback101' Exchange=Default Price=5963.25 Quantity=1 Market position=Long Operation=Operation_Add Order='fcb3f222c95e4968a37773444157b0d7' Time='1/2/2025 9:01 AM',

                    Comment


                      #11
                      I'm messing up with the messages, I don't know why it sends them double, let me know if you need the LOG. THANKS. KINDLY

                      Comment


                        #12
                        Hello rottweiler,

                        As a tip, to export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
                        1. Click Tools -> Export -> NinjaScript Add-on...
                        2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
                        3. Click the 'Export' button
                        4. Enter the script name in the value for 'File name:'
                        5. Choose a save location -> click Save
                        6. Click OK to clear the export location message
                        By default your exported file will be in the following location:
                        • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
                        Below is a link to the help guide on Exporting NinjaScripts.


                        You can share an export instead of posting large amounts of code in a forum post or email.


                        That said, to understand the behavior it is necessary to print out the values with labels and the bar datetime as well as the order information.​

                        Prints will let you know why a condition is evaluating as true or false and why an action was triggered or not triggered at a specific time and TraceOrders and printing the order.ToString() in OnOrderUpdate() will let you know what orders are being submitted and what is happening to the orders.

                        Provide the output saved to a text file in your next post along with a date and time where behavior is unexpected, the behavior that occurred and the behavior you expect, and I would be happy to assist you with analyzing the issue.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello rottweiler,

                          From post # 2:

                          "In the strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that triggers the action.
                          The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.
                          The debugging print output should clearly show what the condition is, what time the conditions are being compared, all values being compared, and how they are being compared.​"

                          "Further, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.
                          After enabling TraceOrders remove the instance of the strategy from the Configured list in the Strategies window and add a new instance of the strategy from the Available list.​"

                          "Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply."


                          You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            The penultimate order with a contract is DELTA LONG which is opened with Stop Loss and Take Profit, then DELTA SHORT is opened with a contract (and DELTA LONG remains open because from the strategy I want each new order that is opened not to close the previous one) and the Chart Trader goes into FLAT, but on the chart the Stop Loss and Take Profit of DELTA LONG and DELTA SHORT remain highlighted, what I don't understand is if everything is normal, or if when a DELTA SHORT is opened with a DELTA LONG still open, in the code I have to specify that Stop Loss and Take Profit of DELTA LONG must be eliminated. THANK YOU. KINDLY YOURS
                            Attached Files

                            Comment


                              #15
                              Hello rottweiler,

                              "The penultimate order with a contract is DELTA LONG which is opened with Stop Loss and Take Profit, then DELTA SHORT is opened with a contract (and DELTA LONG remains open because from the strategy I want each new order that is opened not to close the previous one)"

                              Unfortunately, I am not understanding this. A strategy position can be long or short, it cannot be both.


                              "in the code I have to specify that Stop Loss and Take Profit of DELTA LONG must be eliminated"

                              Are you wanting to exit a long position with a sell market order, then cancel a working sell stop market order and sell limit order, then submit a sell market order to enter the opposite direction?
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by iantriestrading, 04-19-2025, 10:23 AM
                              3 responses
                              55 views
                              0 likes
                              Last Post iantriestrading  
                              Started by raysinred, Yesterday, 02:05 PM
                              2 responses
                              20 views
                              0 likes
                              Last Post raysinred  
                              Started by fredfred123, 09-29-2017, 05:16 AM
                              5 responses
                              807 views
                              0 likes
                              Last Post MysticFractalForums  
                              Started by algospoke, Today, 06:44 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post algospoke  
                              Started by gambcl, Today, 06:32 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post gambcl
                              by gambcl
                               
                              Working...
                              X