#// Indicator forTOS
#// TMO (T)rue (M)omentum (O)scillator) MTF Special Scapler Version
#// TMO Scalper is a special custom version that was designed exclusively for lower time frame scalps (1-5min charts)
#// This version of the TMO Oscillator print the signals ONLY when the higher aggregation is aligned with the current (lower aggregation)
#// Created by L&L Capital
#indicator("TMO Scalper", shorttitle="TMO Scalper", overlay=false)
# Converted by Sam4Cok@Samer800 - 09/2024
declare lower;
input Timeframe1 = AggregationPeriod.MIN;
input Timeframe2 = AggregationPeriod.FIFTEEN_MIN;
input Timeframe3 = AggregationPeriod.THIRTY_MIN;
input tmoLength = 14; #,title = "Length", group = "Settings")
input calcLength = 5; #, title = "Calc Length", group = "Settings")
input smoothLength = 3; #, title = "Smooth Length", group = "Settings")
input offset = 2; #,title = "Signal Offset", group = "Signal Settings")
input obLevel = 9; #,title = "OB Extreme Threshold", group = "Signal Settings")
input osLevel = -9; #,title = "OS Extreme Threshold", group = "Signal Settings")
input ShowTMO1 = yes; #, title = "Show TMO 1", group = "True Momentum Oscillator 1")
input ShowTMO2 = yes; #, title = "Show TMO 2", group = "True Momentum Oscillator 2")
input ShowTMO3 = yes; #, title = "Show TMO 3", group = "True Momentum Oscillator 3")
input showSignal1 = yes; # title = "Show TMO 1 Signals", group = "True Momentum Oscillator 1 Signals")
input ShowTmoExt1 = no; # "Show TMO 1 Signals (Extremes Only)"
input showSignal2 = yes; # "Show TMO 2 Signals"
input ShowTmoExt2 = no; # "Show TMO 2 Signals (Extremes Only)"
def na = Double.NaN;
def last = IsNaN(close);
def current = GetAggregationPeriod();
def tf1 = Max(current, TimeFrame1);
def tf2 = Max(current, TimeFrame2);
def tf3 = Max(current, TimeFrame3);
#// TMO 1 Calculations
def data1 = fold i1=1 to tmolength with p1 do
if close(Period=tf1) > open(Period=tf1)[i1] then p1 + 1 else
if close(Period=tf1) < open(Period=tf1)[i1] then p1 - 1 else p1;
def EMA1 = ExpAverage(data1,calcLength);
def Main1 = ExpAverage(EMA1, smoothLength);
def Signal1 = ExpAverage(Main1, smoothLength);
#// TMO 2 Calculations
def data2 = fold i2=1 to tmolength with p2 do
if close(Period=tf2) > open(Period=tf2)[i2] then p2 + 1 else
if close(Period=tf2) < open(Period=tf2)[i2] then p2 - 1 else p2;
def EMA2 = ExpAverage(data2,calcLength);
def Main2 = ExpAverage(EMA2, smoothLength);
def Signal2 = ExpAverage(Main2, smoothLength);
#// TMO 3 Calculations
def data3 = fold i3=1 to tmolength with p3 do
if close(Period=tf3) > open(Period=tf3)[i3] then p3 + 1 else
if close(Period=tf3) < open(Period=tf3)[i3] then p3 - 1 else p3;
def EMA3 = ExpAverage(data3,calcLength);
def Main3 = ExpAverage(EMA3, smoothLength);
def Signal3 = ExpAverage(Main3, smoothLength);
#// TMO Scalper Signals
def mainln1 = (15 * Main1 /tmolength);
def signaln1 = (15 * Signal1 /tmolength);
def mainln2 = (15 * Main2 /tmolength);
def signaln2 = (15 * Signal2 /tmolength);
def mainln3 = (15 * Main3 /tmolength);
def signaln3 = (15 * Signal3 /tmolength);
def cross1Up = (mainln1 > signaln1) and (mainln1[1] <= signaln1[1]);
def cross1Dn = (signaln1 > mainln1) and (signaln1[1] <= mainln1[1]);
def cross2Up = (mainln2 > signaln2) and (mainln2[1] <= signaln2[1]);
def cross2Dn = (signaln2 > mainln2) and (signaln2[1] <= mainln2[1]);
def tmo1B = if showSignal1 and cross1Up and (mainln2 > signaln2) then (mainln1-offset) else na;
def tmo1S = if showSignal1 and cross1Dn and (mainln2 < signaln2) then (mainln1+offset) else na;
def tmo1ExtB = if ShowTmoExt1 and cross1Up and (mainln1 < oslevel) and (mainln2 > signaln2)
then (mainln1-offset) else na;
def tmo1ExtS = if ShowTmoExt1 and cross1Dn and (mainln1 > oblevel) and (mainln2 < signaln2)
then (mainln1+offset) else na;
def tmo2B = if showSignal2 and cross2Up and (mainln3 > signaln3) then (mainln2-offset) else na;
def tmo2S = if showSignal2 and cross2Dn and (mainln3 < signaln3) then (mainln2+offset) else na;
def tmo2ExtB = if ShowTmoExt2 and cross2Up and (mainln2 < oslevel) and (mainln3 > signaln3)
then (mainln2-offset) else na;
def tmo2ExtS = if ShowTmoExt2 and cross2Dn and (mainln2 > oblevel) and (mainln3 < signaln3)
then (mainln2+offset) else na;
plot tmo1Bull = tmo1B;
plot tmo1Bear = tmo1S;
plot tmo1ExtBull = tmo1ExtB;
plot tmo1ExtBear = tmo1ExtS;
plot tmo2Bull = tmo2B;
plot tmo2Bear = tmo2S;
plot tmo2ExtBull = tmo2ExtB;
plot tmo2ExtBear = tmo2ExtS;
tmo1Bull.SetDefaultColor(Color.GREEN);
tmo1Bear.SetDefaultColor(Color.RED);
tmo2Bull.SetDefaultColor(Color.CYAN);
tmo2Bear.SetDefaultColor(Color.MAGENTA);
tmo1Bull.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
tmo1Bear.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
tmo1ExtBull.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
tmo1ExtBear.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
tmo2Bull.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
tmo2Bear.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
tmo2ExtBull.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
tmo2ExtBear.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#--plots
def mainLine1 = if ShowTMO1 and !last then mainln1 else na; # "TMO 1 Main"
def signalLine1 = if ShowTMO1 and !last then signaln1 else na; # "TMO 1 Signal"
def mainLine2 = if ShowTMO2 and !last then mainln2 else na; # "TMO 1 Main"
def signalLine2 = if ShowTMO2 and !last then signaln2 else na; # "TMO 1 Signal"
def mainLine3 = if ShowTMO3 and !last then mainln3 else na; # "TMO 1 Main"
def signalLine3 = if ShowTMO3 and !last then signaln3 else na; # "TMO 1 Signal"
AddCloud(mainLine1, signalLine1, Color.GREEN, Color.RED, yes);
AddCloud(mainLine2, signalLine2, Color.CYAN, Color.MAGENTA, yes);
AddCloud(mainLine3, signalLine3, Color.WHITE, Color.YELLOW, yes);
#-- Levels
plot Extob = if last then na else 15;
def ob = if last then na else 10;
plot Extos = if last then na else -15;
def os = if last then na else -10;
Extob.SetDefaultColor(Color.RED);
Extos.SetDefaultColor(Color.GREEN);
AddCloud(Extob, ob, Color.DARK_RED);
AddCloud(os, Extos, Color.DARK_GREEN);
#-- END of CODE