Yes correct, but I want to do it automatically with an indicator. The point stop is just for starters, I am looking to create volatility, ATR etc type stops for discretionary trading that plot stop price line once a position is on.
Ah I see. If you do this in an indicator, then you know that you can't automatically submit these orders? This might give you additional slippage, especially in volatile markets, and you can't take a short break when you have a position on since you'll manually need to submit those 'soft' stop-loss orders.
That being said, you can adjust your code to something like this:
Code: Select all
Variables:
stopPrice(0);
if (i_MarketPosition_at_Broker > 0) then begin
// Long stop-loss calculation
end
else if (i_MarketPosition_at_Broker < 0) then begin
// Short stop loss calculation
end;
Plot1(stopPrice, "MyStop");
(Edit: You may need to use a loop to plot the horizontal line for the previous bars instead of only on the current bar.)
But keep in mind that:
A zero ('0') is returned when the current position is flat, or if Automated Trading is not turned on.
Source.