I am testing the Larry Williams formula for entry strategy of
following:
Larry Williams Formula
Inputs: Length(16),
PH( ( ( (H+L+C) / 3) * 0) - L),
PL( ( ( (H+L+C) / 3) * 0) - H);
But is not working. Can anybody help to find out
what is wrong.
Thank you very much.
#region Variables
private DataSeries williamPH ;
private double william_PH_highestValue = 0;
protected override void Initialize()
{
williamPH = new DataSeries(this);
CalculateOnBarClose = true;
}
protected override void OnBarUpdate()
{
//LONG CRITERIA
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss("PositionLong1",CalculationMode.Ticks, 20,false);
SetProfitTarget("PositionLong1",CalculationMode.Ti cks, 10000);
}
// Resets the highest high at the start of every new session
if (Bars.FirstBarOfSession)
williamPH[0]= ( ( ( (High[0]+Low[0]+Close[0]) / 3) * Open[0]) - Low[0]);
// Stores the highest high from the first 16 bars
if (Bars.BarsSinceSession < 16
&& williamPH[0] >William_PH_highestValue )
{
William_PH_highestValue = williamPH[0];
}
// Entry Condition: Submit a buy stop order one tick above the first 30 bar high. Cancel if not filled within 34 bars.
if (Bars.BarsSinceSession > 16 && Bars.BarsSinceSession < 50
&&Position.MarketPosition == MarketPosition.Flat)
{
EnterLongStop(DefaultQuantity, William_PH_highestValue+2*TickSize,"PositionLong1" );
InitialStopPrice = Low[1]-100*TickSize;
ProTarget =2.5*( InitialStopPrice);
SetStopLoss("PositionLong1", CalculationMode.Price, initialStopPrice, false);
SetProfitTarget("PositionLong1", CalculationMode.Price, ProTarget);
}
}
Comment