Zeal Terminal Open Zeal Terminal

Pine Script v5 · Strategy

FRAMA & CPMA Strategy [CSM]

A Pine Script v5 strategy built on Change (Signal). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade is one contract and pays no commission. 11 settings; defaults include FRAMA Source close, FRAMA Length 21 and Fractal Dimension 0.8.

Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.

Does FRAMA & CPMA Strategy [CSM] repaint?
No
No repainting patterns were found in the source.
Does FRAMA & CPMA Strategy [CSM] run in Pine Script v6?
Not tested
The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L5:C0: no source was supplied for the library 'chhagansinghmeena/BankNifty_CSM/3'. Libraries cannot be fetched from TradingView; supply the source in the 'libraries' option. No libraries were supplied.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download.
Does FRAMA & CPMA Strategy [CSM] use a stop loss?
Yes
strategy.exit sets a stop on line 92, 93.
Does FRAMA & CPMA Strategy [CSM] run in Zeal Terminal?
No
Not yet: it imports the library chhagansinghmeena/BankNifty_CSM/3, whose source is not available here, so it does not run here
Does not run in Zeal Terminal yetIt imports the library chhagansinghmeena/BankNifty_CSM/3, whose source is not available here, so it does not run here. The settings, logic and review below are read from the source, which does not need a run.

Review

What a careful reader of this script would point out, found by checking the source.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Requirements
FRAMA SourceclosesourceFRAMA
FRAMA Length21int · min 1 · max 200FRAMA
Fractal Dimension0.8float · min 0.1 · max 2.0FRAMA
CPMA Length21int · min 1 · max 200CPMA
Enable Engulfing Candle Filterfalseboolline 33
Stoploss/Target
Long Take Profit Amount10float · min 0.05 · step 0.05longTakeProfitPerc
Short Take Profit Amount10float · min 0.05 · step 0.05shortTakeProfitPerc
Trailing Take Profit Amount0.5float · min 0.01 · max 100 · step 0.01trailingTakeProfitPerc
Stop Loss100float · min 0 · max 10000 · step 5longStopLossprice shortStopLossprice
Backtesting
Start DateDate & time to begin trading fromtimestamp('01 Jan 2023 03:30 +0000')timeline 18
End DateDate & time to stop tradingtimestamp('1 Jan 2099 15:30 +0000')timeline 18

What it calculates

  • ChangeSignalisDifferentSignalType · line 38

Signal flow

How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

ohlc4ohlc4price datahlcc4hlcc4price datahlc3hlc3price datahl2hl2price datalowlowprice datahighhighprice dataclosecloseprice dataopenopenprice dataCPMA_lengthCPMA Lengthsetting · 21lengthFRAMA Lengthsetting · 21fracDimFractal Dimensionsetting · 0.8longTakeProfitLong Take Profit Amountsetting · 10shortTakeProfitShort Take Profit Amountsetting · 10trailingTakeProfitTrailing Take Profit Am…setting · 0.5LossstratAStop Losssetting · 100isDifferentSignalTypeChange→ isDifferentSignalTypeOpen, price, High, Low, HL2, HLC3, HLCC4, OHLC4Open · price +68 valuesCPMACPMAvalueFRAMAFRAMAvalueSignalSignalvaluelongTakeProfitPerclongTakeProfitPercvalueshortTakeProfitPercshortTakeProfitPercvaluetrailingTakeProfitPerctrailingTakeProfitPercvaluelongTrailingTakeProfitStepTickslongTrailingTakeProfitS…valueshortTrailingTakeProfitStepTicksshortTrailingTakeProfit…valuelongConditionlongConditionconditionshortConditionshortConditionconditionlongIsActivelongIsActiveconditionshortIsActiveshortIsActiveconditionlongStopLosspricelongStopLosspriceconditionlongTakeProfitPricelongTakeProfitPriceconditionshortStopLosspriceshortStopLosspriceconditionshortTakeProfitPriceshortTakeProfitPriceconditionentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryexit:Long TP/SLexit Long TP/SLstrategy.exitexit:Short TP/SLexit Short TP/SLstrategy.exitplot:25CPMAplotplot:26FRAMAplot

Order rules

OrderFires whenBy defaultLine
Open Long longwindow()On90
Open Short shortwindow()On91
Exit Long TP/SL stopwindow()On92
Exit Short TP/SL stopwindow()On93

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

No

No repainting patterns in the source.

The live replay needs a run, and this script does not run in Zeal Terminal yet; the answer comes from the checks on the source alone.

  • ClearHigher-timeframe data1 request.security call(s), none with lookahead on.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
  • ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.

The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.

Similar scripts

Indicators and strategies built from the same calculations.

ScriptSharesTypeNetTradesMax drawdown
Gap Absorption Strategy by noop42crossv5 strategyNo trades on this market
Galileo Galilei by armigoldmancrossv4 strategy+16.9%6142.2%

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

Not tested

The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L5:C0: no source was supplied for the library 'chhagansinghmeena/BankNifty_CSM/3'. Libraries cannot be fetched from TradingView; supply the source in the 'libraries' option. No libraries were supplied.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © chhagansinghmeena-//@version=5+//@version=6strategy("FRAMA & CPMA Strategy [CSM]", shorttitle = "CSM's => FRAMA + CPMA", overlay=true, margin_long=100, margin_short=100)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2No It imports the library chhagansinghmeena/BankNifty_CSM/3, whose source is not available here, so it does not run hereNot measured
PineTSNot testedNot testedNot measured

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.

