COCO研究院

 找回密碼
 註冊
搜索
查看: 27912|回復: 46

MultiCharts 停損追蹤守線交易程式

  [複製鏈接]
發表於 10-10-18 20:06 | 顯示全部樓層 |閱讀模式
把 以前 日盛HTS的一支 簡單的 建新倉、停損、停利、布林通道、守線、追蹤折頭..等等功能的程式
移轉給 MC 經過測試 一切正常顯示 倉位的 進出

MC 編寫自訂函數時,要過濾 輸入參數=0 的 狀況,以免 計算產生 除以0 或 出現 例外異常 的信息。

暫時不把 程式包 上傳,先看看 是否有需要?

我多在 搞破壞,一些業內,粉恨~~~~

真歹勢~~~
發表於 10-10-18 20:40 | 顯示全部樓層
MC還不會用,現在正在學VBA

資格太淺不能下載來參考.............
發表於 10-10-18 22:30 | 顯示全部樓層
把 以前 日盛HTS的一支 簡單的 建新倉、停損、停利、布林通道、守線、追蹤折頭..等等功能的程式
移轉給 MC  ...
trading144 發表於 10-10-18 08:06 PM



    就放上來吧,業內不用管它吧





發表於 10-10-18 22:34 | 顯示全部樓層
雖然我沒用MC 不過我還是很期待 T大的程式可以讓我參考
 樓主| 發表於 10-10-18 22:53 | 顯示全部樓層
這是屬於 MC 的 封包,要使用 MC 才能導入

假若要 文字檔,比較難搞。

每種介面語法略有不同,又沒有 圖形去比對信號,比較難瞭解程式信號的效果。

再看看吧! 有時間在弄出來 TXT檔

HTSTrade.rar

6.23 KB, 下載次數: 1441

 樓主| 發表於 10-10-18 22:54 | 顯示全部樓層
Inputs: InitialStop(21),Profit(89),BreakEven(21),MinDist(13)
           ,Trade(34),car(3),StopLine(34),StopCar(3),Band(89),ref(1)
           ,Line(144),Turn(21),Stpadjust(4),Cnt(1),Factor(1),DayTrade(0),output(0);
Vars:BuyLimit(0),SellLimit(0),isStop(0),isBand(0),TheEnd(0)
     ,isBuy(0),isSell(0),ProfitHit(0),BandHit(0)
     ,lastB(0),lastS(0),isLong(0),isShort(0),isTrace2(0)
     ,Bprice(0),Sprice(0),BandH(0),BandL(0),isTrace(0)
     ,Blost(0),Slost(0),PP(0),HitProfit(0),isTrade2(0)
     ,Bcost(0),Scost(0),isTurned(0),LineH2(0),LineL2(0),LineH1(0),LineL1(0)
     ,Turn1(0),Turn2(0),balance(0),Blost1(0),Slost1(0),Dist(0),Hit(0)
     ,nColor( green ), nCurrentContracts(0);      
Dist=MinDist+Stpadjust*2; //Dist=6+4*2
if Band>0 then begin
Value3 = StdDev((High+Low)/2, Band)[1]; //Band = 89
BandH = AverageFC((High+Low)/2, Band)[1] + 2.5 * Value3;
BandL = AverageFC((High+Low)/2, Band)[1] - 2.5 * Value3;
end;
if Line>0 and Turn>0 then begin
Value1=AverageFC((High+Low)/2, Turn)[0];
Value2=AverageFC((High+Low)/2, Line)[0];
Value21=AverageFC((High+Low)/2, Turn)[1];
Value22=AverageFC((High+Low)/2, Line)[1];
LineH1=AverageFC(High, Line)[0];
LineH2=AverageFC(High, Line)[1];
LineL1=AverageFC(Low, Line)[0];
LineL2=AverageFC(Low, Line)[1];
Turn1=AverageFC((High+Low)/2, Turn)[0]; // Turn = 21
Turn2=AverageFC((High+Low)/2, Turn)[1];
end;
if Turn2>=LineL2 and  Turn1<LineL1 and Line<>0 then begin
  isTurned=2;
end;   
if Turn2<=LineH2 and  Turn1>LineH1 and Line<>0 then begin
  isTurned=1;
