chatGPTでPINEscriptのインジケータ書いてみた。1日目

1日1本、AIの助けを借りてコードを書くことにしました。多少細かいところは自分の手入力もありますが、ほとんどはAIに丸投げスタイルです。

chatGPTはPINEscript Version=4 に対応しています。

高値を更新してて勢いが強まってる時にチャートにサインを出すインジケータを作ってみました。作成時間は1時間ほど。アイデアを文章化するのと、エラーのデバッグに大半の時間を取られています。

お題:高値追いブレイクサインを出すインジケータ

次のコードをPINEscriptで書いて。
入力変数Aの値を元に
入力変数Aの本数分、前のバーの高値に水平線をひく。
この値を変数AAとする。
Aの変数の初期値は16で
高値=変数AAのtrue/falseを変数goにいれて
plotshape(go, style=shape.xcross)
入力変数Cの値を元に
過去C本連続して変数goがtrueならば
plotshapeの色を赤色に変える

返ってきたコードに、日本語手入力を加えたものがこれ。



// Define input variable A with an initial value of 16
A = input(16, title="指定期間中の高値")

// Get the high prices for the past A bars
AA = highest(high, A)

// Plot the highs as a horizontal line
plot(AA, style = plot.style_line, color = color.green, linewidth = 2)

// Check if high is equal to AA
go = high == AA

// Define input variable C
C = input(3, title="高値連続強い本数")

// Check if go is true for the past C bars
count = 0
for i = 0 to C
    if go[i]
        count := count + 1
    else
        count := 0

// Plot an asterisk in red color when go is true for the past C bars
color = go and count >= C ? color.red : color.green
plotshape(go, style=shape.xcross, color=color)


チャートに適用した画像がこれ
指定期間中の高値と、バーの高値が同じなら、バーの上にシャープマークを表示する。連続して条件を満たしたらオレンジ色に表示を変えています。

チップはこちらからお願いします