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

Indicator crossover count (please help)

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

    Indicator crossover count (please help)

    Hi
    I'm a newbie with ninjascript and with coding in general
    I'm trying to put some ideas into code

    I want the strategy to place the trade only for the first 2 retrace of price and stochastic
    after there is a crossover in the 2 ema's
    I know I'm doing something wrong

    Any ideas on how i can approach this?

    Code:
    private EMA EMA1;
    private SMA SMA1;
    private Stochastics Stochastics2;
    private bool firstretrace = false;
    private bool secondretrace= false;
    protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    FastEMA                    = 15;
                    SlowSMA                    = 50;
                    StokK                    = 5;
                    StokD                    = 3;
                    StokS                    = 2;
                }
    protected override void OnBarUpdate()
            {  
                if (CurrentBars[0] < 2 || CurrentBars[1] < 1)
                return;
                
                if ((CrossBelow(Stochastics2.K, 20, 1))
                    && (Close[0] < EMA1[0])
                    &&(EMA1[0] > SMA1[0]))
                    {
                        firstretrace = true;
                    }    
                if ((firstretrace == false)
                    && (Close[0] < EMA1[0])
                    && (CrossBelow(Stochastics2.K, 20, 1))
                    &&(EMA1[0] > SMA1[0]))
                    {
                        secondretrace = true;
                    }        
                  
                 // Long
                if ((CrossAbove(Stochastics2.K, Stochastics2.D, 1))
                    
                    //&& (EMA1[0] > SMA1[0])
                     && (firstretrace == true) || (secondretrace == true)
                    
                     && (Stochastics2.D[0] < 50)
                     && ((Stochastics2.K[1] < 20)
                     || (Stochastics2.D[2] < 20))
                              
                     && (Close[0] > SMA1[0]))
                    {
                    EnterLong(Convert.ToInt32(DefaultQuantity), @"Long");
                    firstretrace = false;
                    secondretrace= false;    
                    
                    }
                
                    
            }
    Click image for larger version

Name:	retrace.jpg
Views:	1
Size:	327.4 KB
ID:	908191

    #2
    Hello petrugio,

    Our support would not be able to generate the logic or code for you at your request, however, if you a specific question about a comparison or question about specific ways to use code I am happy to assist.

    This thread will remain open for any community members that would like to create the code for you as a convenience to you.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.

    From the code you have provided, it appears you are using bools to know that two events have happened. When you say this isn't working, what exactly is incorrect? Are the bools showing the wrong value when printed?
    Last edited by NinjaTrader_ChelseaB; 06-18-2017, 02:32 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by prdecast, Today, 06:07 AM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by Christopher_R, Today, 12:29 AM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by chartchart, 05-19-2021, 04:14 PM
    3 responses
    577 views
    1 like
    Last Post NinjaTrader_Gaby  
    Started by bsbisme, Yesterday, 02:08 PM
    1 response
    15 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by i019945nj, 12-14-2023, 06:41 AM
    3 responses
    60 views
    0 likes
    Last Post i019945nj  
    Working...
    X