Announcement

Collapse
No announcement yet.

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 CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      58 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      34 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      195 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      360 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      281 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X