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

Help programmazione

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

    Help programmazione

    Hello,
    I wrote a code for practice, below, says that to operate if the inclination is increasing dell'ADX:
    Long if the slope of the SMA is 9> inclination of SMA 25 and MACD> its 10 EMA
    Short if the slope of the SMA 9 is <than the SMA 25 and the MACD <10 of their EMA
    Pressing the F5 key tells me OK, but when I focus on the graph, not doing anything long or short.
    Why?
    Thank you.
    Ciao.
    Roberto
    #region Variables

    private double livello1 = 0;
    private double livello1B = 0;
    private double livello2 = 0;
    private double livello3 = 0;
    private int ave = 0;
    #endregion
    protected override void Initialize()
    {
    Add(ADX(30));
    Add(ADX(30));
    Add(SMA(9));
    Add(SMA(9));
    Add(SMA(20));
    Add(SMA(20));
    Add(MACD(10, 25, 9));
    Add(MACD(10, 25, 9));

    CalculateOnBarClose = true;
    }

    #region CalcoliValori
    private double Valore1()
    {
    return (ADX(30)[0]- ADX(30)[1])/ADX (30) [1];
    }
    private double Valore1B()
    {
    return (ADX(30)[1]- ADX(30)[2])/ADX (30) [2];
    }


    private double Valore2()
    {
    return (SMA(9)[0]-SMA(9)[1])/SMA(9)[1];
    }


    private double Valore3()
    {
    return (SMA(20)[0]-SMA(20)[1])/SMA(20)[1];
    }


    #endregion

    #region OrderRouting
    private void GestisciOrdini()
    {
    if (ADX(30)[0] != 0 && ADX(30)[1] != 0)

    Valore1();
    double livello1;

    if (ADX(30)[1] != 0 && ADX(30)[2] != 0)

    Valore1B();
    double livello1B;


    if (SMA(9)[1]!= 0 && SMA(9)[0] != 0)
    {
    Valore2();
    double livello2;
    }



    if (SMA(20)[1] != SMA(20)[0])
    {
    Valore3();
    double livello3;
    }


    }


    #endregion

    protected override void OnBarUpdate()
    {
    GestisciOrdini();


    if( livello1 > livello1B && livello2 > livello3 && MACD(10, 25, 9).Avg[0] >SMA(MACD(10, 25, 9).Avg, 14)[0])
    {
    EnterLong(1, "ingresso Long ADX");
    }


    if ( livello1 > livello1B && livello2 < livello3 && MACD(10, 25, 9).Avg[0] < SMA(MACD(10, 25, 9).Avg, 14)[0])
    {
    EnterShort(1, "ingresso short ADX");
    }



    if (Position.MarketPosition == MarketPosition.Long && MACD(10, 25, 9).Avg[0] < SMA(MACD(10, 25, 9).Avg, 14)[0])
    {
    ExitLong("uscita long", "");
    }


    if (Position.MarketPosition == MarketPosition.Short && MACD(10, 25, 9).Avg[0] > SMA(MACD(10, 25, 9).Avg, 14)[0])
    {
    ExitShort("uscita short", "");
    }
    }
    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public double Livello1
    {
    get { return livello1; }
    set { livello1 = Math.Max(100,value); }
    }
    [Description("")]
    [GridCategory("Parameters")]
    public double Livello1B
    {
    get { return livello1B; }
    set { livello1B = Math.Max(100,value); }
    }
    [Description("")]
    [GridCategory("Parameters")]
    public double Livello2
    {
    get { return livello2; }
    set { livello2 = Math.Max(100,value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public double Livello3
    {
    get { return livello3; }
    set { livello3 = Math.Max(100,value); }
    }
    [Description("")]
    [GridCategory("Parameters")]
    public int Ave
    {
    get { return ave; }
    set { ave = Math.Max(100,value); }
    }



    #endregion
    }
    }


    #2
    Hi Italy,

    Unfortunately, I cannot debug this for you.

    First, are you getting any errors in the Log while running the script?

    Ensure your condition are being met by placing Print()s in them.
    More info at - http://www.ninjatrader.com/support/f...ead.php?t=3418
    TimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Kaledus, Today, 01:29 PM
    0 responses
    3 views
    0 likes
    Last Post Kaledus
    by Kaledus
     
    Started by PaulMohn, Today, 12:36 PM
    1 response
    16 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by yertle, Yesterday, 08:38 AM
    8 responses
    36 views
    0 likes
    Last Post ryjoga
    by ryjoga
     
    Started by rdtdale, Today, 01:02 PM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by alifarahani, Today, 09:40 AM
    3 responses
    18 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X