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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值