Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Programing question

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

    Programing question

    I am trying to program a automated trading strategy that just follows the flow of price movement for my entrys and my exits, am always in the market,whether long or short, no indicators at all. I exit my short position on the first break above the previous bars, high of that bar if price has been moving down and I would simultaneously than go long. I would than stay long till the break of the previous bars low of that bar which than I would exit my long position and go short. I wrote some code as you can see below, but its missing something(s) to make it run properly and am not sure what it would take to make the strategy run, any input would be greatly appreciated.

    /// <summary>
    /// LONG AND SHORT
    /// </summary>
    [Description("LONG AND SHORT")]
    [Gui.Design.DisplayName("STEVE")]
    public class FLOWTRADING : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)
    #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;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (Bars.CurrentAsk == High[1] + 1 * TickSize
    && Low[1] < Low[2]
    && High[1] <= High[2])
    {
    EnterLongLimit(DefaultQuantity, Bars.CurrentAsk, "");
    }

    // Condition set 2
    if (Low[2] < Low[3]
    && Bars.CurrentAsk == High[1] + 1 * TickSize
    && High[1] <= High[2])
    {
    EnterLongLimit(DefaultQuantity, Bars.CurrentAsk, "");
    }

    // Condition set 3
    if (Bars.CurrentAsk == High[1] + 1 * TickSize
    && Low[3] < Low[4]
    && High[1] <= High[2]
    && High[2] <= High[3])
    {
    EnterLongLimit(DefaultQuantity, Bars.CurrentAsk, "");
    }

    // Condition set 4
    if (Bars.CurrentAsk == High[1] + 1 * TickSize
    && Low[4] < Low[5]
    && High[1] <= High[2]
    && High[2] <= High[3]
    && High[3] <= High[4])
    {
    EnterLongLimit(DefaultQuantity, Bars.CurrentAsk, "");
    }

    // Condition set 5
    if (Bars.CurrentAsk == High[1] + 1 * TickSize
    && Low[5] < Low[6]
    && High[1] <= High[2]
    && High[2] <= High[3]
    && High[3] <= High[4]
    && High[4] <= High[5])
    {
    EnterLongLimit(DefaultQuantity, Bars.CurrentAsk, "");
    }

    // Condition set 6
    if (Bars.CurrentAsk == High[1] + 1 * TickSize
    && High[1] > High[2]
    && Low[1] < Low[2])
    {
    EnterLongLimit(DefaultQuantity, Bars.CurrentAsk, "");
    }

    // Condition set 7
    if (Bars.CurrentAsk == High[1] + 1 * TickSize
    && Low[0] < Low[1])
    {
    EnterLongLimit(DefaultQuantity, Bars.CurrentAsk, "");
    }

    // Condition set 8
    if (Bars.CurrentBid == Low[1] + -1 * TickSize
    && High[1] > High[2]
    && Low[1] >= Low[2])
    {
    EnterShortLimit(DefaultQuantity, Bars.CurrentBid, "");
    }

    // Condition set 9
    if (Bars.CurrentBid == Low[1] + -1 * TickSize
    && High[2] > High[3]
    && Low[1] >= Low[2])
    {
    EnterShortLimit(DefaultQuantity, Bars.CurrentBid, "");
    }

    // Condition set 10
    if (Bars.CurrentBid == Low[1] + -1 * TickSize
    && High[3] > High[4]
    && Low[1] >= Low[2]
    && Low[2] >= Low[3])
    {
    EnterShortLimit(DefaultQuantity, Bars.CurrentBid, "");
    }

    // Condition set 11
    if (Bars.CurrentBid == Low[1] + -1 * TickSize
    && High[4] > High[5]
    && Low[1] >= Low[2]
    && Low[2] >= Low[3]
    && Low[3] >= Low[4])
    {
    EnterShortLimit(DefaultQuantity, Bars.CurrentBid, "");
    }

    // Condition set 12
    if (Bars.CurrentBid == Low[1] + -1 * TickSize
    && High[5] > High[6]
    && Low[1] >= Low[2]
    && Low[2] >= Low[3]
    && Low[3] >= Low[4]
    && Low[4] >= Low[5])
    {
    EnterShortLimit(DefaultQuantity, Bars.CurrentBid, "");
    }

    // Condition set 13
    if (Bars.CurrentBid == Low[1] + -1 * TickSize
    && Low[1] < Low[2]
    && High[1] > High[2])
    {
    EnterShortLimit(DefaultQuantity, Bars.CurrentBid, "");
    }

    // Condition set 14
    if (Bars.CurrentBid == Low[1] + -1 * TickSize
    && High[0] > High[1])
    {
    EnterShortLimit(DefaultQuantity, Bars.CurrentBid, "");
    }
    }


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


    #2
    imported post

    Sorry your strategy is way too complex to comment.

    I suggest:
    - start of a real simple wizard generated sample
    - check if that is working as expected
    - add logic step by step to see where it breaks

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by bmartz, 03-12-2024, 06:12 AM
    4 responses
    32 views
    0 likes
    Last Post bmartz
    by bmartz
     
    Started by Aviram Y, Today, 05:29 AM
    4 responses
    12 views
    0 likes
    Last Post Aviram Y  
    Started by algospoke, 04-17-2024, 06:40 PM
    3 responses
    28 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by gentlebenthebear, Today, 01:30 AM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by cls71, Today, 04:45 AM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X