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

max value

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

    #16
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class MA1to3 : Strategy
    {
    private SMA SMA1;
    private SMA SMA2;
    private SMA SMA3;
    double Diffval;
    double val;
    double maxSma;
    double minSma;
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "MA1to3";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = false;
    Period1 = 1;
    Period2 = 1;
    Period3 = 1;
    Low_Length = 1;
    Low_Multi = 1;
    Range = 1;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    SMA1 =SMA(Typical, Convert.ToInt32(Period1));
    SMA2 =SMA(Typical, Convert.ToInt32(Period2));
    SMA3 =SMA(Typical, Convert.ToInt32(Period3));
    double val =SMA( Low,Convert.ToInt32(Low_Length))[0];

    SetProfitTarget("", CalculationMode.Percent, 2);
    SetStopLoss("", CalculationMode.Percent, 0.5, false);
    }
    }
    protected override void OnBarUpdate()
    {
    if (CurrentBar < 1)
    return;
    if (CurrentBar < BarsRequiredToTrade)
    return;


    double maxSma = Math.Max(SMA(Typical, Period1)[0], Math.Max(SMA(Typical, Period2)[0], SMA(Typical, Period3)[0]));
    double minSma = Math.Min(SMA(Typical, Period1)[0], Math.Min(SMA(Typical, Period2)[0], SMA(Typical, Period3)[0]));
    double Diffval= maxSma - minSma;

    if( (Convert.ToInt32(Close) < (Low_Multi * val)) && (Diffval <= Range) )
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");

    }
    else
    {
    EnterShort(Convert.ToInt32(DefaultQuantity),"");
    }
    }

    #region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(ResourceType = typeof(Custom.Resource),Name="Period1", Order=0, GroupName="Parameters")]
    public int Period1
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(ResourceType = typeof(Custom.Resource),Name="Period2", Order=1, GroupName="Parameters")]
    public int Period2
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(ResourceType = typeof(Custom.Resource),Name="Period3", Order=2, GroupName="Parameters")]
    public int Period3
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="Low_Length", Order=3, GroupName="Parameters")]
    public int Low_Length
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, double.MaxValue)]
    [Display(Name="Low_Multi", Order=4, GroupName="Parameters")]
    public double Low_Multi
    { get; set; }

    //[NinjaScriptProperty]
    //[Range(1, double.MaxValue)]
    //[Display(Name="Vol_Multi", Order=6, GroupName="Parameters")]
    //public double Vol_Multi
    //{ get; set; }

    //[NinjaScriptProperty]
    //[Range(1, int.MaxValue)]
    //[Display(Name="Adx_lv", Order=7, GroupName="Parameters")]
    //public int Adx_lv
    //{ get; set; }

    //[NinjaScriptProperty]
    //[Range(1, int.MaxValue)]
    //Display(Name="Adx_hv", Order=8, GroupName="Parameters")]
    //public int Adx_hv
    //{ get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="Range", Order=5, GroupName="Parameters")]
    public int Range
    { get; set; }

    /*[NinjaScriptProperty]
    [Range(1, double.MaxValue)]
    [Display(Name="Profit_target", Order=10, GroupName="Parameters")]
    public double Profit_target
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, double.MaxValue)]
    [Display(Name="Stop_loss", Order=11, GroupName="Parameters")]
    public double Stop_loss
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, double.MaxValue)]
    [Display(Name="TstopLoss", Order=12, GroupName="Parameters")]
    public double TstopLoss
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="Adx_length", Order=13, GroupName="Parameters")]
    public int Adx_length
    { get; set; }**/
    #endregion

    }
    }


    THIS IS MY WHOLE STRATEGY ITS COMPILE SUCCESSFULLY BUT I AM NOT GETTING ANY OUTPUT ON STRATEGY ANALYZER .PLEASE CHECK

    Comment


      #17
      namespace NinjaTrader.NinjaScript.Strategies
      {
      public class MA1to3 : Strategy
      {
      private SMA SMA1;
      private SMA SMA2;
      private SMA SMA3;
      double Diffval;
      double val;
      double maxSma;
      double minSma;
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Strategy here.";
      Name = "MA1to3";
      Calculate = Calculate.OnBarClose;
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.AllEntries;
      IsExitOnSessionCloseStrategy = true;
      ExitOnSessionCloseSeconds = 30;
      IsFillLimitOnTouch = false;
      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
      OrderFillResolution = OrderFillResolution.Standard;
      Slippage = 0;
      StartBehavior = StartBehavior.WaitUntilFlat;
      TimeInForce = TimeInForce.Gtc;
      TraceOrders = false;
      RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
      StopTargetHandling = StopTargetHandling.PerEntryExecution;
      BarsRequiredToTrade = 20;
      // Disable this property for performance gains in Strategy Analyzer optimizations
      // See the Help Guide for additional information
      IsInstantiatedOnEachOptimizationIteration = false;
      Period1 = 1;
      Period2 = 1;
      Period3 = 1;
      Low_Length = 1;
      Low_Multi = 1;
      Range = 1;
      }
      else if (State == State.Configure)
      {
      }
      else if (State == State.DataLoaded)
      {
      SMA1 =SMA(Typical, Convert.ToInt32(Period1));
      SMA2 =SMA(Typical, Convert.ToInt32(Period2));
      SMA3 =SMA(Typical, Convert.ToInt32(Period3));
      double val =SMA( Low,Convert.ToInt32(Low_Length))[0];

      SetProfitTarget("", CalculationMode.Percent, 2);
      SetStopLoss("", CalculationMode.Percent, 0.5, false);
      }
      }
      protected override void OnBarUpdate()
      {
      if (CurrentBar < 1)
      return;
      if (CurrentBar < BarsRequiredToTrade)
      return;


      double maxSma = Math.Max(SMA1(Typical, Priod1)[0], Math.Max(SMA2(Typical, Period2)[0], SMA3(Typical, Period3)[0]));
      double minSma = Math.Min(SMA1(Typical, Period1)[0], Math.Min(SMA2(Typical, Period2)[0], SMA3(Typical, Period3)[0]));
      double Diffval= maxSma - minSma;

      if( (Convert.ToInt32(Close) < (Low_Multi * val)) && (Diffval <= Range) )
      {
      EnterLong(Convert.ToInt32(DefaultQuantity), "");

      }
      else
      {
      EnterShort(Convert.ToInt32(DefaultQuantity),"");
      }
      }

      WHEN i write such type i got compile type error that rerror is
      the name 'SMA1' does not exist in the current context
      the name 'SMA2' does not exist in the current context
      the name 'SMA3' does not exist in the current context

      WHY , but i have already define SMA1 is as a SMA type then why i got such type of error please clarify my logic.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by wzgy0920, 04-20-2024, 06:09 PM
      2 responses
      26 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, 02-22-2024, 01:11 AM
      5 responses
      32 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, Yesterday, 09:53 PM
      2 responses
      49 views
      0 likes
      Last Post wzgy0920  
      Started by Kensonprib, 04-28-2021, 10:11 AM
      5 responses
      192 views
      0 likes
      Last Post Hasadafa  
      Started by GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,234 views
      0 likes
      Last Post xiinteractive  
      Working...
      X