• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 dtl-saw, Today, 03:36 PM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Started by williamzz, Today, 02:04 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Started by jtrading82, Today, 01:55 PM
    3 responses
    24 views
    0 likes
    Last Post NinjaTrader_Tyler  
    Started by StevenNelson, Today, 01:00 PM
    4 responses
    19 views
    0 likes
    Last Post StevenNelson  
    Started by allinthechart, Today, 12:21 PM
    0 responses
    8 views
    0 likes
    Last Post allinthechart  
    Working...
    X