Hi I want to set initial stopprice to a Swing Low value for longs. And then as usual. In other words have an additional initial requirement, where first CurrentLongStopPrice is set to SwingLow value
and then CurrentLongStopPrice is set to LongTrailStopDistance once price trigggers CurrentLongTriggerPrice. Is it possible?
LongTrailFrequency = 5;
-LongTrailStopDistance = -5;
-ShortTrailFrequency = -5;
ShortTrailStopDistance = 5;
LongProfitTargetTicks = 20;
ShortProfitTargetTicks = -20;
-CurrentLongTriggerPrice = 0;
-CurrentLongStopPrice = 0;
CurrentShortTriggerPrice = 0;
CurrentShortStopPrice = 0;
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
// Set 1
if (Position.MarketPosition == MarketPosition.Flat)
{
CurrentLongStopPrice = 0;
CurrentShortStopPrice = 0;
region trail area start
swinghlLong = Swing(5).SwingLow[1];
swinghlShort = Swing(5).SwingHigh[1];
#endregion
}
if (CurrentBars[0] < 1)
return;
// Set 2
if ((Position.MarketPosition == MarketPosition.Flat)
&& (State == State.Realtime)
&& (Close[0] > Open[0]))
{
CurrentLongTriggerPrice = (Close[0] + (LongTrailFrequency * TickSize)) ;
//CurrentLongStopPrice = (Close[0] + (LongTrailStopDistance * TickSize)) ;
CurrentLongStopPrice = swinghlLong;
EnterLong(Convert.ToInt32(DefaultQuantity), "");
}
// Set 3
if ((Position.MarketPosition == MarketPosition.Flat)
&& (State == State.Realtime)
&& (Close[0] < Open[0]))
{
CurrentShortTriggerPrice = (Close[0] + (ShortTrailFrequency * TickSize)) ;
CurrentShortStopPrice = (Close[0] + (ShortTrailStopDistance * TickSize)) ;
EnterShort(Convert.ToInt32(DefaultQuantity), "");
}
// Set 4
if ((Position.MarketPosition == MarketPosition.Long)
&& (Close[0] > CurrentLongTriggerPrice))
{
CurrentLongTriggerPrice = (Close[0] + (LongTrailFrequency * TickSize)) ;
CurrentLongStopPrice = (Close[0] + (LongTrailStopDistance * TickSize)) ;
}
// Set 5
if ((Position.MarketPosition == MarketPosition.Short)
&& (Close[0] < CurrentShortTriggerPrice))
{
CurrentShortTriggerPrice = (Close[0] + (ShortTrailFrequency * TickSize)) ;
CurrentShortStopPrice = (Close[0] + (ShortTrailStopDistance * TickSize)) ;
}
// Set 6
if (CurrentLongStopPrice != 0)
{
ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), CurrentLongStopPrice, "", "");
}
// Set 7
if (CurrentShortStopPrice != 0)
{
ExitShortStopMarket(Convert.ToInt32(DefaultQuantit y), CurrentShortStopPrice, "", "");
}
// Set 8
if ((Position.MarketPosition == MarketPosition.Long)
&& (Close[0] >= (Position.AveragePrice + (LongProfitTargetTicks * TickSize)) ))
{
ExitLong(Convert.ToInt32(DefaultQuantity), @"Profit Long", "");
}
// Set 9
if ((Position.MarketPosition == MarketPosition.Short)
&& (Close[0] <= (Position.AveragePrice + (ShortProfitTargetTicks * TickSize)) ))
{
ExitShort(Convert.ToInt32(DefaultQuantity), @"ProfitShort", "");
}
}

Comment