開拓者隨機發買賣單的模型源碼[開拓者公式]
- 思路: 投資學里經典的一句話 - 限制損失,讓盈利奔跑。只要盈虧比達到一個理想的值,那勝率低也一樣能賺到錢。為了驗證這個理論,我寫了一個隨機發買賣單的模型,并且限制每次損失的上限,對盈利進行追蹤止損。模型為日內交易,每3分鐘發一個單。
- 源碼:(程序化交易網 m.kzuj.com.cn 轉載請保留出處)
- Params
- Numeric InitialStop(2);
- Numeric BreakEvenStop(3);
- Numeric TrailStop(5);
- Vars
- Numeric RandNum;
- Numeric BuyOrSell;
- Numeric StopLine;
- Numeric MyEntryPrice;
- Numeric MyExitPrice;
- NumericSeries HighestAfterEntry;
- NumericSeries LowestAfterEntry;
- Begin
- If(Time>=0.1455){//如果要實盤測試,把Time改為CurrentTime
- If(MarketPosition == 1)
- Sell(0,Close);
- If(MarketPosition == -1)
- BuyToCover(0,Close);
- return;
- }
- If(BarsSinceentry == 0)
- {
- HighestAfterEntry = Close;
- LowestAfterEntry = Close;
- If(MarketPosition <> 0)
- {
- HighestAfterEntry = Max(HighestAfterEntry,AvgEntryPrice);
- LowestAfterEntry = Min(LowestAfterEntry,AvgEntryPrice);
- }
- }else
- {
- HighestAfterEntry = Max(HighestAfterEntry,High);
- LowestAfterEntry = Min(LowestAfterEntry,Low);
- }
- Commentary("HighestAfterEntry="+Text(HighestAfterEntry)); Commentary("LowestAfterEntry="+Text(LowestAfterEntry));
- MyEntryPrice = AvgEntryPrice;
- If(MarketPosition==1) // 有多倉的情況( m.kzuj.com.cn )
- {
- StopLine = AvgEntryPrice * (1-InitialStop/1000);
- If(HighestAfterEntry[1] >= MyEntryPrice *(1 + BreakEvenStop/1000))
- Stopline = MyEntryPrice;
- If(Stopline < HighestAfterEntry[1]*(1 - TrailStop/1000))
- Stopline = HighestAfterEntry[1]*(1 - TrailStop/1000);
- if(Low <= Stopline)
- {
- MyExitPrice = Stopline;
- If(Open < MyExitPrice) MyExitPrice = Open; // 如果該Bar開盤價有跳空觸發,則用開盤價代替
- Sell(0,MyExitPrice);
- return;
- }
- }else if(MarketPosition==-1) // 有空倉的情況
- {
- StopLine = AvgEntryPrice * (1+InitialStop/1000);
- If(LowestAfterEntry[1] <= MyEntryPrice *(1 - BreakEvenStop/1000))
- Stopline = MyEntryPrice;
- If(Stopline > LowestAfterEntry[1]*(1 + TrailStop/1000))
- Stopline = LowestAfterEntry[1]*(1 + TrailStop/1000);
- Commentary("StopLine="+Text(Stopline));
- If(High >= Stopline)
- {
- MyExitPrice = Stopline;
- If(Open > MyExitPrice) MyExitPrice = Open; // 如果該Bar開盤價有跳空觸發,則用開盤價代替 來源 CXH99.COM
- BuyToCover(0,MyExitPrice);
- return;
- }
- }
- RandNum = Rand(0,100); //產生0到100的隨機數
- BuyOrSell = Mod(RandNum,2); //產生0到1的隨機數
- Commentary("BuyOrSell:"+TEXT(BuyOrSell));
- If(BuyOrSell == 0 && Mod(Minute,3) == 0 && MarketPosition!= -1) //如果BuyOrSell為0,每3分鐘發一次多單
- Buy(1,Close);
- else If(BuyOrSell == 1 && Mod(Minute,3) == 0 && MarketPosition!=1)//如果BuyOrSell為1,每3分鐘發一次空單
- SellShort(1,Close);
- End
有思路,想編寫各種指標公式,程序化交易模型,選股公式,預警公式的朋友
可聯系技術人員 QQ: 262069696 進行 有償 編寫!(不貴!點擊查看價格!)
相關文章
-
沒有相關內容