{
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