COCO研究院

 找回密碼
 註冊
搜索
查看: 4144|回復: 13

[教學] 在倉部位不會賣出 加碼部位卻正常

[複製鏈接]
發表於 16-2-25 14:22 | 顯示全部樓層 |閱讀模式
var:aa(0),mp(0);


mp=marketposition*currentcontracts;


if mp=0 and time>0845 and time<1344 then begin

once(close=7800)begin
        buy ("firstentry")30 contract next bar at 7800 limit;
                aa=7800;
               
        end;
end;

if mp>0 and time>0845 and time<1344 then begin
        if close-aa<-50 then begin
                buy 1 contract next bar at market;
                aa=aa-50;
               
        end else
       
        if  close-aa>100 then begin
                sell  1 contract total next bar at market;
                aa=aa+100;
               
               
       
        end;
end;

訊號只會針對 Firstentry的部位執行一次,請問要怎麼讓他可以持續賣出?
後面的加碼部位卻可以正常買賣




S__14753832.jpg
S__14753833.jpg
發表於 16-3-1 01:09 | 顯示全部樓層
alexliou 發表於 16-2-29 18:01
原PO提到   "訊號只會針對 Firstentry的部位執行一次,請問要怎麼讓他可以持續賣出?"

因為好奇心     這個 ...

為了實驗方便 ,把手工設定價為改成浮動這樣 +100 -100也是浮動
這樣人工下單 ,機器幫忙看家的方式就自行發揮了~~~~

input: FirstLots(30),handkeyprice(7800),starttime(0845),endtime(1344),TP(100),SL(50) ;

var: aa(0),mp(0),counter(0),ename(""),counter2(0);

mp=marketposition*currentcontracts;
if mp=0 and time>starttime and time<endtime then begin
        once(close=handkeyprice)begin
                buy ("firstentry") FirstLots contract next bar at handkeyprice limit;
               aa=handkeyprice;               
       end;
end;

if mp>0 and time>starttime and time<endtime then begin
           if close-aa<-SL then begin
              buy("Buy") 1 contract next bar at market;
              counter2=counter2+1;
              aa=aa-SL;               
       end else if  close-aa>TP then begin
               If counter2<=0 then begin
                       counter=counter+1;
                       ename="S"+NumtoStr(counter,0);
                       sell(ename) 1 contract total next bar at market;
               end else begin
                       sell from entry("Buy") 1 contract total next bar at market;
                       counter2=counter2-1;
               end;               
               aa=aa+TP;               
        end;
end;


評分

參與人數 2金錢 +2 收起 理由
沒房子的阿捨 + 1 感謝分享
Acer2266 + 1 感謝分享

查看全部評分

回復 支持 3 反對 0

使用道具 舉報

發表於 16-3-1 06:02 | 顯示全部樓層
原先版大策略的邏輯稍微複雜
我摸索好久   一直無法精確看出partial selling entry是如何運作的
後來我寫了底下這個程式
玩弄幾下   就確認了
1. partial selling entry的行為模式
    同一個partial selling entry 針對同一"次"的buying entry 只能進行一次的partial sale
2. 有total 與 無total 的差別
3. 庫存部位的出售是採取first in first out 的作法
其中2,3 MC官方文件都有說明,   1則是undocumented

有興趣的人可以自己玩玩看
resolution 建議為5分線
記得在策略屬性將 Allow mutiple entry  orders 勾起來

If Date = 1160226 then Begin   
        If Time = 0900 then
                 Buy 5 contracts next bar at the market;
         
       If Time = 0915 then
               Buy 3 contracts next bar at the market;
      
             If Time = 0930 then
              sell 1 contracts next bar at the market;                  
      
       If Time >= 1000 then
              sell 1 contracts total next bar at the market;   
   
End;

評分

參與人數 2金錢 +6 收起 理由
TrendRover + 5 感謝分享
沒房子的阿捨 + 1 很棒的文章,感恩

查看全部評分

回復 支持 1 反對 0

