I am new to programing in general and ask for your patience.
I was able to get my setprofittarget and breakeven working. However, the setstoploss is placing my stop 1000 pts away from my intended location.
Calulationmode.OnEachTick
here is my code:
if (BarsInProgress == 0)
{
EntryLong = (High[1] + 1 * TickSize);
//Enter Long
if (SignalLong[0] == 2 && Close[0] > EMA1[0] && ADX1[0] > 25 && EntryLong >= GetCurrentAsk())
{
BreakEvenTrigger = true;
EnterLongStopMarket(Convert.ToInt32(DefaultQuantit y), EntryLong, "Long1");
EnterLongStopMarket(Convert.ToInt32(DefaultQuantit y), EntryLong, "Long2");
SetStopLoss("Long1", CalculationMode.Ticks, Low[1] - StopPrice1, false);
SetStopLoss("Long2", CalculationMode.Ticks, Low[1] - StopPrice2, false);
}
else if (SignalLong[0] == 2 && Close[0] > EMA1[0] && ADX1[0] > 25 && EntryLong < GetCurrentAsk())
{
BreakEvenTrigger = true;
EnterLongLimit(Convert.ToInt32(DefaultQuantity), EntryLong, "Long1");
EnterLongLimit(Convert.ToInt32(DefaultQuantity), EntryLong, "Long2");
SetStopLoss("Long1", CalculationMode.Ticks, Low[1] - StopPrice1, false);
SetStopLoss("Long2", CalculationMode.Ticks, Low[1] - StopPrice2, false);
}
EntryShort = (Low[1] - 1 * TickSize);
//Enter Short
if (SignalShort[0] == -2 && Close[0] < EMA1[0] && ADX1[0] > 25 && EntryShort <= GetCurrentBid())
{
BreakEvenTrigger = true;
EnterShortStopMarket(Convert.ToInt32(DefaultQuanti ty), EntryShort, "Short1");
EnterShortStopMarket(Convert.ToInt32(DefaultQuanti ty), EntryShort, "Short2");
SetStopLoss("Short1", CalculationMode.Ticks, High[1] + StopPrice1, false);
SetStopLoss("Short2", CalculationMode.Ticks, High[1] + StopPrice2, false);
}
else if (SignalShort[0] == -2 && Close[0] < EMA1[0] && ADX1[0] > 25 && EntryShort > GetCurrentBid())
{
BreakEvenTrigger = true;
EnterShortLimit(Convert.ToInt32(DefaultQuantity), EntryShort, "Short1");
EnterShortLimit(Convert.ToInt32(DefaultQuantity), EntryShort, "Short2");
SetStopLoss("Short1", CalculationMode.Ticks, High[1] + StopPrice1, false);
SetStopLoss("Short2", CalculationMode.Ticks, High[1] + StopPrice2, false);
}
}
if (Position.MarketPosition == MarketPosition.Flat)
{
BreakEvenTrigger = true;
SetStopLoss("Long1", CalculationMode.Ticks, Low[1] - StopPrice1, false);
SetStopLoss("Long2", CalculationMode.Ticks, Low[1] - StopPrice2, false);
SetStopLoss("Short1", CalculationMode.Ticks, High[1] + StopPrice1, false);
SetStopLoss("Short2", CalculationMode.Ticks, High[1] + StopPrice2, false);
}
if (Position.MarketPosition == MarketPosition.Long && BreakEvenTrigger)
{
if (Close[0] >= Position.AveragePrice + (BreakEven * TickSize))
{
SetStopLoss("Long2", CalculationMode.Price, Position.AveragePrice + 1 * TickSize, false);
BreakEvenTrigger = false;
}
}
if (Position.MarketPosition == MarketPosition.Short && BreakEvenTrigger)
{
if (Close[0] <= Position.AveragePrice - (BreakEven * TickSize))
{
SetStopLoss("Short2", CalculationMode.Price, Position.AveragePrice - 1 * TickSize, false);
BreakEvenTrigger = false;
}
}
}
however when I am on live trading this is the stop loss that was placed (highlighted).
how can I fix this?
2) If I want to set my stop loss at the lowest of the preceding 3 bars do I just use "Lowestbar(3) + 1 * TickSize" instead?
Comment