-
Notifications
You must be signed in to change notification settings - Fork 54
GPT prompt template
Rafal W. edited this page Sep 21, 2024
·
6 revisions
You can create new EA31337 strategies using AI GPTs such as (ChatGPT, Claude, Copilot Grok and many more).
TBC
Develop a comprehensive MQL5 trading strategy using EA31337 Framework with the following specifications:
- Name of strategy: MA Cross
- Description: Strategy to utilize 2 MA indicators and trade on MA crossing.
- Which indicators to use: Use appropriate onces.
- When to open trades: When fast MA crosses the slow MA.
- When to close trades: When fast MA crosses back the slow MA.
- Profit take logic: Profit take should be 40 pips.
- Stop loss logic: Stop loss should be the value of slow MA.
Strategy main code structure:
- Main logic is written in single Stg_{Name}.mqh using strategy class.
- File should start with a comment with @file and @brief description of the strategy.
- Must define the following inputs (prefix each name with strategy name): `float LotSize, int SignalOpenMethod, float SignalOpenLevel, int SignalOpenFilterMethod, int SignalOpenFilterTime, int SignalOpenBoostMethod, int SignalCloseMethod, int SignalCloseFilter, float SignalCloseLevel, int PriceStopMethod, float PriceStopLevel, int TickFilterMethod, float MaxSpread, short Shift, float OrderCloseLoss, float OrderCloseProfit, int OrderCloseTime`
- Must define the following struct to initialize input values into structure (replace Name with strategy name): `struct Stg_Name_Params_Defaults : StgParams { Stg_Name_Params_Defaults() : StgParams(::Name_SignalOpenMethod, ::Name_SignalOpenFilterMethod, ::Name_SignalOpenLevel, ::Name_SignalOpenBoostMethod, ::Name_SignalCloseMethod, ::Name_SignalCloseFilter, ::Name_SignalCloseLevel, ::Name_PriceStopMethod, ::Name_PriceStopLevel, ::Name_TickFilterMethod, ::Name_MaxSpread, ::Name_Shift) { Set(STRAT_PARAM_LS, Name_LotSize); Set(STRAT_PARAM_OCL, Name_OrderCloseLoss); Set(STRAT_PARAM_OCP, Name_OrderCloseProfit); Set(STRAT_PARAM_OCT, Name_OrderCloseTime); Set(STRAT_PARAM_SOFT, Name_SignalOpenFilterTime); } };`
- Must define: `class Stg_{Name} : public Strategy { }`
- Must define public constructor: `Stg_{Name}(StgParams &_sparams, TradeParams &_tparams, ChartParams &_cparams, string _name = "") : Strategy(_sparams, _tparams, _cparams, _name) {}`
- Must define method: `bool SignalOpen(ENUM_ORDER_TYPE _cmd, int _method, float _level = 0.0f, int _shift = 0) {}` where _method is SignalOpenMethod, _level is SignalOpenLevel and _shift is Shift input params.
- Strategy's indicator if present, must be initialized by the following method (where `SName` is strategy name and `IName` is indicator short name; depending on indicator, adjust `_indi_params` arguments): `void OnInit() { IndiINameParams _indi_params(::SName_Indi_IName_Period, ::SName_Indi_IName_Applied_Price, ::SName_Indi_IName_Shift); _indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF)); SetIndicator(new Indi_IName(_indi_params)); }`
EA31337 Framework coding standards and rules (ignore during response):
- Avoid calling MQL5 builtin function, reference framework classes and their methods instead.
- Avoid global code outside of the class.
- Avoid using #include in strategy's .mqh, since includes are defined in .mq5.
- Code follows object-oriented programming (OOP).
- To load main strategy's indicator use `GetIndicator()` method.
- Use C++ comments: `//` for inline, `/* */` for class and methods.
- Use `INPUT` instead of `input` for user's input parameters.
- Use `INPUT_GROUP("Foo")` for input grouping.
Available Chart class methods:
- `int GetBarShift(datetime _time, bool _exact = false)` - returns the index of the bar based on the given time.
- `double GetHigh(uint _shift = 0)` - returns high price value for the given shifted bar in the current timeframe.
- `double GetHigh(ENUM_TIMEFRAMES _tf, uint _shift = 0)` - returns high price value for the given timeframe and shifted bar.
- `double GetLow(uint _shift = 0)` - returns low price value for the given shifted bar in the current timeframe.
- `double GetLow(ENUM_TIMEFRAMES _tf, uint _shift = 0)` - returns low price value for the given timeframe and shifted bar.
- `double GetPrice(ENUM_APPLIED_PRICE _ap, int _shift = 0)` - returns the current price for the given applied price and shifted bar.
- `int GetHighest(ENUM_TIMEFRAMES _tf, int type, int _count = WHOLE_ARRAY, int _start = 0)` - returns the shift of the max price value over number of periods for the given timeframe.
- `int GetHighest(int type, int _count = WHOLE_ARRAY, int _start = 0)` - returns the shift of the max price value over number of periods for the given timeframe.
- `long GetVolume(uint _shift = 0)` - returns tick volume value for the given shifted bar.
- `long GetVolume(ENUM_TIMEFRAMES _tf, uint _shift = 0)` - returns tick volume value for the given timeframe and shifted bar.
Available Indicator class methods:
- `bool IsDecreasing(int _rows = 1, int _mode = 0, int _shift = 0)` - returns true when indicator value decreased.
- `bool IsIncreasing(int _rows = 1, int _mode = 0, int _shift = 0)` - returns true when indicator value increased.
- `bool IsIncByPct(float _pct, int _mode = 0, int _shift = 0, int _count = 1, bool _hundreds = true)` - returns true when value increased by given percentage value.
- `bool IsDecByPct(float _pct, int _mode = 0, int _shift = 0, int _count = 1, bool _hundreds = true)` - returns true when value decreased by given percentage value.
- `BarOHLC GetOHLC(unsigned int _shift = 0)` - returns BarOHLC struct with OHLC price values.
Available Strategy class methods:
- `float PriceStop(ENUM_ORDER_TYPE _cmd, ENUM_ORDER_TYPE_VALUE _mode, int _method = 0, float _level = 0.0f, short _bars = 4)` - method to return current order stop values. Should return current stop loss value when _mode is ORDER_TYPE_SL, or profit take when _mode is ORDER_TYPE_TP.
- `bool SignalClose(ENUM_ORDER_TYPE _cmd, int _method = 0, float _level = 0.0f, int _shift = 0)` - method is called on strategy's closing signal. Should return true on closing signal for the existing orders.
- `bool SignalCloseFilter(ENUM_ORDER_TYPE _cmd, int _method = 0, int _shift = 0)` - method for additional closing filtering after SignalClose returns true. Should return true if trade should still be closed, otherwise false when closing should be prevented.
- `bool SignalOpen(ENUM_ORDER_TYPE _cmd, int _method = 0, float _level = 0.0f, int _shift = 0)` - method is called on strategy's opening signal. Should return true on opening signal.
- `bool SignalOpenFilterMethod(ENUM_ORDER_TYPE _cmd, int _method = 0)` - method for additional opening filtering after SignalOpen returns true. Should return true if trade should still be opened, otherwise false when opening should be prevented.
- `void OnOrderOpen(OrderParams &_oparams)` - method called before order is opened (e.g. to alter _oparams).
- `void OnPeriod(unsigned int _periods)` - method called on new time periods, example usage `if ((_periods & DATETIME_HOUR) != 0) { // New hour started. }`
Available indicators:
- AC, AD, ADX, ADXW, AMA, AO, ASI, ATR, Alligator, AppliedPrice, BWMFI, BWZT, Bands, BearsPower, BullsPower, CCI, CHO, CHV, DEMA, DeMarker, DetrandedPrice, Envelopes, Force, FractalAdaptiveMA, Fractals, Gator, HeikenAshi, Ichimoku, Killzones, MA, MACD, MFI, MassIndex, Momentum, OBV, OsMA, Pivot, PriceChannel, PriceFeeder, PriceVolumeTrend, RS, RSI, RVI, RateOfChange, SAR, StdDev, Stochastic, TEMA, TRIX, UltimateOscillator, VIDYA, VROC, Volumes, WPR, WilliamsAD, ZigZag
Code examples:
- Loading chart instance: `Chart *_chart = (Chart *)_indi;`
- Loading indicator instance: `Indi_IName *_indi = GetIndicator();`
- SignalOpen's signal conditions example: `switch (_cmd) { case ORDER_TYPE_BUY: _result &= BUY_CONDITION1; _result &= BUY_CONDITION2; break; case ORDER_TYPE_SELL: _result &= SELL_CONDITION1; _result &= SELL_CONDITION2; break; }`
- To load indicator value, use: `_indi[_shift][_mode]`.
- To load 2 indicators on OnInit() with different indexes: `void OnInit() { IndiIName1Params _iname1_params(::SName_Indi_IName1_Shift); _sve_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF)); SetIndicator(new Indi_IName1(_iname1_params), 0); IndiIName2Params _iname2_params(::SName_Indi_IName2_Shift); _tmat_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF)); SetIndicator(new Indi_IName2(_iname2_params), 1); }`, then can be loaded by `Indi_IName1 *_indi1 = GetIndicator(0); Indi_IName2 *_indi2 = GetIndicator(1);`
Your response should include:
- Key points (such as trading logic on signal open and close)
- MQL5 code implementing this strategy.
- Further suggestions on improvements.
- Your honest opinion about the strategy idea.
- Your internal thought-process on how good strategy may be.
Please write the code in a professional, clean clang format, following best practices for MQL5 development.