Profile Picture

Indicators Previous Day Value

Posted By ywlee 3 Years Ago
Message
Posted Monday January 06 2014
Hi

How do you call the previous day value of an indicator eg. the previous day value for SMA 50?

When I attempted to use SMA50.LookBack(1) it gave an error as it was expecting a value of 0.


phg
Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)
Posted Monday January 06 2014
Offhand, how many lead bars were provided?

-Pete

See also Yahoo group about applying RE.

Posted Sunday January 12 2014
Hi Pete

What do you mean by lead bars?

I have downloaded the bar data for the whole year 2013 for the underlying instrument

Also I have defined SMA as new SMA(50)

Thanks in advance
Posted Sunday January 12 2014
Hi Pete

I have attached the code for reference:

public class MySymbolScript : MySymbolScriptBase
{
// Class variables


SMA SMA50;

public override void Startup()
{
// Initialize
SystemParameters param = SystemData.SystemParameters;
//_williamsR = new WilliamsPctR(14);

SMA50 = new SMA(50);
SMA50.SetInputs(Close);
SMA50.ChartSettings.Color = Color.Blue;


}
public override void NewBar()
{


// Process each new bar
if (!SystemData.InLeadBars)
{
IList pos = SystemData.PositionManager.GetOpenPositions(Symbol);

{
if (SMA50.Current > SMA50.LookBack(1))

{
TradingSystem.OpenPosition(Symbol, PositionType.Long, OrderType.MarketOnOpen); // Buy
}

}

}



}
public override void OrderFilled(Position position, Trade trade)
{
// This method is called when an order is filled

}

public override void OrderCancelled(Position position, Order order, string information)
{
// This method is called when an order is cancelled or rejected
if (!order.CancelPending)
{
OutputWarning("Unexpected order cancel: " + order.ToString() + " " + information);
}
}
}
phg
Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)
Posted Sunday January 12 2014
Hi ywlee,

Good start. The code looks pretty good so far.

See View(tab on tool bar) -> Properties Window -> Simulation -> Lead Bars.
[Alternatively you can do something like this immediately under NewBar()
if (Bars.Count < 50) return; // Wait for 50 bars pass in order to compute a valid SMA(50)]

The SMA is not valid until there is data for 50 bars, so you don't want your methods called until 50 bars have passed. That's what lead bars are: that initial period where your methods are not called or processed until there is enough data for the indicators that are used to become valid.


-Pete

See also Yahoo group about applying RE.

Posted Sunday January 12 2014
Hi Pete

Thanks for the same.

The problem is when I try to run the simulation, I get the following error:

An exception of type System.ArgumentOutOfRangeException was thrown.
Value must be between 0 and 0, value was 1
Parameter name: nBars
at RightEdge.Common.RList`1.LookBack(Int32 nBars)
at MySymbolScript.NewBar() in z:\RightEdge\SMA50\NautilusV1.cs:line 55
at RightEdge.Common.SymbolScriptCollection`1.NewBar()
at MySystemBase.NewBar() in z:\RightEdge\SMA50\BaseClasses.cs:line 31
at RightEdge.Common.Internal.SystemRunner.CallSystemNewBar(FrequencyNewBarEventArgs args)
at RightEdge.Common.Internal.SystemRunner.ProcessBarEvents(IEnumerable`1 eventList)
at RightEdge.Common.FrequencyManager.SendPendingBars()
at RightEdge.Common.FrequencyManager.UpdateTime(DateTime dateTime)
at RightEdge.Common.Internal.SystemRunner._tickGenerator_NewBar(Object sender, NewBarEventArgs e)
at RightEdge.Common.TickGenerator.ProcessBar(NewBarEventArgs args)
at RightEdge.Common.Internal.SystemRunner.ProcessBar(NewBarEventArgs newBars)
at RightEdge.Shared.SystemWrapper.RunSystem(SystemData systemData, SharedSystemRunData runData, ServiceFactory brokerFactory)
at RightEdge.Shared.SystemWrapper.RunSystem(String filename, ServiceFactory brokerFactory, PluginSettings dataStoreSettings)
at RightEdge.Shared.SystemWrapper.RunSystem(String filename, ServiceFactory brokerFactory, PluginSettings dataStoreSettings)
at RightEdge.Shared.TradingModuleWrapper.Run(String filename)
at RightEdge.Shared.TradingModuleWrapper.RunSystem(SharedSystemRunData systemRunData)
at RightEdge.SystemProgress.InitAndRunSystem()


The error log seems to suggest that calling SMA50.LookBack(1) is not valid as its expecting a value of 0 (ie only SMA50.LookBack(0) is valid). Tried will other indicators as well and got the same error.
phg
Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)Supreme Being (48,349 reputation)
Posted Sunday January 12 2014
How many lead bars are specified?

-Pete

See also Yahoo group about applying RE.

Posted Monday January 13 2014
Try something like this for your condition:

if (SMA50.Count >= 2 && SMA50.Current > SMA50.LookBack(1))

IE make sure there are at least 2 bars total before trying to look at the previous one.

Thanks,
Daniel
Posted Monday January 13 2014
Dear Daniel

Thanks! That worked.

On a separate question, how do I compare the current close with the PriceChannelUpper given that the PriceChannelUpper does not accept SetInputs.Close as an argument?

eg. Close.Current = PriceUp.LookBack(1)? // After having defined PriceChannelUpper as PriceUp

Posted Monday January 13 2014
HI Daniel

I resolved it using SystemUtilities.Crossover

Thanks!


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems