我是靠谱客的博主 多情学姐,最近开发中收集的这篇文章主要介绍MC- 挂单STOP交易,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

using  System;
using  System.Drawing;
using  System.Linq;
using  PowerLanguage.Function;
using  ATCenterProxy.interop;
 
namespace  PowerLanguage.Strategy
{
     public  class  Example_StopLimit : SignalObject
     {
         private  IOrderMarket buyMarketOrder, sellMarketOrder;
         private  IOrderStopLimit sellStopLimitOrder;
         private  double  sellStopPrice, sellLimitPrice;
 
         public  Example_StopLimit( object  _ctx) :  base (_ctx) { }
 
         protected  override  void  Create()
         {
             buyMarketOrder = OrderCreator.MarketNextBar( new  SOrderParameters(
                 Contracts.Default,  "EnterLong" , EOrderAction.Buy));
 
             sellMarketOrder = OrderCreator.MarketNextBar( new  SOrderParameters(
                 Contracts.Default,  "ExitLong" , EOrderAction.Sell));
 
             sellStopLimitOrder = OrderCreator.StopLimit( new  SOrderParameters(
                 Contracts.Default,  "StopLMT" , EOrderAction.Sell));
         }
 
         protected  override  void  StartCalc()
         {
             Output.Clear();  // Clear PowerLanguage Editor output tab
         }
 
         protected  override  void  CalcBar()
         {
             // When flat, enter long on first bar of day
             if  ((StrategyInfo.MarketPosition == 0) && (Bars.Time[0].Date != Bars.Time[1].Date))
             {
                 buyMarketOrder.Send();
 
                 sellStopPrice  = Bars.Low[0] - Bars.Range();
                 sellLimitPrice = Bars.Low[0] - (Bars.Range() * 1.5);
 
                 Output.WriteLine( "{0} - Buy order submitted. Sell stop calculated @ {1} with limit {2}" ,
                     Bars.Time[0].ToString( "d-M HH:mm:ss" ),
                     sellStopPrice,
                     sellLimitPrice);
             }
 
             // Long order management
             if  (StrategyInfo.MarketPosition > 0)
             {
                 // Submit the stop-limit order as long as there is an open position
                 sellStopLimitOrder.Send(sellStopPrice, sellLimitPrice);
 
                 Output.WriteLine( "{0} - Submitting sell stop @ {1} with limit {2}" ,
                     Bars.Time[0].ToString( "d-M HH:mm:ss" ),
                     sellStopPrice,
                     sellLimitPrice);
 
                 // Time stop; exit the position after 15 bars
                 double  barsInPosition = Bars.CurrentBar - CurrentPosition.OpenTrades[0].EntryOrder.BarNumber;
                 if  (barsInPosition >= 15)
                 {
                     sellMarketOrder.Send();
 
                     Output.WriteLine( "{0} - Position open for {1} bars, submitting exit long market order" ,
                         Bars.Time[0].ToString( "d-M HH:mm:ss" ),
                         barsInPosition);
                 }
             }
         }
     }
}

 

转载于:https://www.cnblogs.com/aliblogs/p/5493822.html

最后

以上就是多情学姐为你收集整理的MC- 挂单STOP交易的全部内容,希望文章能够帮你解决MC- 挂单STOP交易所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(36)

评论列表共有 0 条评论

立即
投稿
返回
顶部