読み取り専用

フォーラムは現在、読み取り専用のアーカイブとなっています。.

バグ報告やプラットフォームに関する質問はこちら → [email protected]

私たちのコミュニティはDiscordとYouTubeで活動しています。ぜひ参加してください!

ご参加ください Discord YouTube

Is it possible to get 2 inputs (DataSeries) into a custom indicator?

5件の返信

ダヴ

購読者、bbp_participant、3件の返信。.

プロフィールを表示

2年前 #287834

Dear our community,

I want to write a new indicator similar to MA for a pair that isn’t supported. For example, a pair A_B that isn’t supported, but A_USD and B_USD are already supported.

As I know, in order to create a custom indicator like that requirement by programming in Java, I need 2 inputs (DataSeries), one for A_USD and other for B_USD. But, I don’t know how to get these inputs?

I tried several ways but not work.

This is the last try:

@BuildingBlock(name=”(HD) MA2S”, display=”MA2S()[#Shift#]”, returnType = ReturnTypes.Number)
ヘルプ(“MA2S help text”)
public class MA2S extends IndicatorBlock {
    @Parameter(name = “A_USD Price”)
    public DataSeries A_UsdPrice;
    @Parameter(name = “B_USD Price”)
    public DataSeries B_UsdPrice;
    @Parameter(defaultValue=”10″, isPeriod=true, minValue=2, maxValue=1000, step=1)
    public int Period;
    出力
    public DataSeries Value;
    @Override
    protected void OnBarUpdate() は TradingException を発生させます。
        //logic here
    }
}

0

テオ・ゴットヴァルト

Subscriber、bbp_participant、customer、community、sq-ultimate、60 replies.

プロフィールを表示

2年前 #287859

@BuildingBlock(name=”(HD) MA2S”, display=”MA2S(#Symbol1#,#Symbol2#)[#Shift#]”, returnType = ReturnTypes.Number)

ヘルプ
(“Moving Average calculated from the ratio of two symbols”)
public class MA2S extends IndicatorBlock {

@Parameter(name = “Symbol1”)
public String symbol1;

@Parameter(name = “Symbol2″)
public String symbol2;

@Parameter(defaultValue=”10”, isPeriod=true, minValue=2, maxValue=1000, step=1)
public int Period;

出力
public DataSeries Value;

private DataSeries symbol1Price;
private DataSeries symbol2Price;

@Override
protected void Init() throws TradingException {
// Initialize price series for both symbols
symbol1Price = GetSymbolData(symbol1, PriceType.Close);
symbol2Price = GetSymbolData(symbol2, PriceType.Close);
}

@Override
protected void OnBarUpdate() は TradingException を発生させます。
if (CurrentBar < Period) {
Value.Set(Double.NaN);
return;
}

double sum = 0;
for (int i = 0; i < Period; i++) {
// Calculate the ratio for each bar
double ratio = symbol1Price.Get(i) / symbol2Price.Get(i);
sum += ratio;
}

// Calculate and set the average
Value.Set(sum / Period);
}
}

Key points about this implementation:

Use @Parameter with String type to allow symbol selection

@Parameter(name = “Symbol1”)
public String symbol1;
Use GetSymbolData() method to get price data for symbols

symbol1Price = GetSymbolData(symbol1, PriceType.Close);
Initialize the price series in the Init() method rather than trying to get them directly as parameters

You can use this indicator like:

 

MA2S(“EURUSD”, “GBPUSD”, 10)[0]

Additional features you might want to add:

Price type selection:
java
Copy
@Parameter(name = “Price Type”, defaultValue = “Close”)
public PriceType priceType;

// In Init():
symbol1Price = GetSymbolData(symbol1, priceType);
symbol2Price = GetSymbolData(symbol2, priceType);

Error handling:

@Override
protected void Init() throws TradingException {
try {
symbol1Price = GetSymbolData(symbol1, priceType);
symbol2Price = GetSymbolData(symbol2, priceType);
} catch (Exception e) {
throw new TradingException(“Error initializing price data: ” + e.getMessage());
}
}
Validation:

@Override
protected void OnBarUpdate() は TradingException を発生させます。
if (symbol1Price == null || symbol2Price == null) {
throw new TradingException(“Price data not initialized”);
}

if (symbol2Price.Get(0) == 0) {
Value.Set(Double.NaN);
return;
}

// … rest of the calculation
}

This implementation will allow you to create a moving average based on any two symbols that are available in your data feed. The indicator will calculate the ratio between the two symbols for each bar and then compute the moving average of these ratios.

 

敬具

テオ・ゴットヴァルト
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

テオ・ゴットヴァルト

Subscriber、bbp_participant、customer、community、sq-ultimate、60 replies.

プロフィールを表示

2年前 #287860

The last explanation part was destroyed by the Forum Software.
So I paste it here unformatted.
<p data-pm-slice="”1" 1 []”>Key points about this implementation:</p>
 

1. Use @パラメータ with String type to allow symbol selection

`java

@Parameter(name = “Symbol1”)

public String symbol1;

`

 

2. Use GetSymbolData() method to get price data for symbols

`java

symbol1Price = GetSymbolData(symbol1, PriceType.Close);

`

 

3. Initialize the price series in the Init() method rather than trying to get them directly as parameters

 

4. You can use this indicator like:

`java

MA2S(“EURUSD”, “GBPUSD”, 10)[0]

`

 

Additional features you might want to add:

 

1. Price type selection:

`java

@Parameter(name = “Price Type”, defaultValue = “Close”)

public PriceType priceType;

 

// In Init():

symbol1Price = GetSymbolData(symbol1, priceType);

symbol2Price = GetSymbolData(symbol2, priceType);

`

 

2. Error handling:

`java

@Override

protected void Init() throws TradingException {

try {

symbol1Price = GetSymbolData(symbol1, priceType);

symbol2Price = GetSymbolData(symbol2, priceType);

} catch (Exception e) {

throw new TradingException(“Error initializing price data: ” + e.getMessage());

}

}

`

 

3. Validation:

`java

@Override

protected void OnBarUpdate() は TradingException を発生させます。

if (symbol1Price == null || symbol2Price == null) {

throw new TradingException(“Price data not initialized”);

}

 

if (symbol2Price.Get(0) == 0) {

Value.Set(Double.NaN);

return;

}

 

// … rest of the calculation

}

`

 

This implementation will allow you to create a moving average based on any two symbols that are available in your data feed. The indicator will calculate the ratio between the two symbols for each bar and then compute the moving average of these ratios.

敬具

テオ・ゴットヴァルト
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

テオ・ゴットヴァルト

Subscriber、bbp_participant、customer、community、sq-ultimate、60 replies.

プロフィールを表示

2年前 #287861

<p data-pm-slice="”1" 1 []”>Here are 10 significant improvements for the MA2S indicator:</p>
 

1. Add Data Validation and Safety Checks:

`java

@Override

protected void Init() throws TradingException {

if (symbol1.equals(symbol2)) {

throw new TradingException(“Symbols must be different”);

}

if (Period <= 0) {

throw new TradingException(“Period must be positive”);

}

 

try {

symbol1Price = GetSymbolData(symbol1, priceType);

symbol2Price = GetSymbolData(symbol2, priceType);

} catch (Exception e) {

throw new TradingException(“Failed to initialize price data: ” + e.getMessage());

}

}

`

 

2. Add Multiple MA Types:

`java

@Parameter(name = “MA Type”, defaultValue = “Simple”)

public MAType maType;

 

public enum MAType {

Simple,

Exponential,

Weighted,

Hull

}

 

private double calculateMA() {

switch (maType) {

case Simple: return calculateSMA();

case Exponential: return calculateEMA();

case Weighted: return calculateWMA();

case Hull: return calculateHull();

default: return calculateSMA();

}

}

`

 

3. Add Caching for Performance:

`java

private double[] ratioCache;

private int lastUpdatedBar = -1;

 

private void updateCache() {

if (lastUpdatedBar != CurrentBar) {

if (ratioCache == null) {

ratioCache = new double[Period];

}

for (int i = 0; i < Period; i++) {

ratioCache[i] = symbol1Price.Get(i) / symbol2Price.Get(i);

}

lastUpdatedBar = CurrentBar;

}

}

`

 

4. Add Statistical Measures:

`java

@Output(name = “StandardDeviation”)

public DataSeries StdDev;

 

@Output(name = “UpperBand”)

public DataSeries UpperBand;

 

@Output(name = “LowerBand”)

public DataSeries LowerBand;

 

private void calculateStatistics() {

double ma = Value.Get(0);

double sumSquaredDiff = 0;

 

for (int i = 0; i < Period; i++) {

double diff = ratioCache[i] – ma;

sumSquaredDiff += diff * diff;

}

 

double stdDev = Math.sqrt(sumSquaredDiff / Period);

StdDev.Set(stdDev);

UpperBand.Set(ma + (2 * stdDev));

LowerBand.Set(ma – (2 * stdDev));

}

`

 

5. Add Normalization Options:

`java

@Parameter(name = “Normalize”, defaultValue = “false”)

public boolean normalize;

 

@Parameter(name = “Normalization Period”, defaultValue = “100”)

public int normalizationPeriod;

 

private double getNormalizedRatio(double ratio) {

if (!normalize) return ratio;

 

double max = Double.MIN_VALUE;

double min = Double.MAX_VALUE;

 

for (int i = 0; i < normalizationPeriod; i++) {

double historicalRatio = symbol1Price.Get(i) / symbol2Price.Get(i);

max = Math.max(max, historicalRatio);

min = Math.min(min, historicalRatio);

}

 

return (ratio – min) / (max – min);

}

`

 

6. Add Time-Weighted Calculation:

`java

@Parameter(name = “Time Weighted”, defaultValue = “false”)

public boolean timeWeighted;

 

private double calculateTimeWeightedMA() {

double sum = 0;

double weightSum = 0;

 

for (int i = 0; i < Period; i++) {

double weight = timeWeighted ? (Period – i) : 1;

sum += ratioCache[i] * weight;

weightSum += weight;

}

 

return sum / weightSum;

}

`

 

7. Add Volume Consideration:

`java

@Parameter(name = “Volume Weighted”, defaultValue = “false”)

public boolean volumeWeighted;

 

private DataSeries symbol1Volume;

private DataSeries symbol2Volume;

 

private double calculateVolumeWeightedMA() {

double sum = 0;

double volumeSum = 0;

 

for (int i = 0; i < Period; i++) {

double volume = Math.min(symbol1Volume.Get(i), symbol2Volume.Get(i));

sum += ratioCache[i] * volume;

volumeSum += volume;

}

 

return sum / volumeSum;

}

`

 

8. Add Adaptive Period:

`java

@Parameter(name = “Adaptive Period”, defaultValue = “false”)

public boolean adaptivePeriod;

 

@Parameter(name = “Volatility Factor”, defaultValue = “2.0”)

public double volatilityFactor;

 

private int getAdaptivePeriod() {

if (!adaptivePeriod) return Period;

 

double volatility = calculateVolatility();

return Math.max(2, (int)(Period * (1 + volatilityFactor * volatility)));

}

`

 

9. Add Error Metrics:

`java

@Output(name = “MAE”)

public DataSeries MeanAbsoluteError;

 

@Output(name = “RMSE”)

public DataSeries RootMeanSquaredError;

 

private void calculateErrorMetrics() {

double ma = Value.Get(0);

double sumAbsError = 0;

double sumSquaredError = 0;

 

for (int i = 0; i < Period; i++) {

double error = Math.abs(ratioCache[i] – ma);

sumAbsError += error;

sumSquaredError += error * error;

}

 

MeanAbsoluteError.Set(sumAbsError / Period);

RootMeanSquaredError.Set(Math.sqrt(sumSquaredError / Period));

}

`

 

10. Add Trend Detection:

`java

@Output(name = “Trend”)

public DataSeries Trend;

 

@Parameter(name = “Trend Threshold”, defaultValue = “0.001”)

public double trendThreshold;

 

private void detectTrend() {

double currentMA = Value.Get(0);

double previousMA = Value.Get(1);

 

if (Math.abs(currentMA – previousMA) < trendThreshold) {

Trend.Set(0); // Sideways

} else {

Trend.Set(currentMA > previousMA ? 1 : -1); // Up or Down

}

}

`

 

Implementation:

`java

@Override

protected void OnBarUpdate() は TradingException を発生させます。

if (CurrentBar < Period) {

Value.Set(Double.NaN);

return;

}

 

updateCache();

 

double maValue;

if (volumeWeighted) {

maValue = calculateVolumeWeightedMA();

} else if (timeWeighted) {

maValue = calculateTimeWeightedMA();

} else {

maValue = calculateMA();

}

 

Value.Set(maValue);

calculateStatistics();

calculateErrorMetrics();

detectTrend();

}

`

 

These improvements make the indicator more versatile, robust, and informative. Users can choose different calculation methods and get additional statistical information about the ratio between the two symbols.

 

 

敬具

テオ・ゴットヴァルト
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

ダヴ

購読者、bbp_participant、3件の返信。.

プロフィールを表示

2年前 #287877

I got troubles with compile error from your code.

Such as:

>> method does not override or implement a method from a supertype: Init()

>> cannot find symbol: PriceType

>> cannot find symbol: GetSymbolData

 

 

添付ファイル:
に違いない ログインしました 添付ファイルを表示するには.

0

テオ・ゴットヴァルト

Subscriber、bbp_participant、customer、community、sq-ultimate、60 replies.

プロフィールを表示

2年前 #287902

Hello! It’s quite possible that this code contains bugs since it’s untested. The best approach is to input it into ChatGPT or Anthropic 3.5 and let them correct the code for you. Test it again, and if there are more errors, submit it once more for corrections. This is the best way to proceed. Currently, I’m unable to do much work on the screen.

#CodeCorrection #Debugging #ChatGPT #Anthropic #SoftwareTesting

敬具

テオ・ゴットヴァルト
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

5件の返信を表示中 - 1 - 5件目 (全5件中)