How to detect pending Sell Stop and BuyToCover Stop orders?  [SOLVED]

Questions about MultiCharts and user contributed studies.
Sebastian Vermont
Posts: 37
Joined: 06 Jan 2016
Has thanked: 6 times
Been thanked: 5 times

How to detect pending Sell Stop and BuyToCover Stop orders?

Postby Sebastian Vermont » 05 Apr 2016

Hey,

Is there any way to detect existing/pending Sell Stop and BuyToCover stop orders?

For example, let's say a signal executed this:

Code: Select all

if (MarketPosition(0) = -1) and eventBreakevenCoverTrigger then begin

BuyToCover ("BreakEven Stop") next bar at EntryPrice STOP;

end;
Okay, so now during a short trade we've got a stop loss that is a certain distance above the entry price.

Is there any way that I can detect the existence of ANY stop loss order inside the same strategy (preferably in another signal)? What I mean by the distinction "ANY stop loss order" is that I do not need to detect the specific order itself. I just want to find out if any stop loss exists.

To illustrate the use case, let's say I wanted to put the above code in the strategy to enforce breakeven covers in certain situations. Then, as the last signal in the strategy, I want to enforce a stop loss value if no other stop loss order exists, so I write a simple signal:

Code: Select all

inputs:
inputDefaultStopLoss (20);

variables:
conditionStopOrderExists (False),
pipsOnePipBroker (MinMove/PriceScale * 10);


conditionStopOrderExists= *** [This is what I do not know how to do] ***

if MarketPosition(0) = -1 and conditionStopOrderExists=False then begin

BuyToCover ("Default Stop") next bar at EntryPrice + (pipsOnePipBroker * inputInitialStopLoss) STOP;

end;
Any help or direction would be greatly appreciated. I've looked through the order and strategy keywords and I'm coming up blank. I realize the solution is almost certainly there somewhere, but I'm not able to find it.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: How to detect pending Sell Stop and BuyToCover Stop orde  [SOLVED]

Postby Henry MultiСharts » 05 Apr 2016

Hello Sebastian,

PowerLanguage does not provide direct access to pending orders. You can raise a flag in the code when you generate an order.

Sebastian Vermont
Posts: 37
Joined: 06 Jan 2016
Has thanked: 6 times
Been thanked: 5 times

Re: How to detect pending Sell Stop and BuyToCover Stop orde

Postby Sebastian Vermont » 05 Apr 2016

Henry,

Is there a way to supply other signals in the strategy the "flag" without using global variables or i_setplotvalue?

Thanks

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: How to detect pending Sell Stop and BuyToCover Stop orde

Postby Henry MultiСharts » 06 Apr 2016

Henry,

Is there a way to supply other signals in the strategy the "flag" without using global variables or i_setplotvalue?

Thanks
Sebastian,

There is no other way.

Sebastian Vermont
Posts: 37
Joined: 06 Jan 2016
Has thanked: 6 times
Been thanked: 5 times

Re: How to detect pending Sell Stop and BuyToCover Stop orde

Postby Sebastian Vermont » 06 Apr 2016

Okay thanks. I have had success using i_setplotvalue and i_getplotvalue with 2 signals in a strategy, but the last time I tried it with 3 I was getting some weird behavior. I'll give it another shot.


Return to “MultiCharts”