Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need Help with my startegy

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

    Need Help with my startegy

    Can someone please debug my code, it just doesnt work :

    idea is if price goes up n breaks 00 or 50 level, it shud buy, and if price goes down and breaks 00 or 50 level it should sell.

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// System1
    /// </summary>
    [Description("System1")]
    public class S1 : Strategy
    {

    #region Variables
    // Wizard generated variables
    private int Lots=1 ; // Default lot sizes
    private int Intervals = 50; // Default setting for intervals

    // User defined variables (add any user defined variables below)
    double Point=0.0001; // Point
    double UpperLevel=0, LowerLevel=0, LastLevel=0;
    int H=0, L=0;

    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    CalculateOnBarClose = false;
    //SetProfitTarget(CalculationMode.Ticks, 50);
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    Point=TickSize;

    if(H==0 && L==0){
    L= (int) (GetCurrentBid()/TickSize);
    L= L - L%Intervals;
    H= L+Intervals;

    UpperLevel=H*Point;
    LowerLevel=L*Point;

    }


    if(High[0]>=UpperLevel){
    LastLevel=UpperLevel;
    Print("Upperlevel broken: "+LastLevel);

    //Calculate new levels
    UpperLevel=LastLevel+Intervals*Point;
    LowerLevel=LastLevel-Intervals*Point;


    Print("Requesting BUY at: "+ LastLevel);
    EnterLong(Lots,"S1");


    }

    if(Low[0]<=LowerLevel){
    LastLevel=LowerLevel;
    Print("Lowerlevel broken: "+ LastLevel);

    //Calculate new levels
    UpperLevel=LastLevel+Intervals*Point;
    LowerLevel=LastLevel-Intervals*Point;



    Print("Requesting SELL at: "+ LastLevel);
    EnterShort(Lots,"S1");


    }
    }

    #region Properties
    [Description("")]
    [Category("Parameters")]
    public int lots
    {
    get { return Lots; }
    set { Lots = Math.Max(1, value); }
    }

    [Description("")]
    [Category("Parameters")]
    public int intervals
    {
    get { return Intervals; }
    set { Intervals = Math.Max(1, value); }
    }

    #endregion

    }
    }

    #2
    Hello,

    This link may help:
    DenNinjaTrader Customer Service

    Comment


      #3
      I followed the same procedure of putting Print options, but its just goin all wrong.

      when its not suppose to enter the if conditions, its entering.

      Pls help

      Comment


        #4
        peterdias77,

        Remember that during backtesting you have a signal bar and a trade bar. The signal bar is the bar in which your conditions evaluate to true. Because the signal bar is evaluated at bar close that bar has no more tradeable opportunities. This means that your orders are effectively placed at the open of the next bar or the trade bar.

        In regards to your 00 and 50 level orders, this is why you do not see fills at those prices. You placed the order when those conditions were true, but remember you are filled at the open of the next bar. If you want to try and guarantee a price you would want to use a limit order instead of a market order.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X