end;
if StopLine>0 then begin
Value12=AverageFC(Low, StopLine)[1]; // StopLine = 34
Value11=AverageFC(High, StopLine)[1];
end;

HitProfit=Profit;
  
   balance=absvalue( CurrentContracts );
   if CurrentContracts = 0 then begin
      isLong=0;
      isTrace=1;
      isShort=0;
      Hit=0;
      Slost=0;
      Scost=0;
      Blost=0;
      Bcost=0;
   end;
   if time>=84500 then begin
           isTrace2=0;
   end;
if StopLine>0 and StopCar=1 then isStop=Stopped(StopLine,ref) else isStop=0;
if StopLine>0 and StopCar>1 then isStop=Stopped2(StopLine,StopCar,ref) else isStop=0;
   
if Trade>0 and car>0 then isTrade2=Crossed(Trade,car,ref) else isTrade2=0;

if isTrace=1 and isLong=0 and isShort=0 and (time<132500 or DayTrade=0) then begin

   if isTrade2=1 and (isTurned=1 or Value2=0)
      and (Close[0]>Value12 or Value12=0) then begin
      buy("bb") Cnt contracts next bar at market;
      isLong=1;
      isShort=0;
      ProfitHit=0;
      BandHit=0;
      Sprice=0;
      Bcost=Close[0];
      Bprice=Close[0]+IntPortion(HitProfit/1);
      Blost=Close[0] - InitialStop;
      PP=Close[0];
      //Return;
   end;

   if isTrade2=2 and (isTurned=2 or Value2=0)
      and (Close[0]<Value11 or Value11=0) then begin
      SellShort("ss") Cnt contracts next bar at market;
      isLong=0;
      isShort=1;
      ProfitHit=0;
      BandHit=0;
      Bprice=0;
      Scost=Close[0];
      Sprice=Close[0]-IntPortion(HitProfit/1);
      Slost=Close[0] + InitialStop;
      PP=Close[0];
      //Return;
   end;   
   
end;

   
   
if isLong = 1 then begin
   balance=absvalue( CurrentContracts );   
   if InitialStop > 0 and Blost=0 and Bcost=0 then begin
      Blost=EntryPrice(0) - InitialStop ;
      Bcost=EntryPrice(0);
   end;
   if Blost<Bcost and EntryTime(0)=time then begin
      //exitlong("XL0") all contracts this bar at Blost-Stpadjust*2 stop;
      sell("XL0") all contracts next bar at Blost-Stpadjust*2 stop;
   end;
   if Blost<Bcost and EntryTime(0)<time then begin
      //exitlong("XL1") all contracts this bar at Blost stop;
      sell("XL1") all contracts next bar at Blost stop;
   end;
   if Blost<Bcost and EntryTime(0)<time and Close[0]<Blost then begin
      //exitlong("XL") all contracts next bar at market;
      sell("XL") all contracts next bar at market;
   end;   
   if BreakEven > 0 and High[0]-Bcost>BreakEven  and Blost<Bcost and EntryTime(0)<time then begin
      Blost=Bcost+1;
      Blost1=Bcost+1;
   end;
   if MinDist > 0 and High[0]-Blost>Dist  and Blost>Bcost and EntryTime(0)<time
      and (balance=Cnt or ProfitHit=1 or Hit=1) then begin
      Blost=High[0]-Dist;
      Blost1=High[0]-MinDist;
      //exitlong("TL0") Round(Cnt/2,0) contracts this bar at Blost stop;
      sell("TL0") Round(Cnt/2,0) contracts next bar at Blost stop;
   end;
   if MinDist > 0 and High[0]-Blost<Dist and High[0]<=Blost1 and Blost>Bcost
      and EntryTime(0)<time then begin
      //exitlong("TL1") Round(Cnt/2,0) contracts this bar at Blost stop;
      sell("TL1") Round(Cnt/2,0) contracts next bar at Blost stop;
   end;  
   if MinDist > 0 and High[0]-Blost<Dist and High[0]>Blost1 and Blost>Bcost
      and EntryTime(0)<time then begin
      //exitlong("TL2") Round(Cnt/2,0) contracts this bar at Blost1-Stpadjust stop;
      sell("TL2") Round(Cnt/2,0) contracts next bar at Blost1-Stpadjust stop;
   end;
   if MinDist > 0 and High[0]-Blost<Dist and High[0]>Blost1 and Blost>Bcost
      and EntryTime(0)<time and Close[0]<Blost1 then begin
      //exitlong("TL") Round(Cnt/2,0) contracts next bar at market;
      sell("TL") Round(Cnt/2,0) contracts next bar at market;
   end;
   if High > Bprice and HitProfit > 0 and ProfitHit = 0 then begin
      //exitlong("EL")  Round(Cnt/2,0) contracts total next bar at Market;
      sell("EL")  Round(Cnt/2,0) contracts total next bar at Market;
      ProfitHit = 1;
      isTrace2=1;
      Bprice=Bprice+IntPortion(HitProfit*Factor);
      PP=Close[0];
   end;
   if High > Bprice and HitProfit > 0 and ProfitHit = 1 then begin
      //exitlong("EL1")  Round(Cnt/2,0) contracts total next bar at Market;
      sell("EL1")  Round(Cnt/2,0) contracts total next bar at Market;
      ProfitHit = 2;
      PP=Close[0];
   end;   
   if isStop = 2 then begin//and Close > Bcost then
      //exitlong("XL2") all contracts next bar at market;
      sell("XL2") all contracts next bar at market;
      isLong=0;  isTrace=1; isShort=0;
      PP=Close[0];
   end;
   if High > BandH and Band > 0 and BandHit = 0 and ProfitHit = 1 then begin
      //exitlong("top") Round(balance/2,0) contract total next bar at market;
      sell("top") Round(balance/2,0) contract total next bar at market;
      BandHit = 1;
      PP=Close[0];
   end;
   if Turn2>=LineL2 and  Turn1<LineL1 and Line<>0 then begin
      //exitlong("EL3") Round(balance/2,0) contracts next bar at market;
      sell("EL3") Round(balance/2,0) contracts next bar at market;
      PP=Close[0];
      Hit=1;
   end;
   