使用道具 舉報

發表於 16-2-29 18:01 | 顯示全部樓層
原PO提到   "訊號只會針對 Firstentry的部位執行一次,請問要怎麼讓他可以持續賣出?"

因為好奇心     這個問題我實驗了一下午
結果顯示  每個partial sell 的entry  的確只會對相同的long entry進行一次而已
所以第一次買進的30口  
如果要部分平倉   每次賣出一口   就需要30個sell entry
假設你原先買的30口在新買的契約沒消化前不賣
我將原先Code更改如下

var:aa(0),mp(0),counter(0),ename(""),counter2(0);

mp=marketposition*currentcontracts;
if mp=0 and time>0845 and time<1344 then begin
        once(close=7800)begin
                buy ("firstentry")30 contract next bar at 7800 limit;
               aa=7800;               
       end;
end;

if mp>0 and time>0845 and time<1344 then begin
           if close-aa<-100 then begin
              buy("Buy") 1 contract next bar at market;
              counter2=counter2+1;
              aa=aa-100;               
       end else if  close-aa>100 then begin
               If counter2<=0 then begin
                       counter=counter+1;
                       ename="S"+NumtoStr(counter,0);
                       sell(ename) 1 contract total next bar at market;
               end else begin
                       sell from entry("Buy") 1 contract total next bar at market;
                       counter2=counter2-1;
               end;                
               aa=aa+100;               
        end;
end;

我把每50點向下買一口改為每100點買一口
要不然不對稱的買法
若非大大大多頭行情
會買到永遠賣不完(甚至賣不到)原先那30口
回復 支持 1 反對 0

使用道具 舉報

發表於 16-2-27 23:00 | 顯示全部樓層
應該是這個.....

擷取.JPG
回復 支持 0 反對 1

使用道具 舉報

發表於 16-2-26 01:13 | 顯示全部樓層
這邊有沒有設定?

擷取.JPG
 樓主| 發表於 16-2-26 08:40 | 顯示全部樓層
有耶~ 我把它設定到最高值了
發表於 16-2-26 23:10 | 顯示全部樓層
jetluo88 發表於 16-2-26 08:40
有耶~ 我把它設定到最高值了

你是想要做成這樣子嗎?

擷取.JPG
發表於 16-2-29 09:12 | 顯示全部樓層
我作了一下實驗把 sell 換成 sellshort 試了試, marketposition被指令影響的機制跟我們的想像不同 .
   我把sell 換成 sellshort後  他認定 marketposition變成負值 (在 position =initial -1口時----)


發表於 16-2-29 18:14 | 顯示全部樓層
本帖最後由 alexliou 於 16-2-29 18:29 編輯

我想這應該是原PO想要的結果

擷取.PNG
發表於 16-2-29 19:39 | 顯示全部樓層
alex大太厲害了~又跟您偷偷學到新招XD

我也又修改了一下, 應該是這樣吧XD
擷取.JPG

發表於 16-3-1 09:39 | 顯示全部樓層
alexliou 發表於 16-3-1 06:02
原先版大策略的邏輯稍微複雜
我摸索好久   一直無法精確看出partial selling entry是如何運作的
後來我寫了 ...

有個分批出場開關
[SameExitFromOneEntryOnce=false;]
加了這行以後就可以不分entry 只要有多單部位都可以分批Sell
但結果就會像我第二張圖一樣...好像全都先從firstentry出場, 看起來怪怪的

評分

參與人數 2金錢 +4 收起 理由
swwang1999 + 2 感謝分享
alexliou + 2 按一個讚

查看全部評分

 樓主| 發表於 16-3-4 12:52 | 顯示全部樓層
真是太感謝各位大大的幫忙
 樓主| 發表於 16-3-4 13:20 | 顯示全部樓層
想要請問各位大神 要在哪裡可以學到這些資訊.....   
想要進步 可是不知道要從何開始  還是新手 還有好長的路要走
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

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

GMT+8, 24-5-3 14:56

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

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