Programming break out question

Questions about MultiCharts and user contributed studies.
bibulous
Posts: 56
Joined: 16 Apr 2010
Has thanked: 17 times
Been thanked: 2 times

Programming break out question

Postby bibulous » 02 Aug 2010

Hi,

I have a problem / question regarding a simple break out strategy I am working on. The logic is somewhat like:

Code: Select all

if myCondition then begin
buy ("ENTRY L") 1 contracts next bar H + myOffset stop;
sellshort ("ENTRY S") 1 contracts next bar L - myOffset stop;
end;

if MarketPosition = 1 then begin
sell ("LX") 1 contracts next bar myLongTarget limit;
sell ("LS") 1 contracts next bar myLongStop stop;
end;

if MarketPosition = -1 then begin
buytocover ("SX") 1 contracts next bar myShortTarget limit;
buytocover ("SS") 1 contracts next bar myShortStop stop;
end;
My problem is that the stop loss and profit target orders are filled too late. It seems that the sell / buycover orders are sent on the close of the next bar, so I do not have a stop loss for the time of 1 bar. As far as I understand I cannot use SetProfitTarget nor SetStoploss, since my targets / stoplosses are dynamic and I could use the two Set* methods to set a fixed value once.
Is there a simple solution to this problem or do I have to reimplement the strategy using IntraBarOrderGeneration ?

Marc

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: Programming break out question

Postby Dave Masalov » 02 Aug 2010

Dear Marc,

StopLoss and ProfitTarget are sent right after the position is closed. There are special keywords for these order types - SetStopLoss and SetProfitTarget. Please read the Help in the Power Language Editor.

bibulous
Posts: 56
Joined: 16 Apr 2010
Has thanked: 17 times
Been thanked: 2 times

Re: Programming break out question

Postby bibulous » 02 Aug 2010

Dear Marc,

StopLoss and ProfitTarget are sent right after the position is closed. There are special keywords for these order types - SetStopLoss and SetProfitTarget. Please read the Help in the Power Language Editor.
Dear Dave,

Thanks, but then there is something I do not understand.. In the EasyLanguage FAQ http://www.tssupport.com/discussion/vie ... f=1&t=6929 I have read that Set{StopLoss,TakeProfit) should not be used inside a condition. Does that mean I could (and in my case) re-set it on every bar update and if the entry stop is hit then the engine will set the correct stoploss / takeprofit? But, what if I re-set the sl/tp while I am in a position?

Marc

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: Programming break out question

Postby Dave Masalov » 03 Aug 2010

Dear Marc,

Set{StopLoss,TakeProfit) cannot be used within a condition because this condition might not be met when the position is open, and then these orders won't be sent which may lead to a loss. Orders can be re-set on every bar, so the old ones will be canceled and the new ones will be placed.


Return to “MultiCharts”