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

RSI Overbought Oversold Strategy not being Populated

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

    RSI Overbought Oversold Strategy not being Populated

    I am creating my first strategy and trying to perform an if else if statement between overbought and oversold of RSI and Stochastics. But when I enable the strategy on the chart, RSI and Stochastics is not populated. please see the attached code below:

    {
    public class RSITestv2 : Strategy
    {
    private RSI RSI1;
    private Stochastics Stochastics1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "RSITestv2";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    RSI1 = RSI(Close, 14, 3);
    Stochastics1 = Stochastics(Close, 7, 14, 3);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    {
    if (
    // Overbought
    ((RSI1.Avg[0] >= 70)
    || (IsFalling(Stochastics1.D) == true)))
    {
    Draw.ArrowUp(this, @"RSITestv2 Arrow up_1", false, 0, 0, Brushes.Maroon);
    }

    // Set 2
    else if (
    // Oversold
    ((RSI1.Avg[0] <= 30)
    || (IsRising(Stochastics1.D) == true)))
    {
    Draw.ArrowDown(this, @"RSITestv2 Arrow down_1", false, 0, 0, Brushes.DarkGreen);
    }
    }
    }
    }
    }
    I followed the youtube video from NinjaTrader - https://www.youtube.com/watch?v=JZpo01eSO9c

    What am I doing wrong to not have RSI and Stochastic to not show up on the chart?
    Attached Files
    Last edited by w0lverine; 04-03-2019, 04:54 AM.

    #2
    Hello w0lverine,

    Thanks for your post.

    The video is showing the use of the NT7 strategy wizard. Your code shows you are using NT8. I am not sure if you are using the NT8 strategy builder or are coding directly in Ninjascript so I will provide solutions for both.

    If I understand correctly, you are expecting the RSI and the Stochastics to be drawn on the chart when enabling the strategy.

    For Ninjascript created code, to accomplish this you would need to use AddChartIndicator(), please see the help guide here: https://ninjatrader.com/support/help...tindicator.htm Example, in State.DataLoaded you would have AddChartIndicator(RSI1);

    If using the strategy builder, then when selecting the indicator in the strategy builder, in the parameters of the indicator is the checkbox "Plot on chart" that must be checked in order to automatically display the indicator. You need only check one occurrence of the indicator to have it displayed (so if you have 10 sets using the RSI with the same values no need to check plot on chart for all 10, only 1 needs to be checked in order to see the indicator, otherwise all 10 are displayed on top of each other).

    The code for drawing the arrows will draw arrows at the price (Y value) level of 0 which will likely not be visible on the chart. You would need to use some price value reference, such as above or below the bar where the condition occurred. Also, by default, the draw objects will only show the latest occurrence. To see all of the historical markers you would need to create unique draw objects by using a unique tag name. Here is a link to a short video, in the strategy builder, showing how to create unique tag names and locate the Y value of the draw objects. https://Paul-ninjaTrader.tinytake.co...A4M184NTkwOTg3
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Paul,

      Yes you are correct, I am using NT8 and the youtube video as the guideline while I used the NT8 strategy builder. It was confusing at first, but once I got the hang of it, I was able to translate what he was doing with Strategy builder for NT8 and the if else if statements were the same at the end of the day.

      Yes, I am expecting the RSI and stochastics to be drawn on the chart when enabling the strategy.

      And that is my issue, I did not check the box "plot on chart".. Thank you!

      As for drawing the arrows... I did not know that. I'll dig more into that today. Thanks for looking forward on my solution.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by ScottW, Today, 06:09 PM
      0 responses
      2 views
      0 likes
      Last Post ScottW
      by ScottW
       
      Started by Board game geek, 10-29-2023, 12:00 PM
      14 responses
      244 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Waxavi, 04-19-2024, 02:10 AM
      4 responses
      56 views
      0 likes
      Last Post sonia0101  
      Started by cmtjoancolmenero, Today, 03:58 PM
      0 responses
      9 views
      0 likes
      Last Post cmtjoancolmenero  
      Started by Segwin, 05-07-2018, 02:15 PM
      11 responses
      1,778 views
      0 likes
      Last Post aligator  
      Working...
      X