// This indicator will return a value based on analyzing the $INDU
// It should be applied to the 60,30,10,5,3,1 minute $INDUs
// FlatPercentage is the percentage move we conside flat
// Not Included
// 1 - . Use the macci + 3 sma of it for crossover signals
// 2 - Look for turn of an indicator in the mid zone on the lower time frames.
Inputs : OBThreshold(100), OSThreshold(-100),CycleLength(6), Smoothing(5),
OBAlert(80), OSAlert(-80), FlatPercentage(5);
Vars : LoopCount(0), RTNVal(0), FlatAmt(0),ReturnCode(0), Action(" "),
Zone60("", data6),Zone30("", data5),Zone10("", data4),
Zone5("", data3), Zone3("", data2), Zone1("", data1),
Direction60("", data6), Direction30("", data5), Direction10("", data4),
Direction5("", data3), Direction3("", data2), Direction1("", data1),
Bias60(" "), Bias30(" "), Bias10(" "),Bias(" "),
Trigger5(" "), Trigger3(" "), Trigger1(" "),Trigger(""),
CycleHistory60(0, data6),CycleHistory30(0, data5),CycleHistory10(0, data4),
CycleHistory5(0, data3),CycleHistory3(0, data2),CycleHistory1(0,data1);
// If FlatAmt hasn't been calculated yet - do that now...
If FlatAmt = 0 then
FlatAmt = ((OBThreshold - OSThreshold) / 100) * FlatPercentage;
// Calculate the indicator for the timeframes
CycleHistory60 = TTCycle(CycleLength,Smoothing) data6;
CycleHistory30 = TTCycle(CycleLength,Smoothing) data5;
CycleHistory10 = TTCycle(CycleLength,Smoothing) data4;
CycleHistory5 = TTCycle(CycleLength,Smoothing) data3;
CycleHistory3 = TTCycle(CycleLength,Smoothing) data2;
CycleHistory1 = TTCycle(CycleLength,Smoothing) data1;
// Plot cycle 1 as this indicator is for the 1 minute
Plot1(CycleHistory1, "Cycle");
Plot2(OBThreshold,"OverBought");
Plot3(OSThreshold,"Oversold");
plot4(0,"Zero");
Plot5(OBAlert,"Alert");
Plot6(OSAlert,"Alert");
// Now that we have cycle history - we sl pass ihould call another function (TTDirection) that should tell us which way
// The indicator is going - we'ln the array & that function will tell us up, down, flat, etc
// That function can be improved over time
// Direction - Indicates direction
// + moving up
// - moving down
// F flat (should not indicate that it is perfecly flat but within a tolerance - say less than 10% angle)
Direction60 = TT_CYCLE_DIRECTION(FlatAmt, CycleHistory60);
Direction30 = TT_CYCLE_DIRECTION(FlatAmt, CycleHistory30);
Direction10 = TT_CYCLE_DIRECTION(FlatAmt, CycleHistory10);
Direction5 = TT_CYCLE_DIRECTION(FlatAmt, CycleHistory5);
Direction3 = TT_CYCLE_DIRECTION(FlatAmt, CycleHistory3);
Direction1 = TT_CYCLE_DIRECTION(FlatAmt, CycleHistory1);
// Now that we have direction, we can look to see if we are OB, OS (based on inputs above) as well as direction
// and set 2 global variables for the 60 macci as follows :
// Zone - Indicates where it is
// MD - Mid
// AB - in upper alert zone
// OB - Overbrought
// AS - in lower alert zone
// OS - Oversold
Zone60 = TT_CYCLE_AREA(OBThreshold, OSThreshold, OBAlert, OSAlert, CycleHistory60);
Zone30 = TT_CYCLE_AREA(OBThreshold, OSThreshold, OBAlert, OSAlert, CycleHistory30);
Zone10 = TT_CYCLE_AREA(OBThreshold, OSThreshold, OBAlert, OSAlert, CycleHistory10);
Zone5 = TT_CYCLE_AREA(OBThreshold, OSThreshold, OBAlert, OSAlert, CycleHistory5);
Zone3 = TT_CYCLE_AREA(OBThreshold, OSThreshold, OBAlert, OSAlert, CycleHistory3);
Zone1 = TT_CYCLE_AREA(OBThreshold, OSThreshold, OBAlert, OSAlert, CycleHistory1);
// calculate bias for higher timeframes
Bias60 = TT_CYCLE_BIAS(Zone60,Direction60);
Bias30 = TT_CYCLE_BIAS(Zone30,Direction30);
Bias10 = TT_CYCLE_BIAS(Zone10,Direction10);
If Bias10 = Bias60 or Bias10 = Bias30 then Bias = Bias10 else Bias = "None";
// calculate triggers for lower timeframes and determine trigger
Trigger5 = TT_CYCLE_TRIGGER(Zone5, Direction5);
Trigger3 = TT_CYCLE_TRIGGER(Zone3, Direction3);
Trigger1 = TT_CYCLE_TRIGGER(Zone1, Direction1);
If Trigger1 = Trigger5 or Trigger1 = Trigger3 then Trigger = Trigger1 else Bias = "None";
// determine action to take (if any)
Action = "None";
if Bias = "Short" and Trigger = "Short" then Action = "SellShort";
if Bias = "Long" and Trigger = "Long" then Action = "Buy";
if Action = "SellShort" then begin
// Plot1(Low);
Alert("Sell Short");
// ReturnCode = TT_GET_ARRAY;
end;
if Action = "Buy" then begin
// Plot2(High);
Alert("Go Long");
// ReturnCode = TT_GET_ARRAY;
end ;
// Print data
Print(FormatDate( "dd MMM yy", ElDateToDateTime( Date )), " ", FormatTime( "hh:mm", ElTimeToDateTime( Time )) , " Zone 60 = ", Zone60, ", Dir 60 = ", Direction60,
", Zone 30 = ", Zone30, ", Dir 30 = ", Direction30,
", Zone 10 = ", Zone10, ", Dir 10 = ", Direction10,
", Zone 5 = ", Zone5, ", Dir 5 = ", Direction5,
", Zone 3 = ", Zone3, ", Dir 3 = ", Direction3,
", Zone 1 = ", Zone1, ", Dir 1 = ", Direction1,
", Bias = ", Bias, ", Trigger = ", Trigger, ", Action = ", Action);
If Time <> Time[1] and (Action = "Buy" or Action = "SellShort") then begin
Print(" Cycles ", CycleHistory60, " ", CycleHistory30, " ", CycleHistory10,
" ", CycleHistory5, " ", CycleHistory3, " ", CycleHistory1);
end;
// For testing only - if this is the last bar on the chart - output the array
// Switch this off if running in real time
//if LastBarOnChart then
// ReturnCode = TT_GET_ARRAY;