COCO研究院

 找回密碼
 註冊
搜索
查看: 3445|回復: 5

[教學] 請教寫法

[複製鏈接]
發表於 16-1-4 03:26 | 顯示全部樓層 |閱讀模式
請問大大
設定三種情況   做空單--買回平倉

已賣一張空單 設定條件買回 條件共三種情況 如下(略)

if condition1=true then buytocover next bar market;//如果狀況一為成立 下一根K棒開盤價買回
if condition1=false and condition2=true  then buytocover next bar market ;//狀況一不成立 狀況二成立 則買回
if condition1=false and condition2=false and condition3=true then buytocover next bar market;
//狀況一及二都不成立 狀況三成立 則買回

請問是這樣的寫法嗎?
如果要更細一點的設定 狀況一  狀況二   狀況三  有(成立)與(不成立)的情況共八種..2x2x2=8

都要一次寫出來嗎?

或是有更好的寫法?

新手上路 煩請大大幫忙

感恩
                                 
發表於 16-1-4 09:27 | 顯示全部樓層
1. 如果有條件有先後順序

if condition1 then buytocover ...
   else if condition2 then buytocover ...
       else if condition3 then buytocover ...

每一個 else 代表條件不成立的

2. 若是任何一個條件成立都可以

if Condition1 or Condition2 or ..... ConditionN then BuytoCover ....

3. 如果需符合任兩個以上條件時 , 作法要改變


input : TriggerNo(2) ;
var: CountCond(0) ;

重新定義 condition 如下

if 條件1 then cond1 = 1 else cond1 = 0 ;
if 條件2 then cond2 = 2 else cond2 = 0 ;
if 條件3 then cond3 = 3 else cond3 = 0 ;
...
...
if 條件N then condN = 1 else condN = 0 ;

CountCond = Cond1 + Cond2 + ..... CondN ;

if CountCond = TriggerNo then BuytoCover .....

若 TriggerNo = 1 時 ,等同上述 2 的任一條件成立
發表於 16-1-4 09:29 | 顯示全部樓層
easytrader788 發表於 16-1-4 09:27
1. 如果有條件有先後順序

if condition1 then buytocover ...

if 條件1 then cond1 = 1 else cond1 = 0 ;
if 條件2 then cond2 = 1 else cond2 = 0 ;
if 條件3 then cond3 = 1 else cond3 = 0 ;

打錯 , 每一個 CondN 用 1 代表成立 , 0代表不成立

評分

參與人數 1金錢 +2 收起 理由
平靜的海 + 2 按一個讚

查看全部評分

 樓主| 發表於 16-1-6 19:22 | 顯示全部樓層
再請問 已經使用了else if 第二行是需要空一格嗎?

if marketposition=0 and  value1 cross over value2  then
sellshort("S")  next bar at market;

if marketposition<0 and c < MM  then buytocover ("SW") next bar at market;
else if marketposition<0 and value2 cross over value1 then  buytocover ("SW") next bar at market;
end else

我無法編譯成功 爬文找不到類似的寫法 煩請大大指正

感恩
發表於 16-1-6 19:39 | 顯示全部樓層
本帖最後由 pcking2008 於 16-1-6 19:44 編輯
平靜的海 發表於 16-1-6 19:22
再請問 已經使用了else if 第二行是需要空一格嗎?

if marketposition=0 and  value1 cross over value2  t ...

if ...then A else if ...then B else C;

A 跟 B 如果只有一行不能加 ; (兩行以上就一定要用 begin end)
不然就要用
begin
     A;
end

的寫法



評分

參與人數 1金錢 +2 收起 理由
平靜的海 + 2 太強了

查看全部評分

 樓主| 發表於 16-1-6 20:06 | 顯示全部樓層
pcking2008 發表於 16-1-6 19:39
if ...then A else if ...then B else C;

A 跟 B 如果只有一行不能加 ; (兩行以上就一定要用 begin end)

if marketposition<0 and c < MM  then buytocover ("SW") next bar at market     //第一行
else if marketposition<0 and value2 cross over value1 then buytocover ("SW") next bar at market; //第二行

這樣可以編譯成功 謝謝
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-4-20 02:19

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 | AI繪圖AI超擬真美女AI beauty AI Stable DiffusionAI正妹AI Lookbook