Harigami
ログイン
Harigamiは、ログイン不要のコード共有サービスです。コードの投稿後に発行されるURLでコードを共有できます。
PythonやRubyなど一部の言語は、投稿後にオンラインで実行することもできます。
誰でも無料で使えて、広告もありません。コードレビューやスニペットの代わりに使ってみてください。


詳細設定
+
anonymous タイトルなし
Python
//@version=3
strategy("Parabolic SAR Strategy", overlay=true)

start = input(0.02)
increment = input(0.02)
maximum = input(0.2)

psar = sar(start, increment, maximum)

if (psar >= high)
    strategy.entry("ParLE", strategy.long, stop=psar, comment="LONG")
else
    strategy.cancel("ParLE")

if (psar <= low)
    strategy.entry("ParSE", strategy.short, stop=psar, comment="SHORT")
else
    strategy.cancel("ParSE")

plot(psar,color=lime,style =circles,linewidth = 2)
  • 0
  • 1
anonymous タイトルなし
Python
//@version=3
strategy("Bollinger Bands Strategy", overlay=true)
source = close
length = input(20, minval=1)
mult = input(2.0, minval=0.001, maxval=50)

basis = sma(source, length)
dev = mult * stdev(source, length)

upper = basis + dev
lower = basis - dev

buyEntry = crossover(source, lower)
sellEntry = crossunder(source, upper)

if (crossover(source, lower))
    strategy.entry("LONG", strategy.long, stop=lower, oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="LONG")
else
    strategy.cancel(id="LONG")

if (crossunder(source, upper))
    strategy.entry("LONG", strategy.short, stop=upper, oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="SHORT")
else
    strategy.cancel(id="SHORT")

P1 = plot(upper,color=aqua)
P2 = plot(lower,color=aqua)
plot(basis,color=orange)
fill(P1 , P2 ,color=aqua,transp=95)
  • 2
  • 0
anonymous 数値入力用のTextBox
C#
using System;
using System.Windows.Forms;

namespace NumBox2
{
    // ボックスに入力された文字列を数値へ変換する
    public partial class NumBox : TextBox
    {
        // Textが変更されるたびに数値を計算しなおすようにする
        // TextChangedイベントを発生させるメソッドであるところのOnTextChangedをオーバーライドする
        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);
            bool _ = double.TryParse(Text, out double res);
            this.ValText = res;
        }

        // NumBoxから他のコントロールへ移動するタイミングで表示を更新する
        protected override void OnLeave(EventArgs e)
        {
            base.OnLeave(e);
            this.Text = this.ValText.ToString();
        }

        // NumBoxにフォーカスしたらIMEをオフにする
        // (Win8以降ではImeModeが正常に働かないようなので注意)
        protected override void OnGotFocus(EventArgs e)
        {
            base.OnGotFocus(e);
            this.ImeMode = ImeMode.Off;
        }

        // Textを数値に変換した結果が入る(読み取り専用)
        public double ValText { get; private set; } = 0;
    }
}
  • 0
  • 1
Tomoaki Sugiyama タイトルなし
Python
--- index.html ---

<div>{{msg}}</div>

<form action="/post" method="POST">
    <input type="text" name="msg" value="test">
    <input type="submit" value="Submit">
</form>


--- app.py -----

from flask import request

@app.route('/post', methods=['post'])
def post():
    msg = request.form['msg']
    return render_template('index.html', msg=msg)
  • 0
  • 1
anonymous mergeSort
C++
#include<iostream>
#include<vector>
using namespace std;
const int SENTINEL=(1<<29);

void merge(vector<int>&A,int left,int mid,int right){
  int lm=mid-left,mr=right-mid;
  vector<int> L(lm+1),R(mr+1);
  copy(A.begin()+left,A.begin()+left+lm,L.begin());
  copy(A.begin()+mid,A.begin()+mid+mr,R.begin());
  L[lm]=R[mr]=SENTINEL;
  int Ldx=0,Rdx=0;
  for(int i=left;i<right;++i){
    if(L[Ldx]>R[Rdx])A[i]=R[Rdx++];
    else A[i]=L[Ldx++];
  }

}

