Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Order fill resolution in Strategy Analyzer

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

    Order fill resolution in Strategy Analyzer

    Hello,

    I have an strategy that uses an indicator in 30 min timeframe and this indicator needs tick replay mode to works.

    I need to run backtesting to this, using ES at 30 min timeframe but filling the orders at tick granularity. It is not possible to do this, because the indicator needs tick replay to work. So, how could I change the code in order to the strategy allways take the indicator data from 30 min TF (enabling the tick replay feature), but fills the orders with 1 tick resolution data?

    This is the original code:

    namespace NinjaTrader.NinjaScript.Strategies.GomPro
    {
    public class GomOFNakedPOCSampleStrat : Strategy
    {
    private Indicators.GomPro.GomOrderFlowProLevels GomOrderFlowProLevels1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Fades closest naked POC";
    Name = "GomOFNakedPOCSampleStrat";
    Calculate = Calculate.OnEachTick;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    Target = 10;
    Stop = 10;
    MinimumAge =5;
    }
    else if (State == State.Configure)
    {
    SetProfitTarget("L", CalculationMode.Ticks, Target);
    SetStopLoss("L", CalculationMode.Ticks, Stop, false);
    }
    else if (State == State.DataLoaded)
    {
    // you can use the ninja strategy builder to get the correct initializer
    // here are the enums:

    // public enum DeltaCalcType {BidAsk,UpDownTick};
    // public enum ImbalanceComparisonType { Ratio, Difference };
    // public enum ImbalanceTypeType { Diagonal, Horizontal, Both };


    GomOrderFlowProLevels1 = GomOrderFlowProLevels(Close, Gom.DeltaLib.DeltaCalcType.BidAsk, -1, 0, 1, false,
    Gom.OrderFlow.ImbalanceDirectionType.Diagonal, Gom.OrderFlow.ImbalanceComparisonType.Ratio, 3,
    Gom.OrderFlow.ImbalanceDirectionType.None, Gom.OrderFlow.ImbalanceComparisonType.Ratio, 3,
    0,-1, 3, 0, Gom.OrderFlow.SRZoneEndConditionType.FullCandleCro ss, 1, false);

    }

    }

    protected override void OnBarUpdate()
    {
    if (IsFirstTickOfBar)

    {

    GomOrderFlowProLevels1.Update();
    double price=0;
    bool found=false;

    // for each level like NakedPOCLow1, we have to check is the data series actually contains a number.
    // NakedPOCLow1BarsAgo contains the "age" of the naked poc, ie how many bars ago it created.

    if ( GomOrderFlowProLevels1.NakedPOCLow1.IsValidDataPoi nt(0) && // check if value is populated
    GomOrderFlowProLevels1.NakedPOCLow1BarsAgo[0] >=MinimumAge) // check if poc is old enough
    {
    found=true;
    price=GomOrderFlowProLevels1.NakedPOCLow1[0]; // get the poc
    }
    //same for second level
    else if ( GomOrderFlowProLevels1.NakedPOCLow2.IsValidDataPoi nt(0) && // check if value is populated
    GomOrderFlowProLevels1.NakedPOCLow2BarsAgo[0] >=MinimumAge) // check if poc is old enough
    {
    found=true;
    price=GomOrderFlowProLevels1.NakedPOCLow2[0]; // get the poc
    }

    // etc etc all levels can be checked




    if (found)
    EnterLongLimit(Convert.ToInt32(DefaultQuantity), price, @"L");


    }
    }

    Thanks!

    #2
    Hi federicoo, thanks for your question.

    You must use the order entry method overload that accepts a BarsInProgressIndex. If your 1 tick series were the only added data series (BarsArray[1]) you would submit the Long Limit order like this:
    EnterLongLimit(1, true, Convert.ToInt32(DefaultQuantity), price, @"L")

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by andrewtrades, Today, 04:57 PM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by chbruno, Today, 04:10 PM
    0 responses
    6 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by josh18955, 03-25-2023, 11:16 AM
    6 responses
    436 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    7 views
    0 likes
    Last Post FAQtrader  
    Started by rocketman7, Today, 09:41 AM
    5 responses
    19 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X