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 NullPointStrategies, Today, 05:17 AM
    0 responses
    38 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    64 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    41 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X