Help to Create a simple RSI Strategy
2件の返信
Greetings. I come from a Wealthlab background with building blocks, but I am trying to raise the bar and learn and use what StrategyQuant has to offer. I really have read and studied a lot before asking for help. Perhaps a simple tutorial to create a single strategy from scratch, for only one asset, could help newbies with not a lot of experience such as myself. That said, I think by biggest struggle is to build a strategy with only one entry condition e 3 possible exit conditions.
Timeframe: H1
Instruments: a set of US Stocks I have downloaded M1 data
Direction: Long only
Lot size: 1
Only one trade at a time per equity.
ENTRY CONDITION (buy): Price of candle close is below oversold level (range: 5 to 50) of RSI period (range 2 to 10)
EXIT CONDITION 1: Price of candle close is above a SMA period (range: 2 to 30)
EXIT CONDITION 2: Profit target % (range 0.2 to 8) – here no profit target often times generates better results. Can be excluded from the exits to facilitate.
EXIT CONDITION 3: Close position after a number of bars (range: 1 to 30)
Whatever occurs first on exit conditions 1 and 2 closes the trade. Exit condition 3 occurs when 1 and 2 are not met.
I do not want to generate multiple strategies with these rules. I am interested in optimizing each parameter for each stock.
Doubt: in case the last candle of the day closes above the customized SMA the exit will occur on the first candle closed on the following day? This can be good or bad depending on gaps and other vairables. The way to avoid this would be restricting the trading hour to end an hour before the end of the session?
I am including the buiding block I came up with, which is obviously wrong.
Any kind of help is more than welcome.
よろしくお願いいたします。,
Leonardo
0
テオ・ゴットヴァルト
2年前 #287720
Sure, I can help you get started with StrategyQuant to create a single strategy from scratch. Let’s break down your requirements and create a simple strategy step-by-step.
### Step-by-Step Guide to Create a Strategy in StrategyQuant
#### 1. Setting Up the Environment
– **Timeframe:** H1
– **Instruments:** US Stocks (M1 data)
– **Direction:** Long only
– **Lot size:** 1
– **Maximum open trades:** 1 per equity
#### 2. Entry Condition
– **Buy:** Price of candle close is below oversold level (range: 5 to 50) of RSI period (range 2 to 10)
#### 3. Exit Conditions
1. **Exit Condition 1:** Price of candle close is above a SMA period (range: 2 to 30)
2. **Exit Condition 2:** Profit target % (range 0.2 to 8)
3. **Exit Condition 3:** Close position after a number of bars (range: 1 to 30)
#### 4. Optimization
– Optimize each parameter for each stock.
### Building the Strategy in StrategyQuant
#### Step 1: Create a New Strategy
1. Open StrategyQuant.
2. Go to File > New Strategy.
3. Name your strategy and select the appropriate settings (e.g., timeframe, instrument).
#### Step 2: Define the Entry Condition
1. In the 戦略 tab, click on Add Block > 指標.
2. Select RSI and set the period range (2 to 10).
3. Click on Add Block > Condition.
4. Set the condition to Close < RSI(Period) and set the oversold level range (5 to 50).
#### Step 3: Define the Exit Conditions
1. **Exit Condition 1:**
– Click on Add Block > 指標.
– Select SMA and set the period range (2 to 30).
– Click on Add Block > Condition.
– Set the condition to Close > SMA(Period).
2. **Exit Condition 2:**
– Click on Add Block > Condition.
– Set the condition to Profit > Target % and set the range (0.2 to 8).
3. **Exit Condition 3:**
– Click on Add Block > Condition.
– Set the condition to Bars Since Entry > Number of Bars and set the range (1 to 30).
#### Step 4: Combine Exit Conditions
1. Use the Or block to combine Exit Condition 1 and Exit Condition 2.
2. Use the そして block to combine the result of the Or block with Exit Condition 3.
#### Step 5: Optimize Parameters
1. Go to the オプティマイザー tab.
2. Select the parameters you want to optimize (RSI period, oversold level, SMA period, profit target, number of bars).
3. Set the optimization range for each parameter.
4. Run the optimization.
### Addressing Your Doubt
Regarding the exit condition occurring on the first candle of the following day, you can indeed restrict the trading hours to end an hour before the session ends. This can be done by adding a time filter to your strategy.
#### Adding a Time Filter
1. Click on Add Block > Condition.
2. Set the condition to Time > Start Time そして Time < End Time.
3. Adjust the start and end times to restrict trading to the desired hours.
### Example Building Block
Here’s a simplified example of how your building block might look:
`plaintext
Entry Condition:
– RSI(Period) < Oversold Level
Exit Conditions:
– Close > SMA(Period) OR Profit > Target %
– AND Bars Since Entry > Number of Bars
`
### Final Thoughts
– Make sure to test your strategy thoroughly with backtesting and forward testing.
– Consider adding risk management rules to protect your trades.
– Optimize parameters for each stock individually to find the best settings.
If you have any specific questions or run into issues, feel free to ask! Good luck with your strategy development in StrategyQuant.
[Used Mistral Large]
敬具
テオ・ゴットヴァルト
SPRおよびビジュアルオートメーションのトップエキスパート
???? **Q4アップデートの新機能**
1️⃣ Open AI Vision: 最先端の画像認識でSPRを強化。目に見えないものを見る。????????
2️⃣ Open AI TTS: テキストを自然でリアルな音声にシームレスに変換します。違いを聞いてみてください。 ????️????
3️⃣ OpenAIの128kトークンコンテキストウィンドウ搭載GPT-4:AIとの対話で比類なき深みを体験しよう。より深く思考する。????????
4️⃣ OpenAIのDALLE-3:革命的なAIに命令して、息をのむような画像を生成させましょう。想像のその先へ。????️????
5️⃣ ElevenLabs テキスト読み上げ:まるで人間が話しているかのような、リアルな音声合成を体験してください。????️
6️⃣ Automatic1111によるStable Diffusionのローカル&オンライン利用:ローカルとクラウドの両方の画像生成で創造性を解き放ちます。いつでもどこでも作成可能。☁️✨
7️⃣ GPT4All & LM Studio: 強力なオフラインAI機能を活用。あなたのスタジオを、もっと賢く。????️????
8️⃣ DeepL翻訳(SPR統合):リアルタイムで正確な翻訳を実現。世界の言葉を話そう。????????
9️⃣ OpenAIのChatGPT:自然でダイナミックな会話を通じてSPRとエンゲージメントを図りましょう。心からのつながりを築きましょう。 ????️
???? WHISPER by OpenAI: Convert voice to text with effortless precision. Listen, transcribe, act. ????️????
Mistral AI:シームレスな効率性でAI統合をスケール。AIの歩みを次のレベルへ。
AnthropicのClaude 3:次世代のAIの理解力とインタラクティビティを体験してください。人間らしい温かみを持つAIを発見しましょう。
???? **住所:**
ドイツ、デッテンハイム、ヘーレン通り 11
???? **電話:**
オフィス: +49 (7247) 9851112
Mobile: +49 160 6688 222
Fax: +49 (7247) 9851113
???? **メール:**
[[email protected]](mailto:[email protected])
???? **ウェブサイト:**
[IT-Berater](http://www.it-berater.org) | [Smart Package](http://www.smart-package.com)
0
テオ・ゴットヴァルト
2年前 #287721
Outsided of SQX it would look a bit like this ….
コード
//+——————————————————————+
//| Leonardo.mq5 |
//| Copyright 2024, Theo Gottwald |
//| https://www.fa2.de |
//+——————————————————————+
#property copyright “Copyright 2024, Theo Gottwald”
#property link “https://www.fa2.de”
#property version “1.00”
//+——————————————————————+
//| MyStrategy.mq5 |
//| Generated by Leonardo |
//+——————————————————————+
#property strict
#include <Trade/Trade.mqh>
CTrade trade;
// Input parameters
input int RSI_Period = 5; // RSI Period
input int RSI_Oversold = 30; // RSI Oversold Level
input int SMA_Period = 10; // SMA Period
input double Profit_Target = 0.02; // Profit Target in %
input int Bars_To_Exit = 10; // Number of bars to exit
input double Lot_Size = 0.1; // Lot size for the trade
// Global variables
datetime entryTime;
//+——————————————————————+
//| Expert initialization function |
//+——————————————————————+
int OnInit()
{
// Initialization code
return(INIT_SUCCEEDED);
}
//+——————————————————————+
//| Expert deinitialization function |
//+——————————————————————+
void OnDeinit(const int reason)
{
// Deinitialization code
}
//+——————————————————————+
//| Expert tick function |
//+——————————————————————+
void OnTick()
{
// Check if there is an open position on the current symbol
if (PositionSelect(_Symbol) == false)
{
// Entry condition: RSI below oversold level
double rsi = iRSI(_Symbol, PERIOD_CURRENT, RSI_Period, PRICE_CLOSE);
if (rsi < RSI_Oversold)
{
// Open a long position
if (trade.Buy(Lot_Size, NULL, 0, 0, 0, “MyStrategy”))
{
entryTime = TimeCurrent();
Print(“Opened BUY position at price: “, SymbolInfoDouble(_Symbol, SYMBOL_ASK));
}
その他
{
Print(“Error opening position: “, GetLastError());
}
}
}
その他
{
// Exit conditions
// Retrieve position details
double entryPrice = PositionGetDouble(POSITION_PRICE_OPEN);
double currentPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double profit = (currentPrice – entryPrice) / entryPrice * 100;
// Calculate the number of bars since entry
int entryBar = iBarShift(_Symbol, PERIOD_CURRENT, entryTime, true);
int barsSinceEntry = Bars(_Symbol, PERIOD_CURRENT) – entryBar;
// Calculate SMA
double sma = iMA(_Symbol, PERIOD_CURRENT, SMA_Period, 0, MODE_SMA, PRICE_CLOSE);
// Get the latest close price
double closePrice = iClose(_Symbol, PERIOD_CURRENT, 0);
if (closePrice > sma || profit >= Profit_Target || barsSinceEntry >= Bars_To_Exit)
{
// Close the position
if (trade.PositionClose(_Symbol))
{
Print(“Closed position on symbol: “, _Symbol);
}
その他
{
Print(“Error closing position: “, GetLastError());
}
}
}
}
//+——————————————————————+
[Untested]
敬具
テオ・ゴットヴァルト
SPRおよびビジュアルオートメーションのトップエキスパート
???? **Q4アップデートの新機能**
1️⃣ Open AI Vision: 最先端の画像認識でSPRを強化。目に見えないものを見る。????????
2️⃣ Open AI TTS: テキストを自然でリアルな音声にシームレスに変換します。違いを聞いてみてください。 ????️????
3️⃣ OpenAIの128kトークンコンテキストウィンドウ搭載GPT-4:AIとの対話で比類なき深みを体験しよう。より深く思考する。????????
4️⃣ OpenAIのDALLE-3:革命的なAIに命令して、息をのむような画像を生成させましょう。想像のその先へ。????️????
5️⃣ ElevenLabs テキスト読み上げ:まるで人間が話しているかのような、リアルな音声合成を体験してください。????️
6️⃣ Automatic1111によるStable Diffusionのローカル&オンライン利用:ローカルとクラウドの両方の画像生成で創造性を解き放ちます。いつでもどこでも作成可能。☁️✨
7️⃣ GPT4All & LM Studio: 強力なオフラインAI機能を活用。あなたのスタジオを、もっと賢く。????️????
8️⃣ DeepL翻訳(SPR統合):リアルタイムで正確な翻訳を実現。世界の言葉を話そう。????????
9️⃣ OpenAIのChatGPT:自然でダイナミックな会話を通じてSPRとエンゲージメントを図りましょう。心からのつながりを築きましょう。 ????️
???? WHISPER by OpenAI: Convert voice to text with effortless precision. Listen, transcribe, act. ????️????
Mistral AI:シームレスな効率性でAI統合をスケール。AIの歩みを次のレベルへ。
AnthropicのClaude 3:次世代のAIの理解力とインタラクティビティを体験してください。人間らしい温かみを持つAIを発見しましょう。
???? **住所:**
ドイツ、デッテンハイム、ヘーレン通り 11
???? **電話:**
オフィス: +49 (7247) 9851112
Mobile: +49 160 6688 222
Fax: +49 (7247) 9851113
???? **メール:**
[[email protected]](mailto:[email protected])
???? **ウェブサイト:**
[IT-Berater](http://www.it-berater.org) | [Smart Package](http://www.smart-package.com)
0
2件の返信を表示中 - 1 - 2件目 (全2件中)