i have a problem with setting stoploss in my strategy
here is a code
Protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(EMA(MaPer1), EMA(MaPer2), 1)
&& ToTime(Time[0]) >= casBeg
&& ToTime(Time[0]) < casEnd
&& Position.MarketPosition == MarketPosition.Flat)
{
EnterLongStop(10000,High[0] + tick*TickSize , "Long");
}
else if (CrossAbove(EMA(MaPer1), EMA(MaPer2), 1)
&& ToTime(Time[0]) >= casBeg
&& ToTime(Time[0]) < casEnd
&& Position.MarketPosition == MarketPosition.Short)
{
EnterLongStop(10000,High[0] + tick*TickSize , "Long");
}
// Condition set 2
if (CrossBelow(EMA(MaPer1), EMA(MaPer2), 1)
&&ToTime(Time[0]) >= casBeg
&& ToTime(Time[0]) < casEnd
&&Position.MarketPosition == MarketPosition.Flat
)
{
EnterShortStop(10000,Low[0] - tick*TickSize , "Short");
}
else if (CrossBelow(EMA(MaPer1), EMA(MaPer2), 1)
&&ToTime(Time[0]) >= casBeg
&& ToTime(Time[0]) < casEnd
&&Position.MarketPosition == MarketPosition.Long
)
{
EnterShortStop(10000,Low[0] - tick*TickSize , "Short");
}
my entry orders are placed via EnterShortStop/EnterLongStop
if i use SetStopLoss in initialize method it doesnt work.
protected override void Initialize()
{
SetStopLoss(500);
AccountSize = 10000;
ExitOnClose = false;
Could you help me or tell me which method is best/correct to place a stop loss ?
Thank You
Comment