end;


if isShort = 1 then begin
   balance=absvalue( CurrentContracts );
   if InitialStop > 0 and Slost=0 and Scost=0 then begin      
      Slost=EntryPrice(0) + InitialStop ;
      Scost=EntryPrice(0);
   end;   
   if Slost>Scost and EntryTime(0)=time then begin
      //exitshort("XS0") all contracts this bar at Slost+Stpadjust*2 stop;
      BuytoCover("XS0") all contracts next bar at Slost+Stpadjust*2 stop;
   end;
   if Slost>Scost and EntryTime(0)<time then begin
      //exitshort("XS1") all contracts this bar at Slost stop;
      BuytoCover("XS1") all contracts next bar at Slost stop;
   end;   
   if Slost>Scost and EntryTime(0)<time and Close[0]>Slost then begin
      //exitshort("XS") all contracts next bar at market;
      BuytoCover("XS") all contracts next bar at market;
   end;
   if BreakEven > 0 and Scost-Low[0]>BreakEven and Slost>Scost and EntryTime(0)<time then begin
      Slost=Scost-1 ;
      Slost1=Scost-1 ;
   end;
   if MinDist > 0 and Slost-Low[0]>Dist and Slost<Scost and EntryTime(0)<time
      and (balance=Cnt or ProfitHit=1 or Hit=1) then begin
      Slost=Low[0]+Dist ;
      Slost1=Low[0]+MinDist;
      //exitshort("TS0") Round(Cnt/2,0) contracts this bar at Slost stop;
      BuytoCover("TS0") Round(Cnt/2,0) contracts next bar at Slost stop;
   end;
   if MinDist > 0 and Slost-Low[0]<Dist and Low[0]>=Slost1 and Slost<Scost
      and EntryTime(0)<time then begin
      //exitshort("TS1") Round(Cnt/2,0) contracts this bar at Slost stop;
      BuytoCover("TS1") Round(Cnt/2,0) contracts next bar at Slost stop;
   end;
   if MinDist > 0 and Slost-Low[0]<Dist and Low[0]<Slost1 and Slost<Scost
      and EntryTime(0)<time then begin
      //exitshort("TS2") Round(Cnt/2,0) contracts this bar at Slost1+Stpadjust stop;
      BuytoCover("TS2") Round(Cnt/2,0) contracts next bar at Slost1+Stpadjust stop;
   end;
   if MinDist > 0 and Slost-Low[0]<Dist and Low[0]<Slost1  and Slost<Scost
      and EntryTime(0)<time and Close[0]>Slost1 then begin
      //exitshort("TS") Round(Cnt/2,0) contracts next bar at market;
      BuytoCover("TS") Round(Cnt/2,0) contracts next bar at market;
   end;
   if Low < Sprice and HitProfit > 0 and ProfitHit = 0 then begin
      //exitshort("ES") Round(Cnt/2,0) contracts total next bar at Market;
      BuytoCover("ES") Round(Cnt/2,0) contracts total next bar at Market;
      ProfitHit = 1;
      isTrace2=1;
      Sprice=Sprice-IntPortion(HitProfit*Factor);
      PP=Close[0];
   end;
   if Low < Sprice and HitProfit > 0 and ProfitHit = 1 then begin
      //exitshort("ES1") Round(Cnt/2,0) contracts total next bar at Market;
      BuytoCover("ES1") Round(Cnt/2,0) contracts total next bar at Market;
      ProfitHit = 2;
      PP=Close[0];
   end;
   if isStop = 1 then begin//and Close < Scost then
      //exitshort("XS2") all contracts next bar at market;
      BuytoCover("XS2") all contracts next bar at market;
      isShort=0;  isTrace=1; isLong=0;
      PP=Close[0];
   end;
   if Low < BandL and Band > 0 and BandHit = 0 and ProfitHit = 1 then begin
      //exitshort("bot") Round(balance/2,0) contract total next bar at market;
      BuytoCover("bot") Round(balance/2,0) contract total next bar at market;
      BandHit = 1;
      PP=Close[0];
   end;
   if Turn2<=LineH2 and  Turn1>LineH1 and Line<>0 then begin
      //exitshort("ES3") Round(balance/2,0) contracts next bar at market;
      BuytoCover("ES3") Round(balance/2,0) contracts next bar at market;
      PP=Close[0];
      Hit=1;
   end;
