Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy wont open trades!!! PLEASE HELP!

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

    Strategy wont open trades!!! PLEASE HELP!

    So i built a basic BB Crossover strategy and the code compiles fine, but even tho the strat is enabled, the start behaviour is set to immediate sync with account, its not opening any trades. so basically when the price closes either above or below the bb bands it should open a trade in the opposite direction. but it wont. here is the code:
    ```

    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 BollingerBandsStrategy : Strategy
    {
    private int bollingerPeriod = 20;
    private double bollingerDeviation = 2;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    // Set strategy defaults
    // ... (Your existing default settings)

    // Allow the strategy to work with any timeframe
    Calculate = Calculate.OnEachTick;
    }
    else if (State == State.Configure)
    {
    // Add additional configuration here
    AddDataSeries(Data.BarsPeriodType.Minute, 1);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 1) // Check if the primary data series (index 0) is processing
    {
    // Calculate Bollinger Bands
    var bollinger = Bollinger(bollingerPeriod, (int)bollingerDeviation);

    // Print relevant information for debugging
    Print("Current Bar: " + CurrentBar);
    Print("Close[0]: " + Close[0]);
    Print("Upper[0]: " + bollinger.Upper[0]);
    Print("Lower[0]: " + bollinger.Lower[0]);

    // Check for short trade entry
    if (Close[0] > bollinger.Upper[0])
    {
    Print("Short Trade Entry Condition Met");
    EnterShort("Short Entry"); // Open a short trade
    }

    // Check for long trade entry
    if (Close[0] < bollinger.Lower[0])
    {
    Print("Long Trade Entry Condition Met");
    EnterLong("Long Entry"); // Open a long trade
    }
    }
    }
    }
    }

    ```​

    #2
    Hello LiamTwine,

    Thank you for your post.

    So I may accurately assist you, please answer the following questions:
    • What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)
    • Who are you connected to? This is displayed in green in the lower-left corner of the Control Center window.
    • What color is the strategy name on the Strategies tab of the Control Center after it is enabled?
    • What instrument symbol (and expiry if applicable) have you selected? For example, ES 03-22, AAPL, EURUSD, etc.
    • (For a chart) what interval is selected? For example, 5 minute, 1 day, 2000 volume, 4 Renko, etc.
    • Do you receive an error on the screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?
    ​I look forward to your reply.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    53 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    70 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X