i am working on my first real strategy and iÄve got some struggle with the order management. Like you can see in the picture, i want to put a enterlongstop at the top of the candle when the EMA is crossed
crossedbelow & above wasn't working (maybe cause of calculateOnBarClose = false?). Somewhere i have a mistake and i am sorry for steal your time, but i really can't find it.
if ( Opens[0][1] > EMA(Opens[0],20)[1]
&& Lows[0][1] < EMA(Opens[0],20)[1]
&& entryOrder == null
)
{
longbool = true;
SLLong = (Lows[0][LowestBar(Lows[0],1)]);
entryOrder = EnterLongStop(1,Highs[0][1],"BUY"+(BarsPeriods[BarsInProgress].Value));
LongtradeStop = Lows[0][1];
ELS = Highs[0][1]; //EnterLongStop
}
if ( Opens[0][1] < EMA(Opens[0],20)[1]
&& Highs[0][1] > EMA(Opens[0],20)[1]
&& entryOrder == null
)
{
shortbool = true;
SLShort = (Highs[0][HighestBar(Highs[0],1)]);
entryOrder = EnterShortStop(1,Lows[0][1],"SELL"+(BarsPeriods[BarsInProgress].Value));
ShorttradeStop = Highs[0][1];
ESS = Lows[0][1];
}
#endregion
#endregion
#region Keep Order Alive
if ( longbool == true )
{
entryOrder = EnterLongStop(1,ELS,"BUY"+(BarsPeriods[BarsInProgress].Value));
}
if ( shortbool == true)
{
entryOrder = EnterShortStop(1,ESS,"SELL"+(BarsPeriods[BarsInProgress].Value));
}
// Abbruchbedingung für Limit
if((longbool == true && Lows[0][0] < LongtradeStop)
|| (shortbool == true && Highs[0][0] > ShorttradeStop)
)
{
longbool = false;
shortbool = false;
CancelOrder(entryOrder);
entryOrder = null;
}
Home you get what i am working on :-)
Comment