Changing a SetStopLoss to a Sell/Buy Stop on a Price

Questions about MultiCharts and user contributed studies.
Jad
Posts: 92
Joined: 15 Jun 2014
Has thanked: 13 times
Been thanked: 21 times

Changing a SetStopLoss to a Sell/Buy Stop on a Price

Postby Jad » 03 Jul 2014

I am trying to place an initial stop loss immediately after the order is filled but then change that to a trailing stop based on the subsequent lows of bars (rather than use a built-in trailing stop based on a $ or % amount).

For the purposes of this discussion only, I am making that change immediately after the MarketPosition changes from 0 to illustrate the issue.

What I am noticing is that the SetStopLoss is only open for a split second and is immediately cancelled (which is to be expected). However, there is then a very noticeable delay/pause until the replacement Sell Order On A Price is visible and active on the DOM. There is always a delay of up to a second or more before the order shows and, during which time, I have no Stop in place. Here's the EL (pseudo) code. Does anyone know what I'm doing wrong and how to eliminate the time delay?

Code: Select all

If MarketPosition = 0 then begin

If condition1 then begin
(Do 'set variables stuff' to set up order);
Buy Next Bar at Price on a Stop;
end

else
begin
(Do other 'variables stuff');
CommandLine(".at_toggle");
end;

SetStopLoss(StpLoss)

end
else
begin
(Do 'reset variables stuff')
Sell Next Bar at Price on a Stop;
end;

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Changing a SetStopLoss to a Sell/Buy Stop on a Price

Postby TJ » 03 Jul 2014

I am trying to place an initial stop loss immediately after the order is filled but then change that to a trailing stop based on the subsequent lows of bars (rather than use a built-in trailing stop based on a $ or % amount).

For the purposes of this discussion only, I am making that change immediately after the MarketPosition changes from 0 to illustrate the issue.

What I am noticing is that the SetStopLoss is only open for a split second and is immediately cancelled (which is to be expected). However, there is then a very noticeable delay/pause until the replacement Sell Order On A Price is visible and active on the DOM. There is always a delay of up to a second or more before the order shows and, during which time, I have no Stop in place. Here's the EL (pseudo) code. Does anyone know what I'm doing wrong and how to eliminate the time delay?

Code: Select all

If MarketPosition = 0 then begin

If condition1 then begin
(Do 'set variables stuff' to set up order);
Buy Next Bar at Price on a Stop;
end

else
begin
(Do other 'variables stuff');
CommandLine(".at_toggle");
end;

SetStopLoss(StpLoss)

end
else
begin
(Do 'reset variables stuff')
Sell Next Bar at Price on a Stop;
end;
See post #5
viewtopic.php?f=16&t=10811

Jad
Posts: 92
Joined: 15 Jun 2014
Has thanked: 13 times
Been thanked: 21 times

Re: Changing a SetStopLoss to a Sell/Buy Stop on a Price

Postby Jad » 03 Jul 2014

Thank you TJ. My search had already led me to that post but as my SetStopLoss is outside the condition under which the initial order is sent, I believe that SetStopLoss(StpLoss) will be issued regardless of whether 'Condition1' is true or false.

The only time it won't be issued is the tick after the order is filled (i.e. When MarketPosition <> 0) in which case the Sell Next Bar at Price on a Stop; should be executed instead.

That's what I want to happen - and it seems to be happening but there is an inexplicable gap in between.

Incidentally, I apologize for the formatting of the code. I did originally indent it within the 'If' statements but when I looked at it after clicking on the the link that I received in the confirmation email, the text was Center Aligned. So, I edited it and removed the indentation but I see the text is all Left aligned now.

Jad
Posts: 92
Joined: 15 Jun 2014
Has thanked: 13 times
Been thanked: 21 times

Re: Changing a SetStopLoss to a Sell/Buy Stop on a Price

Postby Jad » 07 Jul 2014

Revisited this today and no matter where I place the SetStopLoss, there is a gap (sometimes negligible - sometimes not) between it being cancelled and the Sell at a Price on a Stop showing up.

