TOP OPTIONS TRADER - Can someone convert this please?

BannonMan85

New member
Platform
  1. TradingView
Could someone convert this from tradingview to TOS?

Code:
// This source code is subject to the terms of John J. Smith, CEO of Top Options Traders Academy
// © TOP OPTIONS TRADERs ACADEMY

//@version=4
study("BUY CALLS/PUTS", overlay=true)

/// Pivots
leftbars = input(title="LeftBars", defval=9)
rightbars = input(title="Rightbars", defval=9)

ph = pivothigh(leftbars, rightbars)
pl = pivotlow(leftbars, rightbars)
/// BUY PUTS
hh = valuewhen(ph, ph, 0) > valuewhen(ph[1], ph[1], 0)
plotshape(hh, title="BUY PUTS", style=shape.labeldown, color=color.red, textcolor=color.white, location=location.abovebar, transp=10, text="BUY PUTS", offset=-rightbars, size=size.auto)


/// BUY CALLS
ll = valuewhen(pl[1], pl[1], 0) > valuewhen(pl, pl, 0)
plotshape(ll, title="BUY CALLS", style=shape.labelup, color=color.green, textcolor=color.white, location=location.belowbar, transp=10, text="BUY CALLS", offset=-rightbars, size=size.auto)
 

barbaros

Administrator
Staff member
We can but the signals on the chart are 9 bars late for this indicator. Due to the pivot functions used, they trigger 9 bars late and then offset back 9 bars.
 

barbaros

Administrator
Staff member
Thanks Barbaros, could you explain the issue with the offset being 9 bars?
Sure. I want the best for everyone, so here it goes.

I changed the script to show the real triggers without the offset, aka without being 9 bar lagging.
Code:
// This source code is subject to the terms of John J. Smith, CEO of Top Options Traders Academy
// © TOP OPTIONS TRADERs ACADEMY

//@version=4
study("BUY CALLS/PUTS", overlay=true)

/// Pivots
leftbars = input(title="LeftBars", defval=9)
rightbars = input(title="Rightbars", defval=9)

ph = pivothigh(leftbars, rightbars)
pl = pivotlow(leftbars, rightbars)
/// BUY PUTS
hh = valuewhen(ph, ph, 0) > valuewhen(ph[1], ph[1], 0)
plotshape(hh, title="BUY PUTS", style=shape.labeldown, color=color.red, textcolor=color.white, location=location.abovebar, transp=10, text="PUTS TRIG", size=size.auto)
plotshape(hh, title="BUY PUTS", style=shape.labeldown, color=color.red, textcolor=color.white, location=location.abovebar, transp=10, text="BUY PUTS", offset=-rightbars, size=size.auto)


/// BUY CALLS
ll = valuewhen(pl[1], pl[1], 0) > valuewhen(pl, pl, 0)
plotshape(ll, title="BUY CALLS", style=shape.labelup, color=color.green, textcolor=color.white, location=location.belowbar, transp=10, text="CALLS TRIG", size=size.auto)
plotshape(ll, title="BUY CALLS", style=shape.labelup, color=color.green, textcolor=color.white, location=location.belowbar, transp=10, text="BUY CALLS", offset=-rightbars, size=size.auto)

If you look at the original indicator after the chart finished painting, it looks pretty awesome, right? Who wouldn't want to get rich quick.
KkeL47x.png

However, the real triggers is where the "TRIG" labels are.
tJNwwDp.png


Let me explain...when we rewind the bars, the "buy put" disappears where we were going to get rich.
wvGWs2S.png


As we keep adding bars, then it appears after the fact. A lot of the moves will be over in choppy markets.
fJNKntk.png


We made sure we don't have any repainting in the B4 trading system...There are a lot of misguidance like this out there.
 
Sure. I want the best for everyone, so here it goes.

I changed the script to show the real triggers without the offset, aka without being 9 bar lagging.
Code:
// This source code is subject to the terms of John J. Smith, CEO of Top Options Traders Academy
// © TOP OPTIONS TRADERs ACADEMY

//@version=4
study("BUY CALLS/PUTS", overlay=true)

/// Pivots
leftbars = input(title="LeftBars", defval=9)
rightbars = input(title="Rightbars", defval=9)

ph = pivothigh(leftbars, rightbars)
pl = pivotlow(leftbars, rightbars)
/// BUY PUTS
hh = valuewhen(ph, ph, 0) > valuewhen(ph[1], ph[1], 0)
plotshape(hh, title="BUY PUTS", style=shape.labeldown, color=color.red, textcolor=color.white, location=location.abovebar, transp=10, text="PUTS TRIG", size=size.auto)
plotshape(hh, title="BUY PUTS", style=shape.labeldown, color=color.red, textcolor=color.white, location=location.abovebar, transp=10, text="BUY PUTS", offset=-rightbars, size=size.auto)


