Page 1 of 1

How to detect pending Sell Stop and BuyToCover Stop orders?

Posted: Apr 05 2016
by Sebastian Vermont
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.

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

Posted: Apr 05 2016
by Henry MultiŠ”harts
Hello Sebastian,

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

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

Posted: Apr 05 2016
by Sebastian Vermont
Henry,

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

Thanks

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

Posted: Apr 06 2016
by Henry MultiŠ”harts
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.

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

Posted: Apr 06 2016
by Sebastian Vermont
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.