end;

//if Date=1090819 or Date=1090916 or Date=1091021 or Date=1091118 or Date=1091216 then  //Last Trading Day
//   TheEnd=132500  else TheEnd=134000  
//end if

if time>=TheEnd and DayTrade=1 then begin
   if CurrentContracts > 0 then begin
      //exitlong("end1") all contracts next bar at market;  
      sell("end1") all contracts next bar at market;  
      PP=Close[0];
   end;
   if CurrentContracts < 0 then begin
      //exitshort("end2") all contracts next bar at market;
      buytocover("end2") all contracts next bar at market;
      PP=Close[0];
   end;
end;   

if date=lastcalcdate and time=lastcalctime and output>0 then begin

   FileDelete( "R:\CurrentH"+numtostr(output,0)+".txt" );
   
//  if currentcontracts=0 then begin
   
//    fileappend("R:\CurrentH"+numtostr(output,0)+".txt",cdate(date)+" "+ctime(time)+","+
//    numtostr(currentcontracts,0)+","+numtostr(ExitPrice(0),0));  
  
//  end;

//  if currentcontracts!=0 then begin   
   
//    fileappend("R:\CurrentH"+numtostr(output,0)+".txt",cdate(date)+" "+ctime(time)+","+
//    numtostr(currentcontracts,0)+","+numtostr(PP,0));

//  end;

end;
 樓主| 發表於 10-10-18 22:55 | 顯示全部樓層
Inputs: Length(Numeric),ref(Numeric);

Variables:MAH1(0),MAL1(0),MAH2(0),MAL2(0),CAR1(0),CAR2(0),cur(0),nlast(0);

if Length>0 then begin

MAH1=AverageFC(High, Length)[0+ref];
MAL1=AverageFC(Low, Length)[0+ref];
CAR1=AverageFC((High+Low)/2, 1)[0+ref];
CAR2=AverageFC((High+Low)/2, 1)[1+ref];
MAH2=AverageFC(High, Length)[1+ref];
MAL2=AverageFC(Low, Length)[1+ref];

