Share Code Quickly

What is Harigami?

Harigami is a simple source code sharing service. You can share source code by an URL which is issued after submission.
You can also run your source code online such as Python, Ruby, JavaScript and so on.
For free.Use for code review.
Preferences
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;
}
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;
}
anonymous No title
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);
}
anonymous No title
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);
}
anonymous No title
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)


anonymous No title
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)
anonymous No title
Python
zd
anonymous No title
Python
//@version=3
study("MTF 5 SMA/EMA", overlay=true)

// SMA or EMA
SEswitch = input(title="on:EMA off:SMA", type=bool, defval=true)

//Set resolutions
resA = input(title='5M', type=resolution, defval="1")
resB = input(title='15M', type=resolution, defval="1")
resC = input(title='30M', type=resolution, defval="1")
resD = input(title='1H', type=resolution, defval="1")
resE = input(title='4H', type=resolution, defval="1")

//Set switches
maAswitch = input(title="MA1 On/Off", type=bool, defval=true)
maBswitch = input(title="MA2 On/Off", type=bool, defval=true)
maCswitch = input(title="MA3 On/Off", type=bool, defval=true)
maDswitch = input(title="MA4 On/Off", type=bool, defval=true)
maEswitch = input(title="MA5 On/Off", type=bool, defval=true)

//get data
dataA = security(tickerid, resA, SEswitch ? ema(close,100 ) : sma(close, 100))
dataB = security(tickerid, resB, SEswitch ? ema(close, 300) : sma(close, 300))
dataC = security(tickerid, resC, SEswitch ? ema(close, 600) : sma(close, 600))
dataD = security(tickerid, resD, SEswitch ? ema(close, 1200) : sma(close, 1200))
dataE = security(tickerid, resE, SEswitch ? ema(close, 4800) : sma(close, 4800))


//Plotting
plot(maAswitch ? dataA : na, color=aqua, linewidth=1)
plot(maBswitch ? dataB : na, color=red, linewidth=1)
plot(maCswitch ? dataC : na, color=lime, linewidth=1)
plot(maDswitch ? dataD : na, color=orange, linewidth=1)
plot(maEswitch ? dataE : na, color=purple, linewidth=1)
anonymous No title
Python
//@version=3
study('コゲクラウド', overlay=true)
EMAorSMA = input(title="平均線の選択", defval="SMA", options=["SMA", "EMA"])
FAST= input(title="FASTMA", type=integer, defval=20, minval=1, maxval=10000)
SLOW = input(title="SLOWMA", type=integer, defval=80, minval=1, maxval=10000)
ma_1 = input(title="MA1", type=integer, defval=5, minval=1, maxval=10000)
ma_2 = input(title="MA2", type=integer, defval=75, minval=1, maxval=10000)
ma_3 = input(title="MA3", type=integer, defval=200, minval=1, maxval=10000)
FASTMA = EMAorSMA == "EMA" ? ema(close, FAST) : sma(close, FAST)
SLOWMA = EMAorSMA == "EMA" ? ema(close, SLOW) : sma(close, SLOW)
ma1 = EMAorSMA == "EMA" ? ema(close, ma_1) : sma(close, ma_1)
ma2 = EMAorSMA == "EMA" ? ema(close, ma_2) : sma(close, ma_2)
ma3 = EMAorSMA == "EMA" ? ema(close, ma_3) : sma(close, ma_3)
ec = FASTMA > SLOWMA ? lime:red
plot(FASTMA, color=ec, linewidth=2)
plot(SLOWMA, color=ec, linewidth=2)
fill(plot(FASTMA), plot(SLOWMA), color = ec)
plot(ma1, color=aqua)
plot(ma2, color=purple)
plot(ma3, color=yellow)



anonymous No title
Python
study(title="RSI-SMA-EMA", shorttitle="RSI-SMA-EMA", overlay=false)
src = close, 
len = input(14, minval=1, title="RSI Length")
len2 = input(20, minval=1, title="SMA of RSI Length")
len3 = input(20, minval=1, title="EMA of RSI Length")
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
emaRSI = sma(rsi,len2)
emaRSI2 = ema(rsi,len3)

plot(rsi, title="RSI", style=line, linewidth=1, color=aqua)
plot(emaRSI, title="SMA of RSI", style=line, linewidth=1, color=orange)
plot(emaRSI2, title="EMA of RSI", style=circles, linewidth=1, color=lime)
band1 = hline(70, title="Upper Line", linestyle=dashed, linewidth=1, color=gray)
band0 = hline(30, title="Lower Line", linestyle=dashed, linewidth=1, color=gray)
fill(band1, band0, color=purple, transp=90)