incorrect correct
(A+B*C) (A+(B*C))
(A+B+D+E) (A+(B+(D+E)))
(-20>A) ((0-20)>A)
(A*-B) (A*(0-B))
(AnotB) (Aand(notB))
ABS(a-b) (abs(A-B))
Addition: (A+B)
Subtraction: (A-B)
Multiplication: (A*B)
Division: (A/B)
Absolut value: (absA)
Power of: (A^B)
Natural Logarithm: (logA)
Lowest value of Low of last x bars: (lotx)
Highest value of High of last x bars: (hotx)
Modulo, Remainder of a Division: (A%B)
Round: (rndA)
round to ceil: (ceiA)
Round to floor: (floA)
Round to next minimal tick: (mitA)
EMA of A of last 3 bars: (e03A)
EMA of A of last 7 bars: (e07A)
EMA of A of last 10 bars: (e10A)
EMA of A of last 20 bars: (e20A)
EMA of A of last 50 bars: (e50A)
Smaller then: (A<B)
Greater then: (A>B)
Equal to: (A==B)
Unequal to: (A!=B)
And: (AandB)
Or: (AorB)
Exclusive Or: (AxorB)
Not: (notA)
Past bar value: (A[x]) ,whereby x can be 1,2,3,...,barIndex-1
Bar time: (T)
Bar index: (I)
Opening Price of Bar: (O)
Highest Price of Bar: (H)
Lowest Price of Bar: (L)
Closing Price of Bar: (C)
Min tick value for the current symbol: (K)
Trade Volume: (V)
True Range: (R)
Is Money invested: (M) ,Long position: M=1,
Short position: M=-1,
No position: M=0
Doji: ((abs(O-C))<(10*K))and((H-L)>(100*K))
green Hammer: (((H-C)<(5000*K))and(((O-L)/2)>(abs(O-C)))
Up trend: (C>(e10H))
Down trend: (C<(e10L))
cool down 7 bars: ((any buy condition)and((e07(absM))==0))
possible Pivot High: (H==(hot30))and((C<L[1])or(O>C))
possible Pivot Low: (L==(lot30))and((C>H[1])or(O<C))
1) You need to know the name of the boolean (or integer) variable of your indicator which hold the desired signal. Lets say that this boolean variable is called BUY. If this BUY variable is not plotted on the chart you simply add the following code line at the end of your pine script.
For boolean (true/false) BUY variables use this:
And in case your script's BUY variable is an integer or float then use instate the following code line:
2) Probably the name of this BUY variable in your indicator is not BUY. Simply replace in the code line above the BUY with the name of your script's trade condition variable.
3) Do the same procedure for your SELL variable. Then save your changed Indicator script.
4) Then add the changed Indicator script from step before and this backtester script to the chart ...
5) and go to the settings of it. Choose under "Settings -> Input A" your Indicator. So in the example above choose <Stoch RSI: K>.
The form is usually: '<name of your indicator> : BUY'. Then you see something like Image 1
6) Decide about each trade logic for Go Long and Go Short. In this Example we use for GoLong if "Stoch RSI: K" is smaller then 20. The "Stoch RSI: K" we already loaded it in input A. So we set under Go Long (A<20) and set Enter Signal Delay to 0.
Now we setup Go Short if "Stoch RSI: K" is bigger then 80. So we set under Go Short A>80. Enter Signal Delay is already set.
7) For the Exit conditions you can choose (trailing) Stop loss or Take Profit or Exit by Indicator Signal. What ever comes first triggers the exit. If you like to use an EMA Indicator for the Exit by Indicator just load it in a free input slot B, D, E, F or use the inbuild EMA. For this example we use the inbuild EMA of the last 7 values of close. It is called by the following equation: (e07C). So to exit a long trade when the close price crossunder this EMA you have to type in Exit Long ((e07C)>C). For exit a short trade enter in Exit Short ((e07C)<C).
Input Signals: This are five input slots A, B, D, E & F which you can load up with your preferred Indicators.
Algebraic Equation for the Trade Signals: Here you setup the definitions for Go Long, Go Short, Ex Long & Ex Short. As shown in Image 3 you can combine the input slots A, B, D, E, F with predefined Variables O, H, L, C, T, I, V, K, M, R or any constant value with the in-build function in the instruction set.
Additionally, you have the option to delay entry and exit signals. This feature is particularly useful when trade signals exhibit noise and require smoothing.
You can also enable the script to perform alternating trading. In this mode, trades alternate sequentially—after a long trade, a short trade follows, and then another long trade, and so on.
As shown in Image 4, you can configure the script so that an "exit by signal" also acts as the next entry in the opposite trade direction. To enable this, check the option Exit = Enter Next and set the exit condition as the opposite of the entry condition. With this setting, only one occurrence of the signal is needed to trigger both the exit and the new entry, making the transition seamless.
Equation Tester: Each equation is assigned a checkmark and a color. Activate one like in Image 5 and the chart will highlight bars with a colored background where the corresponding equation result is greater than zero (interpreted as true). At the last bar, a label is displayed showing each equation’s result value. This feature allows you to build your equations and test sub-equations to ensure their results are correct.
Backtest Results: Check mark the List of Trades to see any single trade with their stats. If there are more trades than can fit in the list, you can scroll down by decreasing the Scroll value.
Timezone Adjustment: In case you wanna use an Chart-UTC that differs from the time scale you can activate Timezone Adjustment. Then you have to setup your location UTC correctly! The Exchange UTC will be set in most cases automatically. Known Exchanges include Amsterdam, Chicago, New_York, Los_Angeles, Calcutta, Colombo, Moscow, St_Petersburg, Tokyo, Shanghai, Hongkong, Berlin, London, Paris, Madrid. Only if you have other exchanges you need to setup it by hand.
Time Filter: You can set a Start time or deactivate it by leave it unhooked. The same with End Time and Duration Days. Duration Days can also count from End time in case you deactivate Start time.
Session Filter: Here, you can choose to activate trading on a weekly basis, specifying which days of the week trading is allowed and which are excluded. Additionally, you can configure trading on a daily basis, setting the start and end times for when trades are permitted. If activated, no new trades will be initiated outside the defined times and sessions.
Long & Short: Here you can enable Longs or Shorts or both trades.
TP & SL Settings: Take Profit 1&2 set the target prices of any trade in relation to the entry price. The TP1 exit a part of the position defined by the quantity value. Stop Loss set the price to step out when a trade goes the wrong direction. You can activate also a trailing SL.
Additionally, you can specify whether trades should be executed intrabar or at the bar's closing.
Hedging: The Hedging is basic as shown in the following Image 6 and serves as a catch if price moves fast in the wrong direction.
You can activate a hedging mechanism, which opens a trade in the opposite direction if the price moves x% against the entry price. If both the Stop Loss and Hedging are triggered within the same bar, the hedging action will always take precedence.
Invest Settings: Here, you can set the initial amount of cash to start with. The Quantity Percentage determines how much of the available cash is allocated to each trade, while the Fee Percentage specifies the trading fee applied to both opening and closing positions.
Webhooks: Here, you configure the License ID and the Comment. This is particularly useful if you plan to use multiple instances of the script, ensuring the webhooks target the correct positions. The Take Profit and Stop Loss values are displayed as prices.
الوصول إلى هذا النص مقيد للمستخدمين المصرح لهم من قبل المؤلف وعادة ما يكون الدفع مطلوباً. يمكنك إضافته إلى مفضلاتك، لكن لن تتمكن من استخدامه إلا بعد طلب الإذن والحصول عليه من مؤلفه. تواصل مع BerlinCode42 للحصول على مزيد من المعلومات، أو اتبع إرشادات المؤلف أدناه.
لا تقترح TradingView الدفع مقابل النصوص البرمجية واستخدامها حتى تثق بنسبة 100٪ في مؤلفها وتفهم كيفية عملها. في كثير من الحالات، يمكنك العثور على بديل جيد مفتوح المصدر مجانًا في نصوص مجتمع الخاصة بنا .