Profit Maximizer
"Profit Maximizer PMax" by KivancOzbilgic, MPL-2.0. Ported to FloScript by FloSignals; modifications under MPL-2.0. Original: Profit Maximizer PMax (v3.0), read 2026-10-12T16:05:30.077Z; source language v4.
Licence: Mozilla Public License 2.0 (MPL-2.0) — full text. The source is published with it, modifications included, under the same licence.
Profit Maximizer PMax by KivancOzbilgic, ported from Pine v4. Overlay indicator with 3 plots, 4 marker series, 2 fills, alerts and 11 inputs.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © KivancOzbilgic
//developer: @KivancOzbilgic
//author: @KivancOzbilgic
// ------------------------------------------------------------------------------------------------
// Original author: KivancOzbilgic
// Original title: Profit Maximizer PMax
// Licence: MPL-2.0 (the header above is the original notice, kept verbatim)
// Pine version: 4
// Fetched: 2026-10-12
// Ported to FloScript by FloSignals; modifications under MPL-2.0.
// Converter: @flosignals/floscript 0.1.0, strict mode, score 100/100
// ------------------------------------------------------------------------------------------------
//@floscript=1
//@version=5
// Converted by the FloScript converter from a Pine-compatible v4 source.
indicator("Profit Maximizer", "PMax", overlay=true, format=format.price, precision=2, timeframe="")
src = input(hl2, title="Source")
Periods = input.int(title="ATR Length", defval=10)
Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3.0)
mav = input.string(title="Moving Average Type", defval="EMA", options=["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"])
length = input.int(10, "Moving Average Length", minval=1)
changeATR = input.bool(title="Change ATR Calculation Method ?", defval=true)
Normalize = input.bool(title="Normalize ATR ?", defval=false)
showsupport = input.bool(title="Show Moving Average?", defval=true)
showsignalsk = input.bool(title="Show Crossing Signals?", defval=true)
showsignalsc = input.bool(title="Show Price/Pmax Crossing Signals?", defval=false)
highlighting = input.bool(title="Highlighter On/Off ?", defval=true)
atr2 = ta.sma(ta.tr, Periods)
atr = changeATR ? ta.atr(Periods) : atr2
valpha = 2 / (length + 1)
vud1 = src > src[1] ? src - src[1] : 0
vdd1 = src < src[1] ? src[1] - src : 0
vUD = math.sum(vud1, 9)
vDD = math.sum(vdd1, 9)
vCMO = nz((vUD - vDD) / (vUD + vDD))
VAR = 0.0
VAR := nz(valpha * math.abs(vCMO) * src) + (1 - valpha * math.abs(vCMO)) * nz(VAR[1])
wwalpha = 1 / length
WWMA = 0.0
WWMA := wwalpha * src + (1 - wwalpha) * nz(WWMA[1])
zxLag = length / 2 == math.round(length / 2) ? length / 2 : (length - 1) / 2
zxEMAData = src + (src - src[zxLag])
ZLEMA = ta.ema(zxEMAData, length)
lrc = ta.linreg(src, length, 0)
lrc1 = ta.linreg(src, length, 1)
lrs = lrc - lrc1
TSF = ta.linreg(src, length, 0) + lrs
getMA(src, length) =>
ma = 0.0
if mav == "SMA"
ma := ta.sma(src, length)
ma
if mav == "EMA"
ma := ta.ema(src, length)
ma
if mav == "WMA"
ma := ta.wma(src, length)
ma
if mav == "TMA"
ma := ta.sma(ta.sma(src, math.ceil(length / 2)), math.floor(length / 2) + 1)
ma
if mav == "VAR"
ma := VAR
ma
if mav == "WWMA"
ma := WWMA
ma
if mav == "ZLEMA"
ma := ZLEMA
ma
if mav == "TSF"
ma := TSF
ma
ma
MAvg = getMA(src, length)
longStop = Normalize ? MAvg - Multiplier * atr / close : MAvg - Multiplier * atr
longStopPrev = nz(longStop[1], longStop)
longStop := MAvg > longStopPrev ? math.max(longStop, longStopPrev) : longStop
shortStop = Normalize ? MAvg + Multiplier * atr / close : MAvg + Multiplier * atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := MAvg < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop
dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and MAvg > shortStopPrev ? 1 : dir == 1 and MAvg < longStopPrev ? -1 : dir
PMax = dir == 1 ? longStop : shortStop
plot(showsupport ? MAvg : na, color=#0585E1, linewidth=2, title="Moving Avg Line")
pALL = plot(PMax, color=color.new(color.red, 0), linewidth=2, title="PMax")
alertcondition(ta.cross(MAvg, PMax), title="Cross Alert", message="PMax - Moving Avg Crossing!")
alertcondition(ta.crossover(MAvg, PMax), title="Crossover Alarm", message="Moving Avg BUY SIGNAL!")
alertcondition(ta.crossunder(MAvg, PMax), title="Crossunder Alarm", message="Moving Avg SELL SIGNAL!")
alertcondition(ta.cross(src, PMax), title="Price Cross Alert", message="PMax - Price Crossing!")
alertcondition(ta.crossover(src, PMax), title="Price Crossover Alarm", message="PRICE OVER PMax - BUY SIGNAL!")
alertcondition(ta.crossunder(src, PMax), title="Price Crossunder Alarm", message="PRICE UNDER PMax - SELL SIGNAL!")
buySignalk = ta.crossover(MAvg, PMax)
plotshape(buySignalk and showsignalsk ? PMax * 0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.white)
sellSignallk = ta.crossunder(MAvg, PMax)
plotshape(sellSignallk and showsignalsk ? PMax * 1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)
buySignalc = ta.crossover(src, PMax)
plotshape(buySignalc and showsignalsc ? PMax * 0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(#0F18BF, 0), textcolor=color.white)
sellSignallc = ta.crossunder(src, PMax)
plotshape(sellSignallc and showsignalsc ? PMax * 1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(#0F18BF, 0), textcolor=color.white)
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0, display=display.none)
longFillColor = highlighting ? (MAvg > PMax ? color.green : na) : na
shortFillColor = highlighting ? (MAvg < PMax ? color.red : na) : na
fill(mPlot, pALL, title="UpTrend Highligter", color=longFillColor)
fill(mPlot, pALL, title="DownTrend Highligter", color=shortFillColor)
This file is under the Mozilla Public License 2.0; it is a port of the original by KivancOzbilgic, with the original licence header kept and the changes made for FloScript noted in the file.
- v2
Library refresh 2026-10-14
- v1
Library refresh 2026-10-12
Disclaimer. Scripts are written and published by members, or ported by FloSignals from open-source originals, and are their authors' own work and opinion. FloSignals does not review them for correctness and nothing in a script is financial advice or a recommendation to buy or sell anything — read the Risk Disclaimer. Posting here is under the Community Rules; a script that is not the poster's to post can be reported as the Copyright & Takedowns page says.

Comments (0)
No comments yet. Members can leave one.