I want to know when the Close price is great than the SMA(50). Here is the code I'm using to do it. I'm simply sending the info to the output window for now.
The output gives me the Close price and the SMA(50) value for each bar. It is then suppose to compare the values and tell me if Close is greater than SMA(50) (if Close is less than SMA(50), nothing should be printed in the Outpute Window).
Problem is, it tells me that Close is ALWAYS greater than SMA(50) even when the output of the variables clearly show cases when Close is less than SMA(50).
---> Code Snippet <---
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
double myCloseValue = Close[0];
double mySMA50Value = SMA(50)[0];
Print("The current Close value is " + myCloseValue.ToString());
Print("The current SMA 50 value is " + mySMA50Value.ToString());
// Condition set 1
if (myCloseValue > mySMA50Value);
{
Print("Close is > than SMA50");
}
}
---> End Code Snippet <---
---> Output Window Snippet (comments added for this post and do not appear in actual Output Window output <---
The current Close value is 1.5633
The current SMA 50 value is 1.563874
Close is > than SMA50 .................comment added - this is an error
The current Close value is 1.5565
The current SMA 50 value is 1.56362
Close is > than SMA50 .................comment added - this is an error
The current Close value is 1.5634
The current SMA 50 value is 1.563456
Close is > than SMA50
The current Close value is 1.5665
The current SMA 50 value is 1.563496
Close is > than SMA50
---> End Output Window Snippet <---
What am I doing wrong here?
Much thanks.
- Iggy
Comment