Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MultiTimeframe doesnot work well

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

    MultiTimeframe doesnot work well


    pls consider below exampe:

    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

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class MultiTimeFrame : Strategy
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "MultiTimeFrame";
    Calculate = Calculate.OnPriceChange;
    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;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(null, BarsPeriodType.Minute,5);
    AddDataSeries(null, BarsPeriodType.Minute,240);




    }
    }

    protected override void OnBarUpdate()
    {

    if(BarsInProgress == 1 && BarsInProgress == 2 )
    return;






    double FiveminOpen;
    double FiveminClose;
    double FiveminBid;

    FiveminOpen = Open[0];
    FiveminClose = Close[0];
    FiveminBid = GetCurrentBid (0);








    double FourhourOpen;
    double FourhourClose;
    double FourhourBid;

    FourhourOpen = Open[0];
    FourhourClose = Close[0];
    FourhourBid = GetCurrentBid (0);


    if( (FiveminBid > FiveminOpen) && (FourhourBid > FourhourOpen) )




    Draw.TextFixed(this, "DrawTextFixedBIP1", "FiveminOpen: "
    + FiveminOpen +
    " \nFiveminClose: " + FiveminClose +
    "\nFiveminBid: " +FiveminBid +
    "\nTrend up " , TextPosition.TopLeft);



    if( (FiveminBid < FiveminOpen) && (FourhourBid < FourhourOpen) )




    Draw.TextFixed(this, "DrawTextFixedBIP1", "FiveminOpen: "
    + FiveminOpen +
    " \nFiveminClose: " + FiveminClose +
    "\nFiveminBid: " +FiveminBid +
    "\nTrend down " , TextPosition.TopLeft);





    }
    }
    }


    when candle in four hour and five minute is in same direction i want see trend down message.
    but its only consider four hour condition and cant see 5 minute condition.
    How can i solve it?
    exist same problem with up trend message.
    Best regard


    #2
    Hmm ... first off, this bit of code,

    Code:
    if (BarsInProgress == 1 && BarsInProgress == 2)
       return;
    ​
    is poorly designed -- it will never be a true statement
    and thus it will never return, so your entire OnBarUpdate
    executes for every bar for the primary series and
    every bar for both secondary series.

    I think you meant to use ||, which is the OR operator.

    The && is the AND operator.

    Comment


      #3
      before i test OR operator.
      its not work well.
      it only consider h4 timeframe .
      how can i solve it?

      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