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();
}
}
}
}