if CAR2 <= MAH2 and CAR1 > MAH1 then begin
      cur=1;
end;

if CAR2 >= MAL2 and CAR1 < MAL1 then begin
      cur=2;
end;

if cur <> nlast then begin
   nlast=cur;
   Stopped=nlast;
end   
else begin
   Stopped=0;
end;

end
else  begin
Stopped=0;
end;
 樓主| 發表於 10-10-18 22:55 | 顯示全部樓層
// Cross MA as Stopped2  
Inputs: Length(Numeric),car(Numeric),ref(Numeric);


Variables:MAH1(0),MAL1(0),MAH2(0),MAL2(0),CAR1(0),CAR2(0),cur(0),nlast(0),
          MA1(0),MA2(0);

if Length>0 and car>0 then begin

MAH1=AverageFC(High, Length)[0+ref];
MAL1=AverageFC(Low, Length)[0+ref];
CAR1=AverageFC((High+Low)/2, car)[0+ref];
CAR2=AverageFC((High+Low)/2, car)[1+ref];
MAH2=AverageFC(High, Length)[1+ref];
MAL2=AverageFC(Low, Length)[1+ref];

if CAR2 < MAL2 and CAR1 > MAL1 and cur=2 then begin
      nlast=0;
      cur=0;
      //return;
end;

if CAR2 > MAH2 and CAR1 < MAH1 and cur=1 then begin
      nlast=0;
      cur=0;
      //return;
end;


if CAR2 <= MAH2 and CAR1 > MAH1 then begin //UPCROSS
      cur=1;
end;

if CAR2 >= MAL2 and CAR1 < MAL1 then begin //DOWNCROSS
      cur=2;
end;

if cur <> nlast then begin
   nlast=cur;
   Stopped2=nlast;
end   
else begin
   Stopped2=0;
end;   

end
else  begin
Stopped2=0;
end;
 樓主| 發表於 10-10-18 22:55 | 顯示全部樓層
Inputs: Length(Numeric),car(Numeric),ref(Numeric);


Variables:MAH1(0),MAL1(0),MAH2(0),MAL2(0),CAR1(0),CAR2(0),cur(0),nlast(0);

if Length>0 and car>0 then begin
MAH1=AverageFC(High, Length)[0+ref];
MAL1=AverageFC(Low, Length)[0+ref];
CAR1=AverageFC((High+Low)/2, car)[0+ref];
CAR2=AverageFC((High+Low)/2, car)[1+ref];
MAH2=AverageFC(High, Length)[1+ref];
MAL2=AverageFC(Low, Length)[1+ref];

if CAR2 <= MAH2 and CAR1 > MAH1 then begin
      cur=1;
end;

if CAR2 >= MAL2 and CAR1 < MAL1 then begin
      cur=2;
end;

if cur <> nlast then begin
   nlast=cur;
   Crossed=nlast;
end   
else begin
   Crossed=0;
end;

end
else  begin
Crossed=0;
end;
 樓主| 發表於 10-10-18 22:57 | 顯示全部樓層
嘿嘿!原來可以 直接貼喔!
省事!

大家 加減參考啦!

阿! 福氣啦!!! 呼宜企啦!
殘殘 豆干 切8角。
發表於 10-10-18 23:44 | 顯示全部樓層
感謝分享!!

下載來學習學習!!
有問題再來請教!!
發表於 10-10-19 00:12 | 顯示全部樓層
trading144 大真是文思泉湧,沒點基礎還真無法改
謝啦
發表於 10-10-19 00:19 | 顯示全部樓層
感謝喔
趕快來研究
發表於 10-10-19 19:06 | 顯示全部樓層
trading144大   能分享hts寫好的程式嗎    謝謝
 樓主| 發表於 10-10-19 19:41 | 顯示全部樓層
回復 14# 052756


    這一位仁兄,你碼幫幫忙。

那個 倉位進出 那一行 有 被 // 的  就是 HTS 的 語法。
其他 多港款。

關於 時間 的數字表示 則 需要 多2個0,例如:1340--->134000
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

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

GMT+8, 24-5-9 02:05

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

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