カスタムインジケーター
3件の返信
Hi I wrote a custome indicator for SupplyAndDemand, but when I use it on AlgoWizard. There is no trade. Did I something wrong? See Attachment.
敬具,
ホスチー
0
テオ・ゴットヴァルト
2年前 #287678
### Analysis of the Script
The script is written in Java and appears to be for **StrategyQuant**, which is a platform for automated trading strategies. The class SupplyDemand represents an indicator that calculates supply and demand levels for financial markets.
Here’s a breakdown of key components:
1. **Package and Imports**:
The script imports several libraries from the StrategyQuant platform, which provide functionalities like data handling, trading logic, logging, and custom indicator creation.
2. **Building Block Definition**:
注釈 @ビルディングブロック defines the indicator as a building block for StrategyQuant’s environment. The 名前, 表示, 、および 戻り値の型 define the name of the indicator and how it will appear in the platform, as well as the type of data it will return (in this case, price data).
3. **Parameters**:
– 入力: A データシリーズ object representing the input price series (likely OHLC data).
– ピリオド: Defines how many bars (or periods) are used in the calculation. By default, it’s set to 10.
4. **Output**:
価値: A データシリーズ representing the calculated supply-demand value for each bar.
5. **Core Logic**:
– OnBarUpdate(): This method is triggered every time a new bar (time period) is updated. It attempts to call the updateIndicator() method and catches any exceptions.
– updateIndicator(): This method checks if the input data and output series are valid, calculates the supply-demand value, and logs the output.
– calculateIndicatorValue(): This method calculates the average of the highest and lowest price over the defined ピリオド and returns that as the indicator value.
6. **Error Handling**:
The code handles two types of exceptions:
– TradingException for custom trading errors.
– General Exception for unexpected errors, with both logged for debugging.
### Purpose and Use
The indicator computes an average of the highest and lowest prices over a given period to determine a midpoint price that can be interpreted as a supply or demand level. This midpoint can be used by traders to identify potential areas of support or resistance in a market. The value might signal possible price reversals, helping traders make buy or sell decisions.
### Possible Bugs or Improvements
1. **Null Checks**:
その 入力 そして 価値 series are checked for null values, but only once when updating. A potential issue could occur if these become null during the indicator’s lifecycle (for example, if the data changes or is removed). You could add more robust checks or warnings if this occurs.
2. **Logging Frequency**:
The logging is quite verbose, especially when it logs on every bar update (Log.info("SupplyDemand: Set value...")). This could create performance issues or excessive log files in a live trading environment. Reducing the frequency or using a higher log level (like debug instead of info) could help.
3. **Performance Considerations**:
の中で calculateIndicatorValue() method, the loop iterates over the ピリオド to find the highest and lowest values. If the ピリオド is very long (e.g., 1000), this might slow down performance. Consider optimizing this if the script is expected to run on large datasets or for high-frequency trading strategies.
4. **Edge Case Handling**:
The method uses CurrentBar < Period to handle the early bars (when there isn’t enough data to calculate the indicator). It just returns the first value in 入力. This is acceptable but might produce inaccurate results for those first bars. You could consider more sophisticated logic (e.g., using a partial calculation or smoothing) to deal with this issue.
### Conclusion
This script is a custom supply-demand indicator for StrategyQuant, designed to calculate the average of the highest and lowest prices over a set period. It is useful for identifying market support and resistance levels.
It functions well overall but could benefit from a few performance improvements and enhanced logging control.
コード
package SQ.Blocks.Indicators.SupplyDemand;
com.strategyquant.lib.*; をインポートする;
import com.strategyquant.datalib.*;
import com.strategyquant.tradinglib.*;
SQ.Internal.IndicatorBlock をインポートする;
@BuildingBlock(name=”(XXX) SupplyDemand”, display=”SupplyDemand(#Period#)[#Shift#]”, returnType = ReturnTypes.Price)
ヘルプ(“SupplyDemand help text”)
public class SupplyDemand extends IndicatorBlock {
@パラメータ
public DataSeries Input;
@Parameter(defaultValue=”10″, isPeriod=true, minValue=2, maxValue=1000, step=1)
public int Period;
出力
public DataSeries Value;
@Override
protected void OnBarUpdate() {
try {
updateIndicator();
} catch (TradingException e) {
Log.error(“SupplyDemand: TradingException in OnBarUpdate: ” + e.getMessage());
} catch (Exception e) {
Log.error(“SupplyDemand: Unexpected error in OnBarUpdate: ” + e.getMessage());
}
}
private void updateIndicator() throws TradingException {
// Ensure Input and Value are not null
if (Input == null) {
throw new TradingException(“Input DataSeries is null”);
}
if (Value == null) {
throw new TradingException(“Value DataSeries is null”);
}
double indiValue;
if (CurrentBar < Period) {
// Use an average of available values instead of just the first one for early bars
indiValue = averageOfAvailableValues();
Log.debug(“SupplyDemand: Using average of available values for early bars”);
} else {
indiValue = calculateIndicatorValue();
Log.debug(“SupplyDemand: Calculated value for bar ” + CurrentBar);
}
Value.set(0, indiValue);
Log.debug(“SupplyDemand: Set value ” + indiValue + ” for bar ” + CurrentBar);
}
private double calculateIndicatorValue() throws TradingException {
double highest = Input.get(0);
double lowest = Input.get(0);
// Optimized loop, start from 1 and avoid unnecessary conditions
for (int i = 1; i < Period; i++) {
highest = Math.max(highest, Input.get(i));
lowest = Math.min(lowest, Input.get(i));
}
Log.debug(“SupplyDemand: Highest: ” + highest + “, Lowest: ” + lowest);
return (highest + lowest) / 2;
}
// Average the values of the available bars when CurrentBar < Period
private double averageOfAvailableValues() {
double sum = 0.0;
int count = Math.min(CurrentBar + 1, Period); // Ensure we do not exceed available bars
for (int i = 0; i < count; i++) {
sum += Input.get(i);
}
return sum / count;
}
}
[/code]
PS: 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
Hallo Theo,
vielen Dank.
1
テオ・ゴットヴァルト
2年前 #287719
Keine Ursache, ich würde sogar sagen …. nimm dass:
コード
package SQ.Blocks.Indicators.SupplyDemand;
com.strategyquant.lib.*; をインポートする;
import com.strategyquant.datalib.*;
import com.strategyquant.tradinglib.*;
SQ.Internal.IndicatorBlock をインポートする;
@BuildingBlock(name=”(XXX) SupplyDemand”, display=”SupplyDemand(#Period#)[#Shift#]”, returnType = ReturnTypes.Price)
ヘルプ(“SupplyDemand help text”)
public class SupplyDemand extends IndicatorBlock {
@パラメータ
public DataSeries Input;
@Parameter(defaultValue=”10″, isPeriod=true, minValue=2, maxValue=1000, step=1)
public int Period;
出力
public DataSeries Value;
@Override
protected void OnBarUpdate() {
try {
updateIndicator();
} catch (TradingException e) {
Log.error(“SupplyDemand: TradingException in OnBarUpdate: ” + e.getMessage());
} catch (Exception e) {
Log.error(“SupplyDemand: Unexpected error in OnBarUpdate: ” + e.getMessage());
}
}
private void updateIndicator() throws TradingException {
// Sicherstellen, dass Input und Value nicht null sind
if (Input == null) {
throw new TradingException(“Input DataSeries is null”);
}
if (Value == null) {
throw new TradingException(“Value DataSeries is null”);
}
double indiValue;
if (CurrentBar < Period – 1) {
// Durchschnitt der verfügbaren Werte für frühe Bars verwenden
indiValue = averageOfAvailableValues();
Log.debug(“SupplyDemand: Using average of available values for early bars”);
} else {
indiValue = calculateIndicatorValue();
Log.debug(“SupplyDemand: Calculated value for bar ” + CurrentBar);
}
Value.set(0, indiValue);
Log.debug(“SupplyDemand: Set value ” + indiValue + ” for bar ” + CurrentBar);
}
private double calculateIndicatorValue() throws TradingException {
// Sicherstellen, dass genügend Datenpunkte vorhanden sind
if (Input.size() < Period) {
throw new TradingException(“Not enough data to calculate indicator value”);
}
double highest = Input.get(0);
double lowest = Input.get(0);
// Schleife über die letzten ‘Period’ Bars
for (int i = 1; i < Period; i++) {
double value = Input.get(i);
highest = Math.max(highest, value);
lowest = Math.min(lowest, value);
}
Log.debug(“SupplyDemand: Highest: ” + highest + “, Lowest: ” + lowest);
return (highest + lowest) / 2;
}
// Durchschnitt der verfügbaren Werte berechnen, wenn CurrentBar < Period – 1
private double averageOfAvailableValues() throws TradingException {
int count = CurrentBar + 1; // Anzahl der verfügbaren Bars
// Sicherstellen, dass mindestens ein Datenpunkt vorhanden ist
if (count <= 0) {
throw new TradingException(“No available data to average”);
}
double sum = 0.0;
for (int i = 0; i < count; i++) {
sum += Input.get(i);
}
return sum / count;
}
}[/code]
敬具
テオ・ゴットヴァルト
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
3件の返信を表示中 - 1 - 3件目 (全3件中)