I am having problems with the Strategy Limit orders submission... The thing is that I want to make 3 Entries with different names:
if ((Pattern) //Bullish Pattern
&& (Position.MarketPosition == MarketPosition.Flat)
&& (UseTimeRange ? Time[1].TimeOfDay >= Start.TimeOfDay : true) //Trade is taking place within specified time
&& (UseTimeRange ? Time[1].TimeOfDay <= End.TimeOfDay : true) //Trade is taking place within specified time
&& (UseTradeCount ? currentCount < MaxTradeCount : true)
&& (UseTimeRange ? dailyPnL > -DailyLossLimit : true) //Loss remains 'above' limit
&& (UseTimeRange ? dailyPnL < DailyProfitLimit : true) //Profit remains 'below' limit
///You will be able to enter 'short' after Profit/Stop from a long position. This just prevents entering right away in the same direction
&& (BarsSinceExitExecution("MyStopLong1") > 1 || BarsSinceExitExecution("MyStopLong1") == -1) //Needs 1 candle to enter Long again after being stopped from a long position.
&& (BarsSinceExitExecution("MyTargetLong1") > 1 || BarsSinceExitExecution("MyTargetLong1") == -1) //Needs 1 candle to enter Long again after hitting profit target from a long position.
)
{
if (ActiveTrade_1)
{
EnterLong(Convert.ToInt32(PositionSize1), "MyEntryLong1");
}
if (ActiveTrade_2)
{
EnterLong(Convert.ToInt32(PositionSize2), "MyEntryLong2");
}
if (ActiveTrade_3)
{
EnterLong(Convert.ToInt32(PositionSize3), "MyEntryLong3");
}
Then I code the Stop and Profits in OnMarketData:
protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
{
if (marketDataUpdate.MarketDataType == MarketDataType.Last)
{
if (Position.MarketPosition == MarketPosition.Long && myFreeTradeLong == true)
{
if (ProfitTarget)
{
if (ActiveTrade_1)
{
ExitLongLimit(0, true, Convert.ToInt32(PositionSize1), (Position.AveragePrice + (Target1 * TickSize)) , "MyTargetLong1", "MyEntryLong1");
}
if (ActiveTrade_2)
{
ExitLongLimit(0, true, Convert.ToInt32(PositionSize2), (Position.AveragePrice + (Target2 * TickSize)) , "MyTargetLong2", "MyEntryLong2");
}
if (ActiveTrade_3)
{
ExitLongLimit(0, true, Convert.ToInt32(PositionSize3), (Position.AveragePrice + (Target3 * TickSize)) , "MyTargetLong3", "MyEntryLong3");
}
Print(Convert.ToString(Times[0][0]) + " MyTargetLong SET" + " 1");
}
if (StopLoss)
{
if (ActiveTrade_1)
{
ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize1), InitialStopLong, "MyStopLong1", "MyEntryLong1");
}
if (ActiveTrade_2)
{
ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize2), InitialStopLong, "MyStopLong2", "MyEntryLong2");
}
if (ActiveTrade_3)
{
ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize3), InitialStopLong, "MyStopLong3", "MyEntryLong3");
}
Print(Convert.ToString(Times[0][0]) + " MyStopLong SET" + " 2");
}
Also I have my Breakeven and the Trailing Stop:
if(
(Position.MarketPosition == MarketPosition.Long) //Has to be in a long position
&& (marketDataUpdate.Price >= BreakevenTargetPriceStore) //Price hits our breakeven trigger
&& (myFreeBELong == true) //BE bool is true -> Once its false, you can move your stop freely
)
{
if (ActiveTrade_1)
{
ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize1), (Position.AveragePrice + (BreakevenOffset * TickSize)) , "MyStopLong1", "MyEntryLong1");
}
if (ActiveTrade_2)
{
ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize2), (Position.AveragePrice + (BreakevenOffset * TickSize)) , "MyStopLong2", "MyEntryLong2");
}
if (ActiveTrade_3)
{
ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize3), (Position.AveragePrice + (BreakevenOffset * TickSize)) , "MyStopLong3", "MyEntryLong3");
}
if ((Position.MarketPosition == MarketPosition.Long)
&& (myFreeTrail == true) //Bool needs to be true (Gets Reset with IsFirstTickOfBar to allow trail to occur on each new candle)
&& (marketDataUpdate.Price >= AtrTargetPriceStore)
&& (AtrStopSet > Position.AveragePrice)
&& (AtrBool == false))
{
AtrBool = true;
ProfitStopSet = true;
}
if ((Position.MarketPosition == MarketPosition.Long)
&& (IsFirstTickOfBar == true))
{
AtrCurrentPrice = (ATR1[0] * AtrMultiply) ;
//Print(Convert.ToString(Times[0][0]) + " ATR Current Price: " + Convert.ToString(AtrCurrentPrice) + " 7");
}
if ((Position.MarketPosition == MarketPosition.Long)
&& ((marketDataUpdate.Price - (AtrCurrentPrice)) > AtrStopSet)
&& ((marketDataUpdate.Price - (AtrCurrentPrice)) < GetCurrentBid(0))
&& ((marketDataUpdate.Price - (AtrCurrentPrice)) < GetCurrentAsk(0)))
{
if (UseATRTrailing)
{
AtrStopSet = (Close[0] - (AtrCurrentPrice)) ;
//Print(Convert.ToString(Times[0][0]) + " ATR Stop SET: " + Convert.ToString(AtrStopSet) + " 8");
}
}
if ((Position.MarketPosition == MarketPosition.Long)
&& (AtrBool == true)
// Condition group 1
&& (Low[1] > Low[2]) //Ensure the trail will only move up if the new candles low is higher.
&& ((ProfitStopSet == true)
|| (IsFirstTickOfBar == true)))
{
if (ActiveTrade_1)
{
ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize1), AtrStopSet, "MyStopLong1", "MyEntryLong1");
}
if (ActiveTrade_2)
{
ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize2), AtrStopSet, "MyStopLong2", "MyEntryLong2");
}
if (ActiveTrade_3)
{
ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize3), AtrStopSet, "MyStopLong3", "MyEntryLong3");
}
It works Perfect with the breakeven and the Trailing when you want to trade with 1 Entry, but when I want to use my 3 Entries, the strategy does Only Submits 1 Stop and 1 Profit Target... that makes the 2 remaining Entries keep going forever...
See Image, it Only Submits 1 Stop and 1 Profit Target:
Then when the Break Even activates, the strategy submits the 3 stop loss I wanted at the beginning too... when the profit target is reached then the trailing stop is activated with the remainig 2 entries:
I have prints and TraceOrders = True so I can see what is happening in the order submissions, as you can see I get the error "SignalName does not have a matching FromEntrySignal to exit" but here you can see also that these orders have been previously Submitted.....
WHY IS THAT I DO NOT SEE THEM IN THE CHART????
Regarding this I have following questions:
1 - Why does it submit the 3 Targets and Stops but then ignored?
2 - Should I make ONLY 1 EntryLong with 3 contracts and then make the Profit and stop orders from this Entry? Why I cant make 3 separate Entries and work with each one as I tried?
3 - How can I fix this ? Please explain the error detailed so this can help other users to understand what is happening.
Please take into Account that:
I am using OnEachTick Calculations because one of my Filters is the Volume (VOL).
With the Sim101 works everything perfect but with the DEMO (LIVE) account is where I get this errors.
Signal Names are Okey, can be that the name is "MyTargetLong1" and not @"MyTargetLong1"?? I tried to change that, it keeps working with these errors.
Thanks a lot for your help, I would apreciate if anyone could help me to solve this.
Trading Nasdaq

Comment