PineScript v4, forex trading robot based on the commonly used bullish / bearish pin-bar piercing the moving averages strategy.
I coded this robot to stress-test the PineScript v4 language to see how advanced it is, and whether I could port a forex trading strategy from MT4 to TradingView.
In my opinion, PineScript v4 is still not a professional coding language; for example you cannot use IF-statements to modify the contents of global variables; this makes complex robot behaviour difficult to implement. In addition, it is unclear if the programmer can use nested IF-ELSE, or nested FOR within IF.
The sequence of program execution is also unclear, and although complex order entry and exit appears to function properly, I am not completely comfortable with it.
Recommended Chart Settings:
Asset Class: Forex Time Frame: H1
Long Entry Conditions:
a) Moving Average up trend, fast crosses above slow b) Presence of a Bullish Pin Bar c) Pin Bar pierces either Moving Average d) Moving Averages must be sloping up, angle threshold (optional)
Short Entry Conditions:
a) Moving Average down trend, fast crosses below slow b) Presence of a Bearish Pin Bar c) Pin Bar pierces either Moving Average d) Moving Averages must be sloping down, angle threshold (optional)
Exit Conditions: a) Stoploss level is hit b) Takeprofit level is hit c) Moving Averages cross-back (optional)
Default Robot Settings:
Equity Risk (%): 3 //how much account balance to risk per trade Stop Loss (x*ATR, Float): 2.1 //stoploss = x * ATR, you can change x Risk : Reward (1 : x*SL, Float): 3.1 //takeprofit = x * stop_loss_distance, you can change x Fast MA (Period): 20 //fast moving average period Slow MA (Period): 50 //slow moving average period ATR (Period): 14 //average true range period Use MA Slope (Boolean): true //toggle the requirement of the moving average slope Bull Slope Angle (Deg): 1 //angle above which, moving average is considered to be sloping up Bear Slope Angle (Deg): -1 //angle below which, moving average is considered to be sloping down Exit When MA Re-Cross (Boolean): true //toggle, close trade if moving average crosses back Cancel Entry After X Bars (Period): 3 //cancel the order after x bars not triggered, you can change x
Backtest Results (2019 to 2020, H1, Default Settings):
To reduce the possibility of curve-fitting, this robot was backtested on 12 popular forex currencies, as shown above. The robot was profitable on 8 out of 12 currencies, breakeven on 1, and made a loss on 3.
The default robot settings could be over-fitting for the EUR, as we can see out-sized performance for the EUR pairs, with the exception of the EURGBP. We can see that GBPJPY made the largest loss, so these two pairs could be related.
Risk Warning:
This is a forex trading strategy that involves high risk of equity loss, and backtest performance will not equal future results. You agree to use this script at your own risk.
진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.