I'm looking to add a simple atm to a strategy.
The strategy is simple(long example), upon some condition, enter a trade at market. At that time I would like an OCO with a profit target of a fixed tics. And an emergency stop a fixed tics that would always be there just in case a ways off.
After my entry occurs...... and price moves a fixed distance in my favor, I'd like to adjust that stop to BE+1.
At any point, if price Closes below an indicator, I'd like to exit the position immediately.
I'm attaching a pic that should explain this, and some script.
There is something missing, as my atm isn't executing the way it should(sometimes), mainly the either of the stops I have in place, my hard stop, or my stop below the indicator.
"SpanB" is just the indicator I am using to exit and enter a trade btw. "inTrade" is the flag I'm setting.
protected override void OnBarUpdate()
{
[COLOR="SeaGreen"]//Entry Condition[/COLOR]
if (CrossAbove(Close, spanB, 5) && Close[0] > spanB[0] && High[1] < spanB[1])
{
EnterLong(DefaultQuantity, "Long1");
//Print("Hello");
inTrade = true; [COLOR="SeaGreen"]//we are in a trade[/COLOR]
}
if(inTrade == true) [COLOR="SeaGreen"]//checks if in a trade[/COLOR]
{
[COLOR="SeaGreen"] //Catastrophe stop[/COLOR]
SetStopLoss("Long1", CalculationMode.Ticks, Position.AvgPrice - 16* TickSize, false);
if(Close[0] < spanB[0]) [COLOR="SeaGreen"]//If at anytime after entry price closes below indicator, exit trade[/COLOR]
{
ExitLong("", "Long1");
inTrade = false; [COLOR="SeaGreen"]//just exited so set flag to false[/COLOR]
}
}
[COLOR="SeaGreen"]//If price moves in my favor a set # of tics, adjust initial stop to BE+2[/COLOR]
if (High[0] >= (Position.AvgPrice + 8* TickSize) && inTrade == true)
{
SetStopLoss("Long1", CalculationMode.Price, Position.AvgPrice + 2* TickSize, false);
}
[COLOR="SeaGreen"]//checks to see if we are flat or target was hit. If so, set flag back to false[/COLOR].
if (Position.MarketPosition == MarketPosition.Flat)
inTrade = false;
}

Comment