Source

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © chhagansinghmeena//@version=5strategy("FRAMA & CPMA Strategy [CSM]", shorttitle = "CSM's => FRAMA + CPMA", overlay=true, margin_long=100, margin_short=100)import chhagansinghmeena/BankNifty_CSM/3 as CMsrc = input.source(title = "FRAMA Source", defval = close, group = "Requirements")length = input.int(title='FRAMA Length', defval=21, minval=1, maxval=200, group = "Requirements")fracDim = input.float(title='Fractal Dimension', defval=0.8, minval=0.1, maxval=2.0, group = "Requirements")CPMA_length = input.int(title='CPMA Length', defval=21, minval=1, maxval=200, group = "Requirements")enableEngulfingFilter = input.bool(title = "Enable Engulfing Candle Filter", defval = false, group = "Requirements")longTakeProfit = input.float(10, 'Long Take Profit Amount', minval=0.05, step=0.05,group = "Stoploss/Target") shortTakeProfit = input.float(10, 'Short Take Profit Amount', minval=0.05, step=0.05,group = "Stoploss/Target") trailingTakeProfit = input.float(0.5, 'Trailing Take Profit Amount', minval=0.01, maxval=100, step=0.01,group = "Stoploss/Target") LossstratA = input.float(defval=100, minval=0, maxval=10000, title="Stop Loss", step=5,group="Stoploss/Target")start = input.time(title='Start Date', defval=timestamp('01 Jan 2023 03:30 +0000'), group='Backtesting', tooltip='Date & time to begin trading from')finish = input.time(title='End Date', defval=timestamp('1 Jan 2099 15:30 +0000'), group='Backtesting', tooltip='Date & time to stop trading')window() =>    time >= start and time <= finish ? true : false// Get various price types[Open, price, High, Low , HL2, HLC3, HLCC4, OHLC4 ] = request.security(syminfo.tickerid, timeframe.period, [open, close, high, low, hl2, hlc3, hlcc4, ohlc4])//Get CPMA from LibraryCPMA = CM.CSM_CPMA(length = CPMA_length, price = price, HL2 = HL2, Open = Open , High = High, Low = Low, OHLC4 = OHLC4, HLC3 = HLC3, HLCC4 = HLCC4)//Get FRAMA from LibraryFRAMA = CM.frama_Calculation(src = src, length = length, mult = fracDim)plot(CPMA, color=color.orange, linewidth=2, title="CPMA")plot(FRAMA, color=color.blue, linewidth=2, title="FRAMA")// Detect bullish and bearish engulfing patternsbullishEngulfing = CM.candlepatternbullish()bearishEngulfing = CM.candlepatternbearish()longCondition = (ta.cross(close, FRAMA) and close > FRAMA) or (ta.cross(close, CPMA) and close > CPMA ) shortCondition = (ta.cross(close, FRAMA) and close < FRAMA) or (ta.cross(close, CPMA) and close < CPMA) Signal = 0if enableEngulfingFilter    longCondition := bullishEngulfing and (longCondition or ta.crossover(FRAMA, CPMA))    shortCondition := bearishEngulfing and (shortCondition or ta.crossunder(FRAMA, CPMA))else     Signal := longCondition  ? 1 : shortCondition  ? -1 : nz(Signal[1])    isDifferentSignalType = ta.change(Signal)      longCondition := longCondition and isDifferentSignalType    shortCondition := shortCondition and isDifferentSignalTypelongTakeProfitPerc = longTakeProfit/closeshortTakeProfitPerc = shortTakeProfit/closetrailingTakeProfitPerc =  trailingTakeProfit == 0.01 ? syminfo.mintick/close : trailingTakeProfit/close bool longIsActive = longCondition or strategy.position_size > 0bool shortIsActive = shortCondition or strategy.position_size < 0longIsActive := longCondition or strategy.position_size > 0shortIsActive := shortCondition or strategy.position_size < 0//Long Stop Loss addedfloat longStopLossprice = nalongStopLossprice := if longIsActive     if longCondition and not (strategy.opentrades.size(strategy.opentrades - 1) > 0)        low - LossstratA    else        nz(longStopLossprice[1], low - LossstratA)else    na //Long Take Profir Addedfloat longTakeProfitPrice = nalongTakeProfitPrice := if longIsActive     if longCondition and not (strategy.position_size > 0)        close * (1 + longTakeProfitPerc)    else        nz(longTakeProfitPrice[1], high * (1 - longTakeProfitPerc))else    na//Short StopLoss addedfloat shortStopLossprice = nashortStopLossprice := if shortIsActive     if shortCondition and not (strategy.position_size < 0)        high + LossstratA    else        nz(shortStopLossprice[1], high + LossstratA)else    na//Short Take profit addedfloat shortTakeProfitPrice = nashortTakeProfitPrice := if shortIsActive     if shortCondition and not (strategy.position_size < 0)        close * (1 - shortTakeProfitPerc)    else        nz(shortTakeProfitPrice[1], close * (1 - shortTakeProfitPrice))else    na float longTrailingTakeProfitStepTicks = longTakeProfitPrice * trailingTakeProfitPerc / syminfo.mintickfloat shortTrailingTakeProfitStepTicks = shortTakeProfitPrice * trailingTakeProfitPerc / syminfo.mintickif window()    switch        longCondition=> strategy.entry("Long",strategy.long)        shortCondition=> strategy.entry("Short", strategy.short)    strategy.exit(id = 'Long TP/SL', from_entry = 'Long', trail_price = longTakeProfitPrice , trail_offset = longTrailingTakeProfitStepTicks, stop = longStopLossprice)    strategy.exit(id = 'Short TP/SL', from_entry = 'Short', trail_price = shortTakeProfitPrice, trail_offset = shortTrailingTakeProfitStepTicks, stop = shortStopLossprice)