My question is how to program if then events that are "nested" so that if one condition (step 1) is true I then do step 2, and within step 2 are other conditions that if met do things. Like this sample of a multi time frame strategy:
{
if (BarsInProgress != 0)
return;
{
// Checks if the 5 period SMA is below the 15 period SMA on the 3, 8, 13, 60 minute time frames
if (SMA(BarsArray[1], sMA5)[0] < SMA(BarsArray[1], sMA15)[0] && SMA(BarsArray[2], sMA5)[0] < SMA(BarsArray[2], sMA15)[0] && SMA(BarsArray[3], sMA5)[0] < SMA(BarsArray[3], sMA15)[0] && SMA(BarsArray[4], sMA5)[0] < SMA(BarsArray[4], sMA15)[0])
{
// Checks for a cross below condition of the 5 and 15 period SMA on the primary Bars object and enters short
if (CrossBelow(Stochastics(PeriodD, PeriodK, Smooth).D, Stochastics(PeriodD, PeriodK, Smooth).K, 1)
&& Stochastics(PeriodD, PeriodK, Smooth).D[0] > TopLine)
EnterShort(sHAREposition1, "SHAREposition1signal");
}
}
{
if (SMA(BarsArray[2], sMA5)[0] < SMA(BarsArray[2], sMA15)[0] && SMA(BarsArray[3], sMA5)[0] < SMA(BarsArray[3], sMA15)[0] && SMA(BarsArray[4], sMA5)[0] < SMA(BarsArray[4], sMA15)[0])
// Checks for a cross below condition on the 3min Bars object and enters short
{
if (CrossBelow(Stochastics(BarsArray[1], PeriodD, PeriodK, Smooth).D, Stochastics(BarsArray[1],PeriodD, PeriodK, Smooth).K, 1)
&& Stochastics(BarsArray[1],PeriodD, PeriodK, Smooth).D[0] > TopLine)
EnterShort(sHAREposition2, "SHAREposition2signal");
}
}
// Checks for a cross above condition on the primary Bars object and exits short
if (CrossAbove(Stochastics(PeriodD, PeriodK, Smooth).K, Stochastics(PeriodD, PeriodK, Smooth).D, 1)
&& Stochastics(PeriodD, PeriodK, Smooth).D[0] < BottomLine)
ExitShort("SHAREposition1exit","SHAREposition1sign al");
// Checks for a cross above condition 3min Bars object and exits short
if (CrossAbove(Stochastics(BarsArray[1],PeriodD, PeriodK, Smooth).K, Stochastics(BarsArray[1],PeriodD, PeriodK, Smooth).D, 1)
&& Stochastics(BarsArray[1],PeriodD, PeriodK, Smooth).D[0] < BottomLine)
ExitShort("SHAREposition2exit","SHAREposition2sign al");
}
For instance, where I do this:
// Checks for a cross below condition of the 5 and 15 period SMA on the primary Bars object and enters short
if (CrossBelow(Stochastics(PeriodD, PeriodK, Smooth).D, Stochastics(PeriodD, PeriodK, Smooth).K, 1)
&& Stochastics(PeriodD, PeriodK, Smooth).D[0] > TopLine)
EnterShort(sHAREposition1, "SHAREposition1signal");
that will excecute when the higher level condition below is met:
// Checks if the 5 period SMA is below the 15 period SMA on the 3, 8, 13, 60 minute time frames
if (SMA(BarsArray[1], sMA5)[0] < SMA(BarsArray[1], sMA15)[0] && SMA(BarsArray[2], sMA5)[0] < SMA(BarsArray[2], sMA15)[0] && SMA(BarsArray[3], sMA5)[0] < SMA(BarsArray[3], sMA15)[0] && SMA(BarsArray[4], sMA5)[0] < SMA(BarsArray[4], sMA15)[0])
Ok, so my question is how many of these can I nest or have in some hiearchy? I notice in the Wizard I can have sets of conditions. With not using the wizard, can I have sets of conditions within conditions, like this
{
if (X<Z)
{ if (S<D) go short
{if (S<G) go short
}
}
}
What I would like is to filter down when sets of conditions are met, so that at some level certain trades can be taken, this would mean I could more or less run multiple entries and exits on the same stock as certain conditions are met or expire.
My apologies for this very long winded explanation. I am reading some tutorials and any links would be appreciated.
Comment