void mergeSort(vector<int>&A,int left,int right){
  if(left+1<right){
    int mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int main(){

  int n;
  cin>>n;
  vector<int>A(n);
  for(auto&a:A)cin>>a;

  mergeSort(A,0,n);

  for(auto a:A)cout<<a<<" ";
  cout<<endl;

  return 0;
}
  • 0
  • 1
anonymous quickSort
C++
#include<iostream>
#include<vector>

int partion(std::vector<int>&A,int left,int right){
  int x=A[right];
  int i=left-1;
  for(int j=left;j<right;++j){
    if(A[j]<=x){
      i++;
      std::swap(A[i],A[j]);
    }
  }
  std::swap(A[i+1],A[right]);
  return i+1;
}

void quickSort(std::vector<int>&A,int left,int right){
  if(left<right){
    int q=partion(A,left,right);
    quickSort(A,left,q-1);
    quickSort(A,q+1,right);
  }
}

int main(){

  int n;
  std::cin>>n;
  std::vector<int> A(n);
  for(int i=0;i<n;++i)std::cin>>A[i];

  quickSort(A,0,n-1);
  for(int i=0;i<n;++i)std::cout<<A[i]<<" ";
  std::cout<<std::endl;

  return 0;
}
  • 0
  • 1
anonymous タイトルなし
C#
void Add_Damage(float damage, bool ignoreDefence = false)
{
	float discount = 20f;
	float defense_coef = 1f - CS_Player_Status.Defense / discount;
	if( ignoreDefence )
	{
		defense_coef = 1f;
	}
	if( damage * defense_coef > CS_Player_Status.Shield_Now )
	{
		Game_Over();
	}
	CS_Player_Status.Shield_Now -= damage * defense_coef;

	Debug.Log("ダメージ係数"+defense_coef);
	Debug.Log(damage * defense_coef);
}
  • 0
  • 1
anonymous タイトルなし
Scala
void Add_Damage(float damage, bool ignoreDefence = false)
{
	float discount = 20f;
	float defense_coef = 1f;
	if( !ignoreDefence )
	{
		defense_coef = 1f - CS_Player_Status.Defense / discount;
	}
	if( damage * defense_coef > CS_Player_Status.Shield_Now )
	{
		Game_Over();
	}
	CS_Player_Status.Shield_Now -= damage * defense_coef;

	Debug.Log("ダメージ係数"+defense_coef);
	Debug.Log(damage * defense_coef);
}
  • 0
  • 0
anonymous タイトルなし
Python
//@version=3
study('虹MA+BB', overlay=true)

//input
length = input(20, minval=1, title="SMA length")
src = input(close, title="Source")
mult1 = input(1.0, minval=0.001, maxval=50, title="BB1 mult")
mult2 = input(2.0, minval=0.001, maxval=50, title="BB2 mult")
mult3 = input(3.0, minval=0.001, maxval=50, title="BB3 mult")
bb1 = input(true, title="display BB1")
bb2 = input(true, title="display BB2")
bb3 = input(true, title="display BB3")
alert = input(2, minval=1, maxval=3, title="BB for alert number")
upper_src = input(high, title="BB uppper cross source")
lower_src = input(low, title="BB lower cross source")
cross_select = input("Outside", options=["Outside", "Inside"], title="cross select")

//SMA
basis = sma(src, length)

//BB3
dev3 = mult3 * stdev(src, length)
upper3 = basis + dev3
lower3 = basis - dev3
p5 = plot(bb3 ? upper3 : na, color=blue, title="upper 3")
p6 = plot(bb3 ? lower3 : na, color=blue, title="lower 3")
fill(p5, p6, color=aqua,transp=95,title="fill BB3")

//BB2
dev2 = mult2 * stdev(src, length)
upper2 = basis + dev2
lower2 = basis - dev2
p3 = plot(bb2 ? upper2 : na, color=blue, title="upper 2")
p4 = plot(bb2 ? lower2 : na, color=blue, title="upper 2")
fill(p3, p4, color=aqua,transp=95, title="fill BB2")

//BB1
dev1 = mult1 * stdev(src, length)
upper1 = basis + dev1
lower1 = basis - dev1
p1 = plot(bb1 ? upper1 : na, color=blue, title="upper 1")
p2 = plot(bb1 ? lower1 : na, color=blue, title="lower 1")
fill(p1, p2, color=aqua,transp=95, title="fill BB1")

plot(basis, color=red, title="SMA")

upper = alert == 1 ? upper1 : alert == 2 ? upper2 : upper3
lower = alert == 1 ? lower1 : alert == 2 ? lower2 : lower3
upper_cross = cross_select == "Outside" ? crossover(upper_src, upper) : crossunder(upper_src, upper)
lower_cross = cross_select == "Outside" ? crossunder(lower_src, lower) : crossover(lower_src, lower)

alertcondition(upper_cross or lower_cross, title="Alert BB Cross", message="Alert BB Cross")
//MA
emaOrSma = input(title="MAの選択", defval="EMA", options=["EMA", "SMA"])
maPeriodFast_1 = input(title="MA Period Fast 1", type=integer, defval=3, minval=1, maxval=10000)
maPeriodFast_2 = input(title="MA Period Fast 2", type=integer, defval=5, minval=1, maxval=10000)
maPeriodFast_3 = input(title="MA Period Fast 3", type=integer, defval=8, minval=1, maxval=10000)
maPeriodFast_4 = input(title="MA Period Fast 4", type=integer, defval=10, minval=1, maxval=10000)
maPeriodFast_5 = input(title="MA Period Fast 5", type=integer, defval=12, minval=1, maxval=10000)
maPeriodFast_6 = input(title="MA Period Fast 6", type=integer, defval=15, minval=1, maxval=10000)
maPeriodSlow_1 = input(title="MA Period Slow 1", type=integer, defval=30, minval=1, maxval=10000)
maPeriodSlow_2 = input(title="MA Period Slow 2", type=integer, defval=35, minval=1, maxval=10000)
maPeriodSlow_3 = input(title="MA Period Slow 3", type=integer, defval=40, minval=1, maxval=10000)
maPeriodSlow_4 = input(title="MA Period Slow 4", type=integer, defval=45, minval=1, maxval=10000)
maPeriodSlow_5 = input(title="MA Period Slow 5", type=integer, defval=50, minval=1, maxval=10000)
maPeriodSlow_6 = input(title="MA Period Slow 6", type=integer, defval=60, minval=1, maxval=10000)
fast_1 = emaOrSma == "EMA" ? ema(close, maPeriodFast_1) : sma(close, maPeriodFast_1)
fast_2 = emaOrSma == "EMA" ? ema(close, maPeriodFast_2) : sma(close, maPeriodFast_2)
fast_3 = emaOrSma == "EMA" ? ema(close, maPeriodFast_3) : sma(close, maPeriodFast_3)
fast_4 = emaOrSma == "EMA" ? ema(close, maPeriodFast_4) : sma(close, maPeriodFast_4)
fast_5 = emaOrSma == "EMA" ? ema(close, maPeriodFast_5) : sma(close, maPeriodFast_5)
fast_6 = emaOrSma == "EMA" ? ema(close, maPeriodFast_6) : sma(close, maPeriodFast_6)
slow_1 = emaOrSma == "EMA" ? ema(close, maPeriodSlow_1) : sma(close, maPeriodSlow_1)
slow_2 = emaOrSma == "EMA" ? ema(close, maPeriodSlow_2) : sma(close, maPeriodSlow_2)
slow_3 = emaOrSma == "EMA" ? ema(close, maPeriodSlow_3) : sma(close, maPeriodSlow_3)
slow_4 = emaOrSma == "EMA" ? ema(close, maPeriodSlow_4) : sma(close, maPeriodSlow_4)
slow_5 = emaOrSma == "EMA" ? ema(close, maPeriodSlow_5) : sma(close, maPeriodSlow_5)
slow_6 = emaOrSma == "EMA" ? ema(close, maPeriodSlow_6) : sma(close, maPeriodSlow_6)
//color
plot(fast_1, color=yellow)
plot(fast_2, color=orange)
plot(fast_3, color=red)
plot(fast_4, color=maroon)
plot(fast_5, color=fuchsia)
plot(fast_6, color=purple)
plot(slow_1, color=navy)
plot(slow_2, color=blue)
plot(slow_3, color=aqua)
plot(slow_4, color=teal)
plot(slow_5, color=lime)
plot(slow_6, color=green)


  • 0
  • 1
anonymous タイトルなし
Python
//@version=3
study("MTF 320MA", overlay=true)
SEswitch = input(title="on:EMA off:SMA", type=bool, defval=true)
res = input(title='4H', type=resolution, defval="1")
maEswitch = input(title="MA5 On/Off", type=bool, defval=true)
data = security(tickerid, res, SEswitch ? ema(close, 4800) : sma(close, 4800))
plot(maEswitch ? data : na, color=purple, linewidth=2)
  • 0
  • 0