I have compiled and added my indicator to my chart but dont see any plot - trying to debug it using print statements to the output window yet dont see anything there either.. This is my first custom script....
Another question - when you recompile the indicator does the chart get automatically updated? or do you have to remove and add again?
Here are my variables
#region Variables:
// Wizard generated variables
private int length = 10; // Default setting for Length
private int length1 = 14; // Default setting for Length1
// User defined variables (add any user defined variables below)
private int Trend_flo =0;
private DataSeries PercentR; // Define a DataSeries variable
private int PerR =0;
private double StDev =0;
private int LastBar =0;
private DataSeries TrStop;
#endregion
Here is my initialize region:
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Trend"));
CalculateOnBarClose = true;
Overlay = false;
PriceTypeSupported = true;
}
Here is main code:
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
if(Time[0].Date != Time[1].Date)
{
Trend_flo =0;
Print("Trend_flo initial condition: "+ Trend_flo);
}
double StDev = StdDev(length1)[0];
//double PerR = PercentR(length);
double HH =0.0;
double Divisor = 0.0;
HH = MAX(High, length)[0];
Divisor = HH - MIN(Low, length)[0];
if (Divisor != 0)
PercentR.Set(100 - ( ( HH - Close[0] ) / Divisor ) * 100);
else
PercentR.Set(0.0);
if ((PercentR[0] >= 70) && (PercentR[1] < 70) && (Trend_flo < 1) && (Close[0] > TrStop[0]))
{
TrStop.Set(Low[0] - StDev*1.382);
Trend_flo = 1;
Print("Trend_flo Long: "+ Trend_flo);
LastBar = CurrentBar;
}
if ((PercentR[0] <= 30) && (PercentR[1] > 30) && (Trend_flo > -1) && (Close[0] < TrStop[0]))
{
TrStop.Set(High[0] + StDev*1.382);
Trend_flo = -1;
Print("Trend_flo Short: "+ Trend_flo);
LastBar = CurrentBar;
}
if (Trend_flo == 1)
{
if ((Open[0] <= TrStop[0]) | (High[0] <= TrStop[0]) | (Low[0] <= TrStop[0]) | (Close[0] <= TrStop[0]))
{
Trend_flo =0;
Print("End of Trend_flo Long: "+ Trend_flo);
}
else
{
if (LastBar < CurrentBar)
{
if (TrStop[0] == 0) TrStop.Set(Close[0]);
if (Close[0] > Close[1]) TrStop.Set(Low[0] - StDev * 1.382);
if (Low[0] - High[1] > StDev) TrStop.Set(Low[0] - StDev * 0.618);
if (TrStop[0] < TrStop[1]) TrStop.Set(TrStop[1]);
}
}
}
if (Trend_flo == -1)
{
if ((Open[0] >= TrStop[0]) | (High[0] >= TrStop[0]) | (Low[0] >= TrStop[0]) | (Close[0] >= TrStop[0]))
{
Trend_flo =0;
Print("End of Trend_flo Short: "+ Trend_flo);
}
else
{
if (LastBar < CurrentBar)
{
if (TrStop[0] == 0) TrStop.Set(Close[0]);
if (Close[0] < Close[1]) TrStop.Set(High[0] + StDev * 1.382);
if (Low[1] - High[0] > StDev) TrStop.Set(High[0] + StDev * 1.382);
if (TrStop[0] > TrStop[1]) TrStop.Set(TrStop[1]);
}
}
}
// Set the plot value
Trend.Set(Trend_flo);
//Trend.Set(1);
}
Comment