|
F Mazandarany
2011-01-12 11:20:08
|
|
How does one introduce variables and their optimization in MM scripts. I want to optimize variables "b", and "c" (lines 3 and 4) in the script below. I tried using the optimize function under strategy, it did not work.
string symbolLong = "spy";
string symbolShort = "^GSPC";
string rule1 = "a = close > sma(200)*b;";
string rule2 = "a = close < sma(200)*c;";
TimeSeries buy = Data.ParseFormula(rule1).GetTimeSeries(symbolLong, "a");
TimeSeries sell = Data.ParseFormula(rule2).GetTimeSeries(symbolLong, "a");
if(buy[0] > 0)
{
if(!Portfolio.IsInPortfolio(symbolLong, true))
{
Functions.CloseAllPositions(0);
Portfolio.UpdateCategorySettings("short", 0, 1, null);
Portfolio.UpdateCategorySettings("long", 100, 1, null);
Functions.AddLongPosition(symbolLong, null);
}
}
else if(sell[0] > 0)
{
if(!Portfolio.IsInPortfolio(symbolShort, false))
{
Functions.CloseAllPositions(0);
Portfolio.UpdateCategorySettings("long", 0, 1, null);
Portfolio.UpdateCategorySettings("short", 100, 1, null);
Functions.AddShortPosition(symbolShort, null);
}
}
if(Variables.IsVariableExists("equity"))
{
double equity = (double)Variables.GetVariable("equity");
double roc = Math.Round(((Portfolio.Equity / equity) - 1) * 100, 4);
string text = Divers.CurrentDate.ToString() + (char)Keys.Tab + roc;
Variables.SetVariable("output", Variables.GetVariable("output") + Environment.NewLine + text);
}
else
{
Variables.SetVariable("output", "");
}
Variables.SetVariable("equity", Portfolio.Equity);
|
|