Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Volumetric Bar Code - Strategy Not Executing in Playback Mode

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

    Volumetric Bar Code - Strategy Not Executing in Playback Mode

    Hello...

    I am an absolute newbie in trying to put strategies together.

    I have spent the last 2 months trying to get up to speed enough to put a few ideas into some basic strategies, which have been a success. This is my first try at a little more complicated strategy using volumetric bar and data. I looked on your site about the code needed for these bars, which I placed in my code below. Then I put a few if statements together to execute orders if both volume and delta get to certain levels.

    When I run this in playback mode, I get no trades even though a number of bars on multiple days hit my criteria. I have tried to problem solve by going backwards and minimizing the coe, but still have no success. I feel like its something super basic which I am just not seeing.

    Any help or guidance you may be able to give me would be great. Thank you so much in advance for your help

    Below is my code.

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Calculate = Calculate.OnBarClose;
    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 = 1;
    TraceOrders =true;
    IsInstantiatedOnEachOptimizationIteration = true;
    Quantity = 1;
    SellStop = 16;
    TargetPrice = 80;
    VolumeThreshold = 10000;
    PositiveDeltaThreshold = 800;
    NegativeDeltaThreshold = -800;

    }
    else if (State == State.Configure)
    {
    SetStopLoss(@"Long", CalculationMode.Ticks, SellStop, false);
    SetStopLoss(@"Short", CalculationMode.Ticks, SellStop, false);
    SetProfitTarget(@"Long", CalculationMode.Ticks, TargetPrice);
    SetProfitTarget(@"Short", CalculationMode.Ticks, TargetPrice);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;





    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;

    if (barsType == null)
    return;


    try
    {
    double VWAPValue = OrderFlowVWAP(VWAPResolution.Standard, TradingHours.String2TradingHours("CME US Index Futures RTH"), VWAPStandardDeviations.Three, 1, 2, 3).VWAP[0];
    double price;
    Print("=========================================== ==============================");
    Print("Bar: " + CurrentBar);
    Print("Trades: " + barsType.Volumes[CurrentBar].Trades);
    Print("Total Volume: " + barsType.Volumes[CurrentBar].TotalVolume);
    Print("Total Buying Volume: " + barsType.Volumes[CurrentBar].TotalBuyingVolume);
    Print("Total Selling Volume: " + barsType.Volumes[CurrentBar].TotalSellingVolume);
    Print("Delta for bar: " + barsType.Volumes[CurrentBar].BarDelta);
    Print("Delta for bar (%): " + barsType.Volumes[CurrentBar].GetDeltaPercent());
    Print("Delta for Close: " + barsType.Volumes[CurrentBar].GetDeltaForPrice(Close[0]));
    Print("Ask for Close: " + barsType.Volumes[CurrentBar].GetAskVolumeForPrice(Close[0]));
    Print("Bid for Close: " + barsType.Volumes[CurrentBar].GetBidVolumeForPrice(Close[0]));
    Print("Volume for Close: " + barsType.Volumes[CurrentBar].GetTotalVolumeForPrice(Close[0]));
    Print("Maximum Ask: " + barsType.Volumes[CurrentBar].GetMaximumVolume(true, out price) + " at price: " + price);
    Print("Maximum Bid: " + barsType.Volumes[CurrentBar].GetMaximumVolume(false, out price) + " at price: " + price);
    Print("Maximum Combined: " + barsType.Volumes[CurrentBar].GetMaximumVolume(null, out price) + " at price: " + price);
    Print("Maximum Positive Delta: " + barsType.Volumes[CurrentBar].GetMaximumPositiveDelta());
    Print("Maximum Negative Delta: " + barsType.Volumes[CurrentBar].GetMaximumNegativeDelta());
    Print("Max seen delta (bar): " + barsType.Volumes[CurrentBar].MaxSeenDelta);
    Print("Min seen delta (bar): " + barsType.Volumes[CurrentBar].MinSeenDelta);
    Print("Cumulative delta (bar): " + barsType.Volumes[CurrentBar].CumulativeDelta);

    Print("Delta Since High (bar): " + barsType.Volumes[CurrentBar].DeltaSh);

    Print("Delta Since Low (bar): " + barsType.Volumes[CurrentBar].DeltaSl);

    if (barsType.Volumes[CurrentBar].TotalVolume > VolumeThreshold && barsType.Volumes[CurrentBar].BarDelta > PositiveDeltaThreshold && Close[0] > Open[0] && Position.MarketPosition == MarketPosition.Flat)
    EnterLong(Convert.ToInt32(Quantity), @"Long");

    if (barsType.Volumes[CurrentBar].TotalVolume > VolumeThreshold && barsType.Volumes[CurrentBar].BarDelta < NegativeDeltaThreshold && Close[0] < Open[0] && Position.MarketPosition == MarketPosition.Flat)
    EnterShort(Convert.ToInt32(Quantity), @"Short");
    }
    catch (Exception e) {
    Print ("Something has gone wrong." + e.ToString());
    }​

    #2
    Hello pnolan20,

    Thanks for your post and welcome to the NinjaTrader Forums!

    So I may accurately assist on the matter, please answer all the questions below.
    • What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)
    • Are you using Market Replay data or Historical data with Playback?
    • What instrument symbol (and expiry if applicable) have you selected? For example, ES 03-24, AAPL, EURUSD, etc.
    • (For a chart) what interval is selected? For example, 1 Minute Volumetric, 5 Minute, 1 Day, 2000 Volume, 4 Renko, etc.
    • Do you see any error messages in the Log tab of the Control Center? If so, what does the error report?
    Add prints one line above the conditions to place the orders the prints out all the values being used in the condition to place an order to confirm if the conditions are becoming true.

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

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    Are you seeing that the prints show the conditions to place the trades are becoming true?

    I look forward to assisting further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Brandon,

      Thanks for the quick reply.

      To answer your questions:
      1. 8.0.28.0 64-bit
      2.Market Reply
      3. MES 12-23
      4. 5 minute volumetric chart
      5. No idea what log tab is.

      I will add prints today and see if that helps.

      Comment


        #4
        Hello pnolan20,

        Thanks for your notes.

        The Log tab is on the Control Center window and this would inform you if any errors occurred when running the strategy.

        See this help guide page about the Log tab: https://ninjatrader.com/support/help...8/log_tab2.htm

        Ensure you have Market Replay data downloaded in the Tools > Historical Data window for the instrument and dates you are testing over.

        Adding debugging prints to the script (one line above the condition) will allow you to see exactly how your logic to place trades is evaluating.

        If the expected trade(s) are not appearing, this would indicate that the condition to place the order is not evaluating as true or the order is being ignored for other reasons.

        To understand why the script is behaving as it is, such as placing orders or not placing orders 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.

        Also, enable TraceOrders which will let you know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

        Please let us know if you need assistance analyzing the output from the output window.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Thank you...I will do this today. One quick follow-up. You mentioned TraceOrders. Is that talked about in the help guide page ou linked above? thanks

          Comment


            #6
            Hello pnolan20,

            Thanks for your notes.

            TraceOrders are discussed in the forum thread about using prints to debug a script shared on post # 2.

            You could find the TraceOrders educational resources help guide page here for more information on this property: https://ninjatrader.com/support/help...aceorders2.htm
            Brandon H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by port119, 04-27-2024, 02:43 PM
            3 responses
            30 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by sastrades, 01-31-2024, 10:19 PM
            13 responses
            203 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by reynoldsn, Today, 04:40 PM
            0 responses
            4 views
            0 likes
            Last Post reynoldsn  
            Started by Philippe56140, 04-27-2024, 02:35 PM
            6 responses
            54 views
            0 likes
            Last Post bltdavid  
            Started by ETFVoyageur, Yesterday, 06:05 PM
            7 responses
            45 views
            0 likes
            Last Post ETFVoyageur  
            Working...
            X