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

Strategy which does not give orders..

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

    Strategy which does not give orders..

    Hello,

    I am programming a simple strategy which part of it checks if RSI is above 50 (uptrend) and opens a long position.

    So I am doing the following:

    if (State==State.DataLoaded)
    {
    _RSIAvgSeries = new Series<double>(this);
    }

    private void AddIndicators()
    {
    _RSI = RSI(Close,Convert.ToInt32(RSIperiod), RSISmoothPeriod);
    AddChartIndicator(_RSI);
    _RSIAvgSeries = RSI(Close, Convert.ToInt32(RSIperiod), RSISmoothPeriod).Avg;

    }

    private void SetEntrySignalState()
    {
    _enterLong = IsUpTrend();
    _enterShort = IsDownTrend();
    }

    private bool IsUpTrend()
    {
    return _RSIAvgSeries[0]> 50;
    }

    private bool IsDownTrend()
    {
    return _RSIAvgSeries[0] < 50;
    }


    protected override void OnBarUpdate()
    {
    SetEntrySignalState();


    if (_enterLong)
    {
    _longEntry = EnterLong(_posSize, LongEntry);
    }

    else if (_enterShort)
    {
    _shortEntry = EnterShort(_posSize, ShortEntry);
    }
    }

    I ran the strategy and I am not getting any long or short orders when the RSI is above 50. Furthermore I am trying to Print(_RSIAvgSeries[0]) to check the value of the RSI but the strategy does not give any results on the output window.

    Could you please help on this because I think I am confused with the logic.

    Thank you.

    #2
    Hello yannistsoupakis, thanks for writing in.

    Do you see any errors coming from the Log tab of the Control Center? If you don't see any messages from the strategy in the Control Center you will need to add Print methods on each line to see why it's not hitting the condition e.g.

    Code:
    //Add lines like this throughout the strategy and observe the output window.
    private bool IsUpTrend()
    {
    [B]Print(_RSIAvgSeries[0] + " " + Time[0]);[/B]
    [B]Print(_RSIAvgSeries[0] > 50);[/B]
    return _RSIAvgSeries[0]> 50;
    }
    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your response. Print works now but I get _RsiAvgSeries[0] = 0 in all dates.Obviously it should not do this. Do you have any idea on this error?

      Comment


        #4
        Hello, thanks for your reply.

        There is something wrong with either the initialization of RSI or when you are calling it. My test example is able to produce RSI values:

        Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.


        Please reference this example to fix the issue on your script.

        Please let me know if I can assist any further.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by rtwave, 06-13-2024, 12:10 AM
        8 responses
        92 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Started by samish18, Today, 03:48 AM
        6 responses
        13 views
        0 likes
        Last Post samish18  
        Started by cSharpGuy, Today, 04:56 AM
        5 responses
        33 views
        0 likes
        Last Post cSharpGuy  
        Started by DayTradingDEMON, 07-11-2024, 08:54 AM
        19 responses
        66 views
        0 likes
        Last Post DayTradingDEMON  
        Started by anp23, 02-09-2024, 04:40 PM
        4 responses
        711 views
        0 likes
        Last Post crosstrade  
        Working...
        X