メインコンテンツへスキップ
見出し画像

ライン価格・改

    コンビニの食材にちょい足ししてより美味しくしたり、
    新しい食べ物を生み出したりするのが好きなんですが、
    今更のライン価格ですが今回のはそんな感じのものですw

    画像

    既存のライン価格は設定したラインバリューで水平線を引きますが、
    引きすぎて何のラインなのか分からなくなる事がよくあると思います
    色やスタイルや太さで仕分けてても限界があります
    そこで既存のライン価格インジケータにテキストをちょい足しです
    何のラインかテキストで入力しておけば、色、スタイル、太さ等は、
    ラインの重要度に特化して使用できるようになります

    ※ テキストは半角英数のみにした方が良いと思います
      全角文字を入れると自分の環境だとトレステがクラッシュして、
      トレステ関連のタスクが残ったままの状態になります

    プログラム

    using elsystem;
    using elsystem.drawingobjects;
    using elsystem.drawing;
    using tsdata.marketdata;
    inputs:
    	double LineValue( closeW(1)) [DisplayName = "LineValue", ToolTip = "Enter an EasyLanguage expression.  Enter the value at which to plot the horizontal line."],
    	string MyText( " " ) [DisplayName = "Text", ToolTip = "Text"],
    	int MyPoint( 0 ) [DisplayName = "Point", ToolTip = "Point"],
    	int HorizLineColor( Green ) [DisplayName = "HorizLineColor", ToolTip = "Enter the color to use for the horizontal line."],
    	string HorizLineStyle( "Dashed" ) [DisplayName = "HorizLineStyle", ToolTip = "Enter the style to use for the horizontal line.  Example:solid Dashed Dotted Dashed2 Dashed3"],
    	int HorizLineWeight( 0 ) [DisplayName = "HorizLineWeight", ToolTip = "Enter a number from 0 to 6."],
    	double PercentTransparency( 25 ) [DisplayName = "PercentTransparency", ToolTip = "Enter a number from 0 to 100.  0 is fully opaque.  100 is fully transparent."];
    variables:
    	TextLabel TL( null ),							//テキストラベル
    	Font MyFont( null ),							//ラベルフォント
    	QuotesProvider QP( null ),
    	intrabarpersist int TransparValue( 0 ),
    	HorizontalLine HorizLine( null );				//水平線
    //クォーツプロバイダ設定
    method void CreateQuotesProvider()
    	begin
    		QP = new QuotesProvider;
    		QP.Symbol = Symbol;
    		QP.Fields += "bid,ask,last";
    		QP.Realtime = true;
    		QP.Updated += OnQuoteFieldUpdate;
    		QP.Load = true ;
    	end;
    //ライン設定・描画	
    method HorizontalLine CreateHorizontalLine( double HLPrice, int HLColor, int TransparencyPercent, string HLStyle, int HLWeight, bool MakeHLinePersistent )
    	variables:HorizontalLine HL, int TransparencyValue;
    	begin
    		TransparencyValue = Round( 0.01 * ( 100 - TransparencyPercent ) * 255, 0 ) astype int;
    		HL = HorizontalLine.Create( LineValue );
    		HL.Color = Color.FromARGB( TransparencyValue, GetRValue( HLColor ), GetGValue( HLColor ), GetBValue( HLColor ) );				//ライン色
    		HL.Price = HLPrice;							//ライン価格
    		HL.Style = GetHLStyleType( HLStyle );		//ラインスタイル
    		HL.Weight = HLWeight;						//ライン太さ
    		HL.Lock = true;								//ラインロック
    		HL.Persist = MakeHLinePersistent;			//存続
    		DrawingObjects.Add( HL );					//ライン描画
    //テキストラベル設定・描画
    		TL = TextLabel.Create( BNPoint.Create( CurrentBar - MyPoint, LineValue ), MyText );
    		TL.Color = Color.FromARGB( TransparencyValue, GetRValue( HLColor ), GetGValue( HLColor ), GetBValue( HLColor ) );
    		MyFont = Font.create( "MSUIGothic", 10 );	//テキストフォント
    		TL.Font = MyFont;							//テキストフォント
    		TL.Lock = true;								//テキストロック
    		TL.Persist = true;							//存続
    		DrawingObjects.Add( TL );					//テキスト描画
    		return HL;
    	end ;
    //ラインスタイルタイプ設定
    method StyleType GetHLStyleType( string HorizontalLineStyle )
    	variables: StyleType HLStyleType;
    	begin
    		switch ( LowerStr( HorizontalLineStyle ) ) begin
    			case "dashed":							//破線
    				HLStyleType = StyleType.dashed;
    			case "dashed2":							//一点鎖線
    				HLStyleType = StyleType.dashed2;
    			case "dashed3":							//二点鎖線
    				HLStyleType = StyleType.dashed3;
    			case "dotted":							//点線
    				HLStyleType = StyleType.dotted;
    			default:								//実線
    				HLStyleType = StyleType.solid;
    		end;
    		return HLStyleType;
    	end ;
    //ライン移動
    method void MoveHorizLine( HorizontalLine HorizLineToMove, double HorizLinePrice )
    	begin
    		if HorizLine <> null then HorizLineToMove.Price = HorizLinePrice;
    	end ;
    //クォーツプロバイダ変更あった時
    method void OnQuoteFieldUpdate( Object QPUpdateSender, QuoteUpdatedEventArgs QPUpdateArgs )
    	begin
    		MoveHorizLine( HorizLine, LineValue );
    	end ;
    //初回のみ
    once CreateQuotesProvider();
    //最後のバーのみ
    once ( LastBarOnChartEx ) begin
    	HorizLine = CreateHorizontalLine( LineValue, HorizLineColor, PercentTransparency, HorizLineStyle, HorizLineWeight, true );
    end ;
    MoveHorizLine( HorizLine, LineValue );
    ※ 設定のDisplayNameは、表示 - ツールバー - リソースビューの
      Japaneseの所で日本語変換しています
      DisplayName = ""の所に直接記述してもOKです

    画像


    あなたへのおすすめ