/// BUY CALLS
ll = valuewhen(pl[1], pl[1], 0) > valuewhen(pl, pl, 0)
plotshape(ll, title="BUY CALLS", style=shape.labelup, color=color.green, textcolor=color.white, location=location.belowbar, transp=10, text="CALLS TRIG", size=size.auto)
plotshape(ll, title="BUY CALLS", style=shape.labelup, color=color.green, textcolor=color.white, location=location.belowbar, transp=10, text="BUY CALLS", offset=-rightbars, size=size.auto)

If you look at the original indicator after the chart finished painting, it looks pretty awesome, right? Who wouldn't want to get rich quick.
KkeL47x.png

However, the real triggers is where the "TRIG" labels are.
tJNwwDp.png


Let me explain...when we rewind the bars, the "buy put" disappears where we were going to get rich.
wvGWs2S.png


As we keep adding bars, then it appears after the fact. A lot of the moves will be over in choppy markets.
fJNKntk.png


We made sure we don't have any repainting in the B4 trading system...There are a lot of misguidance like this out there.
I agree with you @barbaros .. keep up the good job!
 

barbaros

Administrator
Staff member
Thanks barbaros, can i get this for TOS? It looks like its still in pinescript
Here you go. As close as I can get it for now.
2Hz6jkV.png

Code:
# Converted for b4indicators.com
# Join us at: https://discord.gg/kD3pKE2CQd
# barbaros

declare upper;

input Length_Forward   = 9;
input Length_Backward  = 9;

def _BN  = BarNumber();     # current barnumber
def _NaN = Double.NaN;      # non-numeric values
def _H   = high;            # high price
def _L   = low;             # low price
def _C   = close;           # close price
def _O   = open;            # open price
def _LL  = Lowestall(_L);   # lowest _L price
def _HH  = highestall(_H);  # highest _H price

script FindPivots {
    input dat = high; # default data or study being evaluated
    input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
    input PF  = 1;    # default pivot forward period
    input PB  = 5;    # default pivot backward period

    ##############
    def _nan;    # used for non-number returns
    def _BN;     # the current barnumber 
    def _VStop;  # confirms that the lookforward period continues the pivot trend
    def _V;      # the Value at the actual pivot point
    def _VBar;   # the bar number at the pivot point
    def _PV;     # the previous pivot Value
    def _PVBar;  # the previous pivot bar number
    def _VDiff;  # the difference in values between last two pivot points
    def _VDist;  # the diffence in barnumbers between last two pivot points
    def _VSlope; # the Slope calculated using value and distance changes
    def _VPivot; # used for the pivot point connector line only
    ##############

    _BN  = BarNumber();
    _nan = Double.NaN;
    _VStop = 
        fold a = 1 to PF + 1 
        with b = 1 while b 
        do if HL > 0 then 
            dat > GetValue(dat, -a) else 
            dat < GetValue(dat, -a) ;
    if (HL > 0) {
        _V = if _BN > PB and dat == Highest(dat, PB) and _VStop 
            then dat else _nan;
    } else {
        _V = if _BN > PB and dat == Lowest(dat, PB) and _VStop 
            then dat else _nan;
    }
    ;
    _VBar   = if !IsNaN(_V) then _BN else _VBar[1];
    _PV     = if !IsNaN(_V) then GetValue(dat, _BN - _VBar[1]) else _PV[1];
    _PVBar  = if   _VBar != _VBar[1] 
            then _PVBar[1] else _VBar;
    _VDiff  = AbsValue(_V) - AbsValue(_PV);
    _VDist  = _BN - _PVBar;
    _VSlope = if _V > _PV  then 1 else 
              if _V < _PV  then -1 else 0;
    if (HL > 0) {
        _VPivot = _BN >= HighestAll(_PVBar);
    } else {
        _VPivot = _BN >= LowestAll(_PVBar);
    }
    ;    
    plot result = if !IsNaN(_V) and _VStop then _V else _nan; #return the final _dat value at the most recent pivot point (same as V)
}
;

def ph =  findpivots(_H, 1, length_forward, length_backward)."result";
def pl =  findpivots(_L, -1, length_forward, length_backward)."result";

def ph_1 = if !isnan(ph) then ph else ph_1[1];
def pl_1 = if !isnan(pl) then pl else pl_1[1];

def hh = !isnan(ph) and ph > ph_1[1];
def ll = !isnan(pl) and pl < pl_1[1];

