# Programming Workshop :chart_with_upwards_trend:
## 2022/10/20
[](https://)
:::success
//連續3紅K
//1跟比1跟高
//量放大
//參數化
//宣告參數: input:參數名稱(預設值,"說明文字");
//將參數取代原有的固定數值
:::
input: R1(1.2, "量的倍數");
condition1 = trueall(c>o,3);
condition2 = trueall(c>c[1],2);
condition3 = v>v[1]*R1;
condition4 = v>500;
if condition1
>and condition2
and condition3
and condition4
then ret=1;
---
value1 = getfield("外資買賣超", "D"); //買張- 賣張
condition1 = value1 > 500 ;
if condition1 then ret=1;
outputField(1, value1, "外資買超張數");
---
:::success
//計算資料, 取得資料 :dart:
:::
value1 = getfield("外資買賣超", "D"); //買張- 賣張
:::success
//設定條件
:::
condition1 = value1 > 500 ;
:::success
//執行選股
<font color="#f00">//if condition1 and condition1[1] and condition1[2] then ret=1;</font>
:::
if trueall(condition1,3) then ret=1;
:::success
//顯示資料 :100:
:::
outputField(1, value1, "外資買超張數");
settotalBar(20);
input:days(3,"連續買超天數");
input:v1(500,"買超張數");
---
:::success
//計算資料, 取得資料
:::
value1 = getfield("外資買賣超", "D"); //買張- 賣張
:::success
//設定條件 :+1:
:::
condition1 = value1 > v1 ;
:::success
//執行選股
//if condition1 and condition1[1] and condition1[2] then ret=1;
:::
if trueall(condition1,days) then ret=1;
:::success
//顯示資料
:::
outputField(1, value1, "外資買超張數");
---
value1 = getfield("每股稅後淨利(元)", "Y");
value2 = getfield("股本(元)", "D");
value3 = getfield("股東權益報酬率", "Y");
condition1 = value1>=5;
condition2 = value3>15;
if trueall(condition1,3) and trueall(condition2, 3) then ret=1;
outputField(1,value1, "EPS");
outputField(2,value2, "股本");
---
:::success
//連續3紅K
//1跟比1跟高
//量放大
//參數化
//1.宣告參數: input:參數名稱(預設值,"說明文字");
//2.將參數取代原有的固定數值
:::
input: R1(1.2, "量的倍數");
if symbol="6505.TW" then raiseRunTimeError("此商品不做!");
>condition1 = trueall(c>o,3);
condition2 = trueall(c>c[1],2);
condition3 = v>v[1]*R1;
condition4 = v>500;
if condition1
>and condition2
and condition3
and condition4
then setposition(1);
value1=lowest(L[1],5);
condition10=c <value1;
if condition10 then setposition(0);
:::success
//連續3紅K
//1跟比1跟高
//量放大
:::
if userid<>"NTUB-20" then raiseRunTimeError("xxx");
if date>20221231 then raiseRunTimeError("xxxxxx");
:::success
//參數化
//1.宣告參數: input:參數名稱(預設值,"說明文字");
//2.將參數取代原有的固定數值
:::
input: R1(1.2, "量的倍數");
if symbol="6505.TW" then raiseRunTimeError("此商品不做!");
>condition11= getfield("月營收", "M")< getfield("月營收", "M")[1];
condition1 = trueall(c>o,3);
condition2 = trueall(c>c[1],2);
condition3 = v>v[1]*R1;
condition4 = v>500;
if condition1
>and condition2
and condition3
and condition4
then setposition(1);
value1=lowest(L[1],5);
condition10=c <value1;
if condition10 then setposition(0);
if condition11 then setposition(0);
---
## 2022/12/01 選股策略
#### 上課完整影片檔~
[https://youtu.be/CP04efJd4oY](https://youtu.be/CP04efJd4oY)
:::success
Average
:::
value1 = average(c,20) ;
//condition1=c>value1 and c[1]<value1[1];
condition1=c cross Over value1;
condition2=v>500;
if condition1 and condition2 then ret=1;
:::success
EMA
:::
value1 = ema(c,20) ;
//condition1=c>value1 and c[1]<value1[1];
condition1=c cross Over value1;
condition2=v>500;
if condition1 and condition2 then ret=1;
:::success
RSI
:::
value1 = rsi(c,6);
//condition1=value1>80;
condition1=value1 cross Over 80;
condition2=v>500;
if condition1 and condition2 then ret=1;
outputField1(value1,"rsi");
:::success
KD
:::
settotalBar(50);
var:rsv1(0),k1(0),d1(0);
stochastic(9,3,3,rsv1,k1,d1);
condition1=k1 cross Over d1;
condition2=v>500;
if condition1 and condition2 then ret=1;
:::success
RSI+KD+SMA
:::
settotalBar(50);
var:rsv1(0),k1(0),d1(0);
stochastic(9,3,3,rsv1,k1,d1);
condition1=k1 cross Over d1;
condition2=v>500 and v>v[1]*1.2;
condition3=rsi(c,6)>60;
condition4=c>average(c,20);
//condition3=value1>60;
if condition1
and condition2
and condition3
and condition4
then ret=1;


:::success
月線交易
:::
value1 = average(c,20) ;
//condition1=c>value1 and c[1]<value1[1];
condition1=c cross Over value1;
condition2=v>500;
if condition1 and condition2 then setposition=(1);//多方部位一張(翻單交易)
condition3=c cross Under value1;//收盤價跌破月線
if condition3 and condition2 then setposition=(-1);



:::success
月線交易(剔除特定股票)
:::
if symbol="3008.tw" or symbol="3034.tw" then raiseRunTimeError("不交易");
value1 = average(c,20) ;
//condition1=c>value1 and c[1]<value1[1];
condition1=c cross Over value1;
condition2=v>500;
if condition1 and condition2 then setposition(1);
condition3=c cross Under value1;//收盤價跌破月線
if condition3 and condition2 then setposition(-1);

:::success
平倉(回測)
:::
if symbol="3008.tw" or symbol="3034.tw" then raiseRunTimeError("不交易");
value1 = average(c,20) ;
//condition1=c>value1 and c[1]<value1[1];
condition1=c cross Over value1;
condition2=v>500;
if condition1 and condition2 then setposition(1);
condition3=c cross Under value1;//收盤價跌破月線
if condition3 and condition2 then setposition(-1);
if filled>0 and c<filledAvgPrice*0.9 then setposition(0);//先平倉
if filled<0 and c>filledAvgPrice*1.1 then setposition(0);
{"metaMigratedAt":"2023-06-17T12:12:13.141Z","metaMigratedFrom":"YAML","title":"Programming Workshop :chart_with_upwards_trend:","breaks":true,"contributors":"[{\"id\":\"230da274-85b1-4ec8-9dd3-d8064a92fc6a\",\"add\":6865,\"del\":1594}]"}