Back

C# FOREX MACD handling & short selling in forex

Hi guys, i am new but i am overwhlem by how great Quantconnect with VS is !!

previously was using QC web.. didn't get use to doing coding in browser... everything was slow and looking at documentation/classes/methods/interfiles is a hassles.

i need some help understanding how to handle MACD 

public override void Initialize()
        {

            foreach (var ForexPair in _pairs)
            {
                _symbols.Add(AddForex(ForexPair, Resolution.Minute, "OANDA", leverage: _leverage).Symbol);
                _macd = MACD(ForexPair, 12, 26, 9, MovingAverageType.Exponential, Resolution.Minute);
                _macdDic.Add(ForexPair, _macd); //MACD value is return here.

            }
}

  public override void OnData(Slice data)
        {

foreach (string ForexPair in _symbols) //as you can see i have many forexpairs.
                    {

                        var tolerance = 0.0025m;
 

                        Debug(_macd[ForexPair].Histogram); << doing this will give me error. how do i access different forex pairs _macd values?
                        Debug(_macdDic[ForexPair]); << while this is ok as MACD return values is already store d in Initialize()

 }
}

 

as for shortselling in forex how do i do it correctly

X = "EURUSD" // etc etc

 

  SetHoldings(X, 0.01); //execute buy by pecentage

var s = Securities[X].Holdings;

below are 2 method to sell or close.

 Liquidate(X); //execute close << this is ok

MarketOrder(X, s.Quantity);  <<< this is not working correctly for me any idea...

i would like MarketOrder to work as this can close partial trade quantity, doing a reversal trade as well etc.. more flexible.

 

thanks for reading.

Update Backtest







0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hey Tham1606,

Debug(_macd[ForexPair].Histogram);

_macd is the indicator, while _macdDic is the dictionary of indicators. We should instead use _macdDic[ForexPair].Histogram.

We can submit sell orders and short orders by using negative quantities in our orders. If we sell more shares than we have, then we are in a short position.

MarketOrder(X, -s.Quantity)

Learn more in the documentation on Trading and Orders.

Best
Rahul

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed