IStrategyPerformance.ConvertCurrency Method Help  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
bdwg
Posts: 5
Joined: 27 Jan 2018
Has thanked: 2 times

IStrategyPerformance.ConvertCurrency Method Help

Postby bdwg » 16 Mar 2018

Hey everyone,

I try hard to not ask for coding help because I learn so much more if I figure it out myself, but I have hit a wall. I really don't understand how to use Interfaces provided by MC. I am currently trying to write some code that will convert the the ATR (average true range) for a symbol that is in a foreign currency into the base strategy currency (USD in my case). To do this I am trying to use the IStrategyPerformance.ConvertCurrency Method.

I have learned a lot getting this far, and I am not sure if I am using the IStrategyPerformance.ConvertCurrency Method correctly, but I have a signal code that does not get any compile errors, but it does get an Object reference not set to an instance of an object error when used in a chart. This error is being generated on line 45, the line where I try to do the currency conversion.

This is probably a lot to ask, but I am more than positive that I am just doing something fundamentally wrong, and if someone would look at my code and let me know what I am screwing up I would greatly appreciate it..

I tried to write a super clean, super short, long entry signal to make the code easier to read but still used generally in the way I plan on using it. The signal sends a buy signal when it reaches a new 50 bar high, before it sends the sell signal, it sends an output.writeline with the value of the converted ATR value at the time the sell signal was generated. I actually plan to use the converted ATR in position sizing, not just a write line, but this is easier to troubleshoot I would think.

Thanks!

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;

namespace PowerLanguage.Strategy {
public class BOD_Currency_LE : SignalObject
{

public BOD_Currency_LE(object _ctx):base(_ctx)
{
brkoutLength = 50;
atrEnterPos = 100;
}

private int brkoutLength;

private int atrEnterPos;

private double convertedATR;

private IOrderMarket longFutures_LE;

private IStrategyPerformance convertCurrency;


protected override void Create()
{
// create variable objects, function objects, order objects etc.

longFutures_LE = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.UserSpecified, "LONG", EOrderAction.Buy));
}

protected override void StartCalc()
{
// assign inputs

}

protected override void CalcBar()
{
// strategy logic

convertedATR = convertCurrency.ConvertCurrency(Bars.Time[0],StrategyCurrencyCode,Bars.Info.CurrencyCode,this.AverageTrueRange(atrEnterPos));

if (PublicFunctions.DoubleGreater(Bars.Close[0], Bars.Close.Highest(brkoutLength, 1)))
{

Output.WriteLine("Converted ATR: {0}", convertedATR);

longFutures_LE.Send();

}
}
}
}
ConCurr_LE.pln
(2.09 KiB) Downloaded 475 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: IStrategyPerformance.ConvertCurrency Method Help  [SOLVED]

Postby Henry MultiСharts » 19 Mar 2018

Hello bdwg,

You need to add the following line in StartCalc:
convertCurrency = StrategyInfo;

bdwg
Posts: 5
Joined: 27 Jan 2018
Has thanked: 2 times

Re: IStrategyPerformance.ConvertCurrency Method Help

Postby bdwg » 19 Mar 2018

You need to add the following line in StartCalc:
convertCurrency = StrategyInfo;
This Works!!!

Thank you!!

I would not have guessed that, and I couldn't find any documentation saying that. Is there somewhere I could have figured this out on my own? It would be good to know because I am sure I will have similar hangups with other interfaces in the future.


Return to “MultiCharts .NET”