Within the attached photo you will see that the strategy should have entered short at the begging of the blue line and exited at the end. My question is:
why in the world is this not working at coded? Is there a maximum number of if statements then it doesn't respond as well? It's as if it only reads 25% of my if-statements or something.
#region Variables
// Wizard generated variables
private int my_TakeProfit = 19; // Default setting for My_TakeProfit
// User defined variables (add any user defined variables below)
private int bars_Ago = 0;
private int ulte_Fast = 7;
private int ulte_Int = 14;
private int ulte_Slow = 28;
private int oB_Num = 78;
private int oS_Num = 26;
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
DefaultQuantity = 10000;
Add(UltimateOscillator(Ulte_Fast, Ulte_Int, Ulte_Slow));
SetStopLoss("", CalculationMode.Ticks, 200, false);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Short Section
#region Short
// If UO goes above OB_Num then Crosses below the OB_Num it will then finally enter short.
if ( UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow)[Bars_Ago] >= 75
&& CrossBelow(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), OB_Num, 1))
{
EnterShort(DefaultQuantity, "Shorting D1");
}
// If our position is open short and the market then goes back above the OB_Num we exit the position taking our loss as soon as possible.
else if ( Position.MarketPosition == MarketPosition.Short
&& CrossAbove(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), OB_Num, 1) )
{
ExitShort("", "Exiting D1 S");
}
else if ( Position.MarketPosition == MarketPosition.Short
&& UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow)[Bars_Ago] <= (OB_Num +1))
{
ExitShort("", "Exit Short Profit");
}
else if ( Position.MarketPosition == MarketPosition.Short
&& UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow)[Bars_Ago] <= 50 )
{
if ( CrossAbove(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), 40, 1) )
{
ExitShort("","Exit Short Profit");
}
}
#endregion
#region Long
else if( Position.MarketPosition == MarketPosition.Long
&& CrossAbove(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), OB_Num, 1) )
{
ExitLong("", "Exit Long Profit");
}
// OverSold Section
// If UO is lessthan or equal to OS_Num we proceed.
else if ( UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow)[Bars_Ago] <= (OS_Num +1) )
{
// If we are under oversold number then crossabove it we will then enter long
if ( CrossAbove(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), OS_Num, 1) )
{
EnterLong(DefaultQuantity, "Long D1");
}
}
// If position is == long and the UO falls below the oversold number we exit long position to take our loss.
else if ( Position.MarketPosition == MarketPosition.Long
&& CrossBelow(UltimateOscillator(ulte_Fast, ulte_Int, ulte_Slow), OS_Num, 1) )
{
ExitLong("", "Exiting D1 L");
}
#endregion
Comment