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 אמיתית, מחבר הסקריפט הזה פרסם אותו בקוד פתוח, כך שסוחרים יוכלו להבין ולאמת אותו. כל הכבוד למחבר! אתה יכול להשתמש בו בחינם, אבל השימוש החוזר בקוד זה בפרסום כפוף לכללי הבית. אתה יכול להכניס אותו למועדפים כדי להשתמש בו בגרף.
המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.