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 yertle, Yesterday, 08:38 AM
        7 responses
        28 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by bmartz, 03-12-2024, 06:12 AM
        2 responses
        20 views
        0 likes
        Last Post bmartz
        by bmartz
         
        Started by funk10101, Today, 12:02 AM
        0 responses
        4 views
        0 likes
        Last Post funk10101  
        Started by gravdigaz6, Yesterday, 11:40 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by MarianApalaghiei, Yesterday, 10:49 PM
        3 responses
        10 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X