addchartbubble(ll, pl, "BUY CALLS", color.green, no); 
addchartbubble(hh, ph, "BUY PUTS", color.red, yes);
 
Here you go. As close as I can get it for now.
2Hz6jkV.png

Code:
# Converted for b4indicators.com
# Join us at: https://discord.gg/kD3pKE2CQd
# barbaros

declare upper;

input Length_Forward   = 9;
input Length_Backward  = 9;

def _BN  = BarNumber();     # current barnumber
def _NaN = Double.NaN;      # non-numeric values
def _H   = high;            # high price
def _L   = low;             # low price
def _C   = close;           # close price
def _O   = open;            # open price
def _LL  = Lowestall(_L);   # lowest _L price
def _HH  = highestall(_H);  # highest _H price

script FindPivots {
    input dat = high; # default data or study being evaluated
    input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
    input PF  = 1;    # default pivot forward period
    input PB  = 5;    # default pivot backward period

    ##############
    def _nan;    # used for non-number returns
    def _BN;     # the current barnumber
    def _VStop;  # confirms that the lookforward period continues the pivot trend
    def _V;      # the Value at the actual pivot point
    def _VBar;   # the bar number at the pivot point
    def _PV;     # the previous pivot Value
    def _PVBar;  # the previous pivot bar number
    def _VDiff;  # the difference in values between last two pivot points
    def _VDist;  # the diffence in barnumbers between last two pivot points
    def _VSlope; # the Slope calculated using value and distance changes
    def _VPivot; # used for the pivot point connector line only
    ##############

    _BN  = BarNumber();
    _nan = Double.NaN;
    _VStop =
        fold a = 1 to PF + 1
        with b = 1 while b
        do if HL > 0 then
            dat > GetValue(dat, -a) else
            dat < GetValue(dat, -a) ;
    if (HL > 0) {
        _V = if _BN > PB and dat == Highest(dat, PB) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > PB and dat == Lowest(dat, PB) and _VStop
            then dat else _nan;
    }
    ;
    _VBar   = if !IsNaN(_V) then _BN else _VBar[1];
    _PV     = if !IsNaN(_V) then GetValue(dat, _BN - _VBar[1]) else _PV[1];
    _PVBar  = if   _VBar != _VBar[1]
            then _PVBar[1] else _VBar;
    _VDiff  = AbsValue(_V) - AbsValue(_PV);
    _VDist  = _BN - _PVBar;
    _VSlope = if _V > _PV  then 1 else
              if _V < _PV  then -1 else 0;
    if (HL > 0) {
        _VPivot = _BN >= HighestAll(_PVBar);
    } else {
        _VPivot = _BN >= LowestAll(_PVBar);
    }
    ;   
    plot result = if !IsNaN(_V) and _VStop then _V else _nan; #return the final _dat value at the most recent pivot point (same as V)
}
;

def ph =  findpivots(_H, 1, length_forward, length_backward)."result";
def pl =  findpivots(_L, -1, length_forward, length_backward)."result";

def ph_1 = if !isnan(ph) then ph else ph_1[1];
def pl_1 = if !isnan(pl) then pl else pl_1[1];

def hh = !isnan(ph) and ph > ph_1[1];
def ll = !isnan(pl) and pl < pl_1[1];

addchartbubble(ll, pl, "BUY CALLS", color.green, no);
addchartbubble(hh, ph, "BUY PUTS", color.red, yes);
Great job like always @barbaros ! thank you some much for help everyone here
 

BannonMan85

New member
Barbaros, you are an absolutely amazing human being, I appreciate this. I will tell you this, I actually got it from a guy who I was following on twitter and a bunch of people were wanting it to be converted to TOS, so I immediately thought of you and asked the author if I could bring it to you, he agreed and I sent him what you made and he loves it and I think he said he is going to try and get in contact with you and he said he will definitely let everyone know that you are the one that did the conversion. Thanks once again
 

barbaros

Administrator
Staff member
Barbaros, you are an absolutely amazing human being, I appreciate this. I will tell you this, I actually got it from a guy who I was following on twitter and a bunch of people were wanting it to be converted to TOS, so I immediately thought of you and asked the author if I could bring it to you, he agreed and I sent him what you made and he loves it and I think he said he is going to try and get in contact with you and he said he will definitely let everyone know that you are the one that did the conversion. Thanks once again
Sounds good. I appreciate it. I operate by "treat everyone the way you want to be treated".
 

barbaros

Administrator
Staff member
Unfortunately, this won’t be possible @lovetotrade. It is based on fractals and you need bars on each side of the peak to identify the fractal. However, it is doing higher high and lower low before it prints, so you might be able anticipate.
 
Top