Work on Bollinger Bands.
This commit is contained in:
@@ -15,16 +15,18 @@ namespace TradeBlotter.Model
|
|||||||
private GainLossModel()
|
private GainLossModel()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
public static CompositeDataSource CreateCompositeDataSource(DateTime xSource,double ySource)
|
|
||||||
{
|
//public static CompositeDataSource CreateCompositeDataSource(DateTime xSource,double ySource)
|
||||||
CompositeDataSource compositeDataSource;
|
//{
|
||||||
var xData=new EnumerableDataSource<DateTime>(new DateTime[] { xSource });
|
// CompositeDataSource compositeDataSource;
|
||||||
xData.SetXMapping(x => (x.Ticks/10000000000.0));
|
// var xData=new EnumerableDataSource<DateTime>(new DateTime[] { xSource });
|
||||||
var yData=new EnumerableDataSource<double>(new double[] { ySource });
|
// xData.SetXMapping(x => (x.Ticks/10000000000.0));
|
||||||
yData.SetYMapping(y => y);
|
// var yData=new EnumerableDataSource<double>(new double[] { ySource });
|
||||||
compositeDataSource=xData.Join(yData);
|
// yData.SetYMapping(y => y);
|
||||||
return compositeDataSource;
|
// compositeDataSource=xData.Join(yData);
|
||||||
}
|
// return compositeDataSource;
|
||||||
|
//}
|
||||||
|
|
||||||
public static CompositeDataSource Price(Price price)
|
public static CompositeDataSource Price(Price price)
|
||||||
{
|
{
|
||||||
if (null == price) return null;
|
if (null == price) return null;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace TradeBlotter.Model
|
|||||||
private StopLimitCompositeModel()
|
private StopLimitCompositeModel()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CompositeDataSource CreateCompositeDataSource(StopLimits stopLimits)
|
public static CompositeDataSource CreateCompositeDataSource(StopLimits stopLimits)
|
||||||
{
|
{
|
||||||
if(null==stopLimits) return null;
|
if(null==stopLimits) return null;
|
||||||
@@ -25,5 +26,22 @@ namespace TradeBlotter.Model
|
|||||||
compositeDataSource=xData.Join(yData);
|
compositeDataSource=xData.Join(yData);
|
||||||
return compositeDataSource;
|
return compositeDataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CompositeDataSource CreateCompositeDataSource(DateTime xSource,StopLimits stopLimits)
|
||||||
|
{
|
||||||
|
if(null==stopLimits) return null;
|
||||||
|
CompositeDataSource compositeDataSource;
|
||||||
|
List<DateTime> stopLimitDates = new List<DateTime>();
|
||||||
|
foreach(StopLimit stopLimit in stopLimits)
|
||||||
|
{
|
||||||
|
stopLimitDates.Add(stopLimit.EffectiveDate);
|
||||||
|
}
|
||||||
|
var xData=new EnumerableDataSource<DateTime>(stopLimitDates.Select(x => x.Date));
|
||||||
|
xData.SetXMapping(x => (x.Ticks/10000000000.0));
|
||||||
|
var yData=new EnumerableDataSource<double>(stopLimits.Select(y => y.StopPrice));
|
||||||
|
yData.SetYMapping(y => y);
|
||||||
|
compositeDataSource=xData.Join(yData);
|
||||||
|
return compositeDataSource;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace TradeBlotter.ViewModels
|
|||||||
private static readonly String BAND_MESSAGE="Generating Bollinger Band...";
|
private static readonly String BAND_MESSAGE="Generating Bollinger Band...";
|
||||||
private static readonly String DATA_MESSAGE="Loading Pricing Data...";
|
private static readonly String DATA_MESSAGE="Loading Pricing Data...";
|
||||||
private BollingerBands bollingerBands;
|
private BollingerBands bollingerBands;
|
||||||
private StopLimit stopLimit; // This is the stop limit that is looked up in the database and displayed (if there is one)
|
private StopLimits internalStopLimits; // This is the stop limit that is looked up in the database and displayed (if there is one)
|
||||||
private StopLimits stopLimits; // These stop limits might be passed in with the SaveParams. (i.e.) MMTRend model passes in StopLimits. If these are passsed in then they are displayed instead of stopLimit.
|
private StopLimits stopLimits; // These stop limits might be passed in with the SaveParams. (i.e.) MMTRend model passes in StopLimits. If these are passsed in then they are displayed instead of stopLimit.
|
||||||
private String symbol;
|
private String symbol;
|
||||||
private String companyName;
|
private String companyName;
|
||||||
@@ -220,7 +220,7 @@ namespace TradeBlotter.ViewModels
|
|||||||
prices=null;
|
prices=null;
|
||||||
portfolioTrades=null;
|
portfolioTrades=null;
|
||||||
portfolioTradesLots=null;
|
portfolioTradesLots=null;
|
||||||
stopLimit=null;
|
internalStopLimits=null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventArgs.PropertyName.Equals("SyncTradeToBand")||
|
if (eventArgs.PropertyName.Equals("SyncTradeToBand")||
|
||||||
@@ -238,7 +238,7 @@ namespace TradeBlotter.ViewModels
|
|||||||
BusyContent=DATA_MESSAGE;
|
BusyContent=DATA_MESSAGE;
|
||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
stopLimit=StopLimitDA.GetStopLimit(symbol);
|
internalStopLimits=StopLimitDA.GetStopLimits(symbol);
|
||||||
portfolioTrades = PortfolioDA.GetTradesSymbol(symbol);
|
portfolioTrades = PortfolioDA.GetTradesSymbol(symbol);
|
||||||
portfolioTradesLots=LotAggregator.CombineLots(portfolioTrades);
|
portfolioTradesLots=LotAggregator.CombineLots(portfolioTrades);
|
||||||
if (null != portfolioTrades && 0 != portfolioTrades.Count)
|
if (null != portfolioTrades && 0 != portfolioTrades.Count)
|
||||||
@@ -442,9 +442,9 @@ namespace TradeBlotter.ViewModels
|
|||||||
{
|
{
|
||||||
compositeDataSourceStopLimit=StopLimitCompositeModel.CreateCompositeDataSource(stopLimits);
|
compositeDataSourceStopLimit=StopLimitCompositeModel.CreateCompositeDataSource(stopLimits);
|
||||||
}
|
}
|
||||||
else if(null!=stopLimit && null!=zeroPrice)
|
else if(null!=internalStopLimits && null!=zeroPrice)
|
||||||
{
|
{
|
||||||
compositeDataSourceStopLimit=GainLossModel.CreateCompositeDataSource(zeroPrice.Date,stopLimit.StopPrice);
|
compositeDataSourceStopLimit=StopLimitCompositeModel.CreateCompositeDataSource(zeroPrice.Date,stopLimits);
|
||||||
}
|
}
|
||||||
|
|
||||||
compositeDataSourceInsiderTransactionPointDisposedSmall=InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(disposedSummariesBin[2]),minClose);
|
compositeDataSourceInsiderTransactionPointDisposedSmall=InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(disposedSummariesBin[2]),minClose);
|
||||||
@@ -784,19 +784,43 @@ namespace TradeBlotter.ViewModels
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(null==zeroPrice)return null;
|
if (null == zeroPrice) return null;
|
||||||
if(null==stopLimit||null==zeroPrice||!showTradeLabels) return null;
|
if (null == internalStopLimits || null == zeroPrice || !showTradeLabels) return null;
|
||||||
CenteredTextMarker centerTextMarker=new CenteredTextMarker();
|
for(int index=0;index<internalStopLimits.Count;index++)
|
||||||
Price latestPrice=prices[0];
|
{
|
||||||
double percentOffsetFromLow=((latestPrice.Low-stopLimit.StopPrice)/stopLimit.StopPrice);
|
StopLimit limit=internalStopLimits[index];
|
||||||
StringBuilder sb=new StringBuilder();
|
CenteredTextMarker centerTextMarker=new CenteredTextMarker();
|
||||||
sb.Append(stopLimit.StopType).Append(" ");
|
|
||||||
sb.Append(Utility.FormatCurrency(stopLimit.StopPrice));
|
StringBuilder sb=new StringBuilder();
|
||||||
sb.Append(" (").Append(percentOffsetFromLow>0?"+":"").Append(Utility.FormatPercent(percentOffsetFromLow)).Append(")");
|
sb.Append(limit.StopType).Append(" ");
|
||||||
centerTextMarker.Text=sb.ToString();
|
sb.Append(Utility.FormatCurrency(limit.StopPrice));
|
||||||
centeredTextMarkers.Add(centerTextMarker);
|
if(index==internalStopLimits.Count-1)
|
||||||
centerTextMarker.VerticalShift="40";
|
{
|
||||||
centerTextMarker.HorizontalShift="32";
|
Price latestPrice=prices[0]; // always use the most recent price when calculating the spread (in percent) from the active stop limit.
|
||||||
|
double percentOffsetFromLow=((latestPrice.Low-limit.StopPrice)/limit.StopPrice);
|
||||||
|
sb.Append(" (").Append(percentOffsetFromLow>0?"+":"").Append(Utility.FormatPercent(percentOffsetFromLow)).Append(")");
|
||||||
|
}
|
||||||
|
centerTextMarker.Text=sb.ToString();
|
||||||
|
if(0==index&&internalStopLimits.Count>1) centerTextMarker.VerticalShift="25";
|
||||||
|
else centerTextMarker.VerticalShift="40";
|
||||||
|
centerTextMarker.HorizontalShift="32";
|
||||||
|
centeredTextMarkers.Add(centerTextMarker);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//CenteredTextMarker centerTextMarker=new CenteredTextMarker();
|
||||||
|
//Price latestPrice=prices[0];
|
||||||
|
//double percentOffsetFromLow=((latestPrice.Low-stopLimit.StopPrice)/stopLimit.StopPrice);
|
||||||
|
//StringBuilder sb=new StringBuilder();
|
||||||
|
//sb.Append(stopLimit.StopType).Append(" ");
|
||||||
|
//sb.Append(Utility.FormatCurrency(stopLimit.StopPrice));
|
||||||
|
//sb.Append(" (").Append(percentOffsetFromLow>0?"+":"").Append(Utility.FormatPercent(percentOffsetFromLow)).Append(")");
|
||||||
|
//centerTextMarker.Text=sb.ToString();
|
||||||
|
//centeredTextMarkers.Add(centerTextMarker);
|
||||||
|
//centerTextMarker.VerticalShift="40";
|
||||||
|
//centerTextMarker.HorizontalShift="32";
|
||||||
}
|
}
|
||||||
return centeredTextMarkers.ToArray();
|
return centeredTextMarkers.ToArray();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user