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

need help with my strategy

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

    need help with my strategy

    here is the logic, if the price goes above last high pivot, go long and if the price goes below last low pivot , go short.there must be something wrong with the condition i set so it didn't work. I also attached the fractal indicator i am using for my strategy . thanks for your help

    public class FractalStrategy : Strategy
    {
    #region Variables

    private int myInput0 = 1;
    #endregion

    protected override void Initialize()
    {
    Add(Fractals());

    CalculateOnBarClose = true;
    }

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

    if ( High[0]> Fractals().Plot1[1]) // wrong conditon

    {
    EnterLong();
    }
    Attached Files

    #2
    Hello peterhxu7,

    Thanks for opening the thread.

    I would recommend placing prints for the values of the items used in your condition so you may observe why the condition did or did not become true. From a glance, it looks like you are looking for a plot value of a previous bar, but the indicator may not have a plot value for that bar.

    Example prints could be as follows to observe your logic as it executes.
    Code:
    Print("");
    Print(High[0]);
    Print(Fractals().Plot1[1]);
    if ( High[0]> Fractals().Plot1[1])
    I may also suggest to use Position.MarketPosition to control your entries so you will not reverse your position by calling EnterLong() when you are in s short position, for example.

    I've included resources on debugging - https://ninjatrader.com/support/foru...ead.php?t=3418

    Position.MarketPosition - https://ninjatrader.com/support/help...etposition.htm

    Please let us know if you have any questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      hi jim:
      thanks for your response. I tried the print function and it didn't print anything on the chart.
      but if you had a chance to take a look at the indicator Fractal itself, there are two plots and both of the plots value can be found on my chart. it's so weaired

      Comment


        #4
        Hello peterhxu7,

        Prints are displayed in the NinjaScript Output window. (Control Center > Tools > Output Window...)

        The Fractals indicator has two plots, but does not make a plot on every bar formation. You may use the data box with the middle mouse button on a chart to determine if a bar index has a plot value associated with it. A barsAgo reference of 1 will look for the value at the previous bar, not to be confused with the last value that was plotted. The prints in the output window will also make this clearer.

        Please let me know if you have any additional questions.
        JimNinjaTrader Customer Service

        Comment


          #5
          thanks . The values showed on the output window were all wrong. I took a look at the Fractal indicator again. There are regions HighPivot and LowPivot. can i code something like Print("");
          Print(Fractals().HighPivot());

          THank again for your help

          Comment


            #6
            Hello peterhxu7,

            I do not see a public HighPivot() method or LowPivot() method in this indicator that would let you use that syntax.

            My recommendation would be to modify the indicator so it will always have a plot value instead of plotting only when a swing is made. For example, always plot 0 and apply a different value when a swing is made. This way, you can keep the track of the last made High or Low plot if a new high or low is made. (When you see a plot value that is not 0, update a variable in your strategy that tells you the last high or last low plotted.)

            PlotColors can also be used to set a Plot's color to Color.Transparent or to a visible color. So if a plot value is 0, you can make the color of that plot transparent.

            PlotColors - https://ninjatrader.com/support/help...plotcolors.htm

            Please let us know if we can be of further assistance.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by f.saeidi, Today, 12:14 PM
            3 responses
            7 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by Russ Moreland, Today, 12:54 PM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by philmg, Today, 12:55 PM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Started by TradeForge, 04-19-2024, 02:09 AM
            2 responses
            31 views
            0 likes
            Last Post TradeForge  
            Started by aprilfool, 12-03-2022, 03:01 PM
            3 responses
            327 views
            0 likes
            Last Post NinjaTrader_Adrian  
            Working...
            X