In the end, I decided to keep the SetStopLoss active and use it as a Trailing Stop by recalculating '(StpLoss)'. Fortunately, a negative value is accepted to permit locking in profit. Admittedly, it's ugly - but it does work without any time gaps before the Stop Order is moved.

I have also noticed the following:

When cancel/replacing an order, sometimes one or more errors are returned with message: 'Another command is in execution'.

The result is, for example:
If the current Trailing Sell Stop is at 10 and the market moves up on the next tick to require the Stop to be moved to 11 and then the next tick to 12 and the next to 13, I will receive two of these errors. While while the Stop is moved to 11 after the first tick in the series, it remains at 11 until it is hit or until another tick causes it to move higher again.

My guess (and it's only a guess) is that MC has not received confirmation that the Order has been moved to 11 before the ticks requiring further moves are received.

If so, then that's understandable but once the confirmation of the move to 11 has been received, no further move of the order takes place even thought the script is continuing to request a move to 12 and then 13. Another request to 14 seems to be needed before the order is moved off 11. This does not always occur and is only happening when there is a flurry of activity. During slow periods, it does not happen.

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

Re: Changing a SetStopLoss to a Sell/Buy Stop on a Price

Postby Henry MultiСharts » 15 Jul 2014

Revisited this today and no matter where I place the SetStopLoss, there is a gap (sometimes negligible - sometimes not) between it being cancelled and the Sell at a Price on a Stop showing up.

In the end, I decided to keep the SetStopLoss active and use it as a Trailing Stop by recalculating '(StpLoss)'. Fortunately, a negative value is accepted to permit locking in profit. Admittedly, it's ugly - but it does work without any time gaps before the Stop Order is moved.
Hello Jad,

In your code SetStopLoss is under a condition:

Code: Select all

If MarketPosition = 0 then begin
SetStopLoss();
end;
Please try using the SetStopLoss command without any conditions. It will behave the same - the order will trigger only when there is an open position.
I have also noticed the following:
When cancel/replacing an order, sometimes one or more errors are returned with message: 'Another command is in execution'.
The result is, for example:
If the current Trailing Sell Stop is at 10 and the market moves up on the next tick to require the Stop to be moved to 11 and then the next tick to 12 and the next to 13, I will receive two of these errors. While while the Stop is moved to 11 after the first tick in the series, it remains at 11 until it is hit or until another tick causes it to move higher again.
My guess (and it's only a guess) is that MC has not received confirmation that the Order has been moved to 11 before the ticks requiring further moves are received.
If so, then that's understandable but once the confirmation of the move to 11 has been received, no further move of the order takes place even thought the script is continuing to request a move to 12 and then 13. Another request to 14 seems to be needed before the order is moved off 11. This does not always occur and is only happening when there is a flurry of activity. During slow periods, it does not happen.
It depends on the instrument you are using. The trailing price is calculated in the instrument currency. That is possible that 1 tick price change on the chart does not change the trailing price due to insignificant change expressed in the currency value.
min $ move (1 tick) = Min.Movment * Price Scale * Big Pont Value.
These values can be found in QuoteManager -> Edit symbol -> Settings.

Jad
Posts: 92
Joined: 15 Jun 2014
Has thanked: 13 times
Been thanked: 21 times

Re: Changing a SetStopLoss to a Sell/Buy Stop on a Price

Postby Jad » 15 Jul 2014

Thanks Henry but if 'insignificant change' means one tick, then I would expect any and every one tick change to be treated the same (i.e. changed or ignored). I understand your point but in this case, the problem does not seem to be related to the significance of the price change but the speed of it.

The script's process is such that if a move results in a requirement to move the Stop up - to say, 11 (using the same example above), then any further move (even one more upward tick) will require a further move to 12.

Note: This works without any problems - often moving the Stop in several, one-tick increments - when the market is not 'fast' - which is why I don't think this problem is related to whether or not the price move is significant enough to warrant a move. If that was the case, we'd have another problem with inconsistent results from the same actions.

This issue occurs during the following events (again using the example in my previous post above)

Step1. Current Stop = 10
Step2. Market moves up requiring the Stop to be moved to 11
Step3. The Order is sent to move the Stop to 11 BUT before it is Accepted and Working....
Step4. Another move requires another Order to be sent to move the Stop to 12
Step5. The order to move the Stop to 12 is rejected because the previous order to move the Stop to 11 - in Step3 - is still in execution. The order sent in Step3 is eventually Accepted and can be seen Working @ 11.
Step6. The Order remains at 11 (instead of 12) because Step4 resulted in a rejection due to a 'fast' market.

Everything above makes sense to me. I have no problem with the sequence of events nor do I expect MC to be able to do anything about those events because they occur during a 'fast' market - even if that 'fast' market only lasts for one or two ticks. What I do not understand is what happens afterwards....:

Step7. The script continues to send Orders to move the Stop to 12 on every tick but, even after the market has slowed, the Stop remains at 11.

The Stop should be moved to 12 on the first tick after the 'fast' market conditions cease.

My guess is that MC records the rejected attempt to move the Stop to 12 and 'thinks' that is where the Stop is currently Working at the Broker (but it most certainly is not).

It then ignores every subsequent request to move it there - no matter how many requests are sent or how much the market slows. It takes another request (in a slow enough market to not also be rejected) to a different price (e.g. 13) before the Stop is 'automatically' moved off 11.

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

Re: Changing a SetStopLoss to a Sell/Buy Stop on a Price

Postby Henry MultiСharts » 21 Jul 2014

Hello Jad,

When you experience this behavior please send us the following information to support@multicharts.com for further analysis:
  • what exact version and build number of MultiCharts are you running? (in MultiCharts go to Help tab-> About)
  • which broker do you use?
  • MultiCharts logs (if you have not restarted the platform. Logs from the previous run are erased when you start MC). In MultiCharts go to Help->Feedback->Send logs. Please let me know that you have uploaded the logs
    If you want to send the logs manually please follow this guide: https://www.multicharts.com/trading-sof ... harts_Logs
  • In MultiCharts go to File->New->Open Order and position tracker window-> Orders tab->make sure you are not filtering the information in columns, then go to File->Export to excel.
    Please also export the information from the Logs tab and send it to us for analysis;
  • attach a detailed description and highlight the issue on the screenshots;
  • attach the workspace you are using;
  • in QuoteManager select the symbol you are using, make a right click on it->Export data->Export instrument (without data). Send us the Qmd export file for analysis;
  • in PowerLanguage editor->File->Export->export with dependent functions the studies you are using in the workspaces you are providing. Send us the study export file.

Jad
Posts: 92
Joined: 15 Jun 2014
Has thanked: 13 times
Been thanked: 21 times

Re: Changing a SetStopLoss to a Sell/Buy Stop on a Price

Postby Jad » 21 Jul 2014

Thanks Henry, I believe that the engineers have already investigated the issue and, as a temporary workaround, have recommended changing my script to make it not modify the orders so often because, unfortunately, in the current version it is the only possible workaround.
I have been told that the developers have also decided to implement the feature in the future versions, most likely 9.1 Release. Apparently, the fix will be that if a request for a modification comes before the completion of the previous request to modify the order, then this modification will be put in a queue and only released once confirmation has been received - thus there won't be any of this type of rejection error and all modification requests will be completed.

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

Re: Changing a SetStopLoss to a Sell/Buy Stop on a Price

Postby Henry MultiСharts » 23 Jul 2014

Thanks Henry, I believe that the engineers have already investigated the issue and, as a temporary workaround, have recommended changing my script to make it not modify the orders so often because, unfortunately, in the current version it is the only possible workaround.
That is correct.
I have been told that the developers have also decided to implement the feature in the future versions, most likely 9.1 Release. Apparently, the fix will be that if a request for a modification comes before the completion of the previous request to modify the order, then this modification will be put in a queue and only released once confirmation has been received - thus there won't be any of this type of rejection error and all modification requests will be completed.
Exactly. It is targeted to MultiCharts 9.1 Beta 1


Return to “MultiCharts”