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 charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        59 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        143 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        161 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        97 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        276 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X