I'm having an issue with my strategy. It draws an arrow_up far from when it is supposed to draw it (Check pic 1, It should draw it where I put the blue arrow not on the rectangle).
So I investigated further with some prints and the script output I found something strange or at least I don't get it. My strategy prints values for bars even before the indicator (pic2)
For example i was expecting at 3:20 AM the Integer sentiment to be 1 but instead the strategy shows value = 2. And then The indicator shows the right value 1.
Since the strategy showed the value 1 at 4:40 that is why the arrow showed up late.
It has to do with the way a call the indicator or the whay I calculate (On each tick vs end of bar)?
here is the code where a call my indicator
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "VV";
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 = true;
Ratio = 1;
Surface = 1;
Hight = 1;
VolumeUp = 0;
VolumeDown = 0;
LongIn = false;
ShortIn = false;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
VolumeUpDown1 = VolumeUpDown(Close);
MAX1 = MAX(VolumeUpDown1.DownVolume, Convert.ToInt32(Surface));
MAX2 = MAX(VolumeUpDown1.UpVolume, Convert.ToInt32(Surface));
INPULSOR1 = INPULSOR(Close);
VolumeUpDown1.Plots[0].Brush = Brushes.DarkCyan;
VolumeUpDown1.Plots[1].Brush = Brushes.Crimson;
INPULSOR1.Plots[0].Brush = Brushes.Purple;
AddChartIndicator(VolumeUpDown1);
AddChartIndicator(INPULSOR1);
}
}
And then I use it like this.
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if ((Close[0] > Open[0])
&& (Volume[0] >= Hight)
&& (Volume[0] >= (MAX1[1] * Ratio) )
&& (Volume[0] >= (MAX2[1] * Ratio) )
&& (Times[0][0].TimeOfDay >= new TimeSpan(2, 0, 0))
&& (Times[0][0].TimeOfDay <= new TimeSpan(11, 0, 0))
&& (Close[0] > INPULSOR1[0])
&& (LongIn == false)
&& INPULSOR1.Sentiment == 1
)
{
Draw.ArrowUp(this, @"VV_Arrow up_1 " + Convert.ToString(CurrentBars[0]), false, 0, (Low[0] + (-4 * TickSize)) , Brushes.Blue);
VolumeUp = Convert.ToInt32(Volume[0]);
LongIn = true;
}
if (LongIn == true)
if (INPULSOR1.Sentiment == 2 || (VolumeUp * 1.5 <= Convert.ToInt32(Volume[0]) && Close[0] < Open[0] ) )
{
Draw.ArrowDown(this, @"VV_Arrow down_1 " + Convert.ToString(CurrentBars[0]), false, 0, (High[0] + (4 * TickSize)) , Brushes.Blue);
LongIn = false;
}
Comment