I have a short position x1 of an index Futures, and trying to use "CurrentPosition.Side == EMarketPositionSide.Short" condition to assign a variable to when a short position is opened. However, it appears that the scripts did not run the statement for this condition when I already have a short position opened (did not print the "testing").
Please advise if the following coding is correct, or is there another way to do it? (I am building a spread trading strategy - Long A and Short B simultaneously once the conductions are met, hence I need to pass some variable when A has been shorted / B has been longed for global variables)
....
protected override void Create() {
short_order = OrderCreator.Limit(new SOrderParameters(Contracts.Default, EOrderAction.SellShort));
}
protected override void StartCalc() {
Output.Clear();
}
protected override void CalcBar(){
...
if(CurrentPosition.Side == EMarketPositionSide.Short)
{
int testing = -1;
Output.WriteLine("{0}",testing);
}
CurrentPosition.Side == EMarketPositionSide.Short
-
- Posts: 21
- Joined: Mar 08 2021
- Been thanked: 1 time
I was thinking about using "StrategyInfo.MarketPosition < 0" but it will not work as both short A and long B will net off the StrategyInfo.MarketPosition which will become 0
- Tammy MultiCharts
- Posts: 200
- Joined: Aug 06 2020
- Has thanked: 6 times
- Been thanked: 65 times
Hello lewisthegood,
Please check the code sample below that might help you achieve your goal.
Please check the code sample below that might help you achieve your goal.
Code: Select all
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
namespace PowerLanguage.Strategy
{
public class _Test_ : SignalObject
{
public _Test_(object _ctx):base(_ctx){}
private IOrderPriced short_order;
protected override void Create() {
short_order = OrderCreator.Limit(new SOrderParameters(Contracts.Default, EOrderAction.SellShort));
}
protected override void StartCalc() {
Output.Clear();
}
protected override void CalcBar()
{
if (Bars.CurrentBar == 10)
short_order.Send(Bars.Close[0] - 10.0);
Output.WriteLine("BarUpdateTime: {0}", Bars.BarUpdateTime);
if(CurrentPosition.Side == EMarketPositionSide.Short)
{
int testing = -1;
Output.WriteLine("{0}",testing);
}
}
}
}