Exit problem for specific entries

Questions about MultiCharts and user contributed studies.
Spikehog
Posts: 39
Joined: 09 Dec 2013
Has thanked: 26 times
Been thanked: 1 time

Exit problem for specific entries

Postby Spikehog » 25 Jan 2017

I have 2 SELL entries which have separate exits. I use PRINT to make sure that all conditions are met. And the PRINT statements are shown in the output as per the conditions. However both BUYTOCOVER orders are not executed when stop prices (where the orange lines are) are met. I do not know what has gone wrong. Please help!

Code: Select all


If trEntryBar < CL75EntryBar and trEntryName = "trSELL" then
Begin
BuyToCover {("trSXBreakEven") from Entry ("trSELL")} 1 Contracts next bar at trEntryPrice stop;
Print(datetimetostring(datetime), " PosTradeCount(0)>", PosTradeCount(0), " trSELL>", trEntryName, " trEntryprice>", trEntryPrice, " ", CL75EntryName);
End;
If trEntryBar < CL75EntryBar and CL75EntryName = "CLB75oxSE" then
Begin
BuyToCover {("CL75SXStopLoss") from Entry ("CLB75oxSE")} 1 Contracts next bar at CL75Entryprice+100 stop;
Print(datetimetostring(datetime), " PosTradeCount(0)>", PosTradeCount(0), " CLB75oxSE>", CL75EntryName, " CL75Entryprice>", CL75Entryprice, " ", trEntryName);
End;
Attachments
MultichartsSupport25012017.PNG
(54.02 KiB) Downloaded 825 times
Last edited by Spikehog on 25 Jan 2017, edited 1 time in total.

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

Re: Exit problem for specific entries

Postby TJ » 25 Jan 2017

See post #5
5. The First Step in Debugging Your Code
viewtopic.php?t=11713

Spikehog
Posts: 39
Joined: 09 Dec 2013
Has thanked: 26 times
Been thanked: 1 time

Re: Exit problem for specific entries

Postby Spikehog » 25 Jan 2017

HJ, I just updated the code. Please advise where the problem is. Thanks

MAZINGUER
Posts: 75
Joined: 06 Jan 2017
Has thanked: 9 times
Been thanked: 25 times

Re: Exit problem for specific entries

Postby MAZINGUER » 26 Jan 2017

Hello Spikehog,
Hello,
In principle, that part of the code looks good.
That is why I believe that the failure must be in the declaration of the variables.
I also see a logic failure, because the BUYTOCOVER commands do not go into operation until you have both sales positions open because you put the necessary condition that trEntryprice is lower than CL75Entryprice. Therefore if the first (trEntryPrice) is activated but the second (CL75Entryprice) is not activated, the stop command will not be launched.
It is best to name the buy and sell orders, and then reference those orders to place the stops.
Also, in my opinion you should put a stop immediately after launching a purchase or sale order and do not expect to have two. For example,

Code: Select all

If sell-condition then
Sell ​​("on") 1 shares next bar at market;
BuyToCover ("off") from Entry ("on") 1 Contracts next bar at ............... stop;
If you want to add conditions to the stop order BuyToCover, you can do this by nesting "if" statements, but then I would add another stop, because stop orders will not be activated until the conditions are met.
I hope I have explained

Spikehog
Posts: 39
Joined: 09 Dec 2013
Has thanked: 26 times
Been thanked: 1 time

Re: Exit problem for specific entries

Postby Spikehog » 26 Jan 2017

Mazinguer, thank you for your detailed and clear explanation. I have checked again if the the problem is to do with variables. I printed out every single variable (which was related to the exit orders) when the conditions were met. The entry name and exit price were right. And I do not have a clue why they do not exit the way I want them to. It is really frustrating!

MAZINGUER
Posts: 75
Joined: 06 Jan 2017
Has thanked: 9 times
Been thanked: 25 times

Re: Exit problem for specific entries

Postby MAZINGUER » 26 Jan 2017

Spikehog,
Please try to place the stop orders inside the block "if sell-condition then begin .... end"
Make two "if ... then begin" blocks: one for buy orders and one for sellShort orders.
Then inside each block places the stop orders (which you can place directly or subject to another "If")

Spikehog
Posts: 39
Joined: 09 Dec 2013
Has thanked: 26 times
Been thanked: 1 time

Re: Exit problem for specific entries

Postby Spikehog » 26 Jan 2017

Mazinguer, I put entries and exits in different signals. As you can see on the picture above, the 'DayTightRange_EC' and 'CL75BoxV2.2_EC' are the entry signals and the 'ExitControl_SwitchCase' is the exit signal which is the heart of risk control to give exit instructions to both entry signals. In the beginning of this strategy development, I tested each exit with single signal individually. They were fine. However when I put all together, it did not turn out to be what I expected.

MAZINGUER
Posts: 75
Joined: 06 Jan 2017
Has thanked: 9 times
Been thanked: 25 times

Re: Exit problem for specific entries

Postby MAZINGUER » 26 Jan 2017

I mean something similar to this:

Code: Select all

If (sell-condition) then
SellShort "trSELL" 1 contracts next bar at ... (market/stop/limit) ;
SellShort "CLB75oxSE" 1 contracts next bar at....(market/ stop/limit);
if MarketPosition=-1 then begin
If (cover-condition-1) then
BuyToCover ("trSXBreakEven") from Entry ("trSELL") 1 Contracts next bar at trEntryPrice stop;
If (cover-condition2) then
BuyToCover {("CL75SXStopLoss") from Entry ("CLB75oxSE")} 1 Contracts next bar at CL75Entryprice+100 stop;
end;


Return